Snap for 5061196 from 8807af4b74c296b26741c1a299d06b1d4367cdf5 to master-cuttlefish-testing-release

Change-Id: I1b7f91eca5bebd23cea54a99038989acf7951f0e
diff --git a/aidl.cpp b/aidl.cpp
index 7ed535d..1f804bc 100644
--- a/aidl.cpp
+++ b/aidl.cpp
@@ -37,6 +37,7 @@
 #include <android-base/strings.h>
 
 #include "aidl_language.h"
+#include "aidl_typenames.h"
 #include "generate_cpp.h"
 #include "generate_java.h"
 #include "generate_ndk.h"
@@ -163,11 +164,6 @@
 int check_types(const AidlInterface* c, TypeNamespace* types) {
   int err = 0;
 
-  if (c->IsUtf8() && c->IsUtf8InCpp()) {
-    AIDL_ERROR(c) << "Interface cannot be marked as both @utf8 and @utf8InCpp";
-    err = 1;
-  }
-
   // Has to be a pointer due to deleting copy constructor. No idea why.
   map<string, const AidlMethod*> method_names;
   for (const auto& m : c->GetMethods()) {
@@ -541,7 +537,9 @@
 
   set<string> type_from_import_statements;
   for (const auto& import : main_parser->GetImports()) {
-    type_from_import_statements.emplace(import->GetNeededClass());
+    if (!AidlTypenames::IsBuiltinTypename(import->GetNeededClass())) {
+      type_from_import_statements.emplace(import->GetNeededClass());
+    }
   }
 
   // When referencing a type using fully qualified name it should be imported
diff --git a/aidl_language.cpp b/aidl_language.cpp
index 281c149..8c42c40 100644
--- a/aidl_language.cpp
+++ b/aidl_language.cpp
@@ -69,10 +69,9 @@
 }
 
 static const string kNullable("nullable");
-static const string kUtf8("utf8");
 static const string kUtf8InCpp("utf8InCpp");
 
-static const set<string> kAnnotationNames{kNullable, kUtf8, kUtf8InCpp};
+static const set<string> kAnnotationNames{kNullable, kUtf8InCpp};
 
 AidlAnnotation* AidlAnnotation::Parse(const AidlLocation& location, const string& name) {
   if (kAnnotationNames.find(name) == kAnnotationNames.end()) {
@@ -107,10 +106,6 @@
   return HasAnnotation(annotations_, kNullable);
 }
 
-bool AidlAnnotatable::IsUtf8() const {
-  return HasAnnotation(annotations_, kUtf8);
-}
-
 bool AidlAnnotatable::IsUtf8InCpp() const {
   return HasAnnotation(annotations_, kUtf8InCpp);
 }
diff --git a/aidl_language.h b/aidl_language.h
index 306e30a..72b4b75 100644
--- a/aidl_language.h
+++ b/aidl_language.h
@@ -157,7 +157,6 @@
 
   void Annotate(set<AidlAnnotation>&& annotations) { annotations_ = std::move(annotations); }
   bool IsNullable() const;
-  bool IsUtf8() const;
   bool IsUtf8InCpp() const;
   std::string ToString() const;
 
diff --git a/aidl_to_java.cpp b/aidl_to_java.cpp
index a46d8e3..6e8a0b5 100644
--- a/aidl_to_java.cpp
+++ b/aidl_to_java.cpp
@@ -66,6 +66,7 @@
       {"IBinder", "android.os.IBinder"},
       {"FileDescriptor", "java.io.FileDescriptor"},
       {"CharSequence", "java.lang.CharSequence"},
+      {"ParcelFileDescriptor", "android.os.ParcelFileDescriptor"},
   };
   const string& aidl_name = aidl.GetName();
   if (m.find(aidl_name) != m.end()) {
@@ -113,11 +114,12 @@
                                         const AidlTypenames& typenames) {
   const string name = aidl.GetName();
 
-  // List<T> is support only for String, Binder and Parcelable.
+  // List<T> is support only for String, Binder, ParcelFileDescriptor and Parcelable.
   if (name == "List" && aidl.IsGeneric()) {
     const string& contained_type = aidl.GetTypeParameters().at(0)->GetName();
     if (AidlTypenames::IsBuiltinTypename(contained_type)) {
-      if (contained_type != "String" && contained_type != "IBinder") {
+      if (contained_type != "String" && contained_type != "IBinder" &&
+          contained_type != "ParcelFileDescriptor") {
         return true;
       }
     } else {
@@ -270,6 +272,14 @@
        [](const CodeGeneratorContext& c) {
          c.writer << c.parcel << ".writeRawFileDescriptorArray(" << c.var << ");\n";
        }},
+      {"ParcelFileDescriptor",
+       [](const CodeGeneratorContext& c) {
+         c.writer << c.parcel << ".writeTypedObject(" << c.var << ", " << GetFlagFor(c) << ");\n";
+       }},
+      {"ParcelFileDescriptor[]",
+       [](const CodeGeneratorContext& c) {
+         c.writer << c.parcel << ".writeTypedArray(" << c.var << ", " << GetFlagFor(c) << ");\n";
+       }},
       {"CharSequence",
        [](const CodeGeneratorContext& c) {
          // TextUtils.writeToParcel does not accept null. So, we need to handle
@@ -450,6 +460,16 @@
        [](const CodeGeneratorContext& c) {
          c.writer << c.var << " = " << c.parcel << ".createRawFileDescriptorArray();\n";
        }},
+      {"ParcelFileDescriptor",
+       [](const CodeGeneratorContext& c) {
+         c.writer << c.var << " = " << c.parcel
+                  << ".readTypedObject(android.os.ParcelFileDescriptor.CREATOR);\n";
+       }},
+      {"ParcelFileDescriptor[]",
+       [](const CodeGeneratorContext& c) {
+         c.writer << c.var << " = " << c.parcel
+                  << ".createTypedArray(android.os.ParcelFileDescriptor.CREATOR);\n";
+       }},
       {"CharSequence",
        [](const CodeGeneratorContext& c) {
          // We have written 0 for null CharSequence.
@@ -575,6 +595,16 @@
        [](const CodeGeneratorContext& c) {
          c.writer << c.var << " = " << c.parcel << ".createRawFileDescriptorArray();\n";
        }},
+      {"ParcelFileDescriptor",
+       [](const CodeGeneratorContext& c) {
+         c.writer << c.var << " = " << c.parcel
+                  << ".readTypedObject(android.os.ParcelFileDescriptor.CREATOR);\n";
+       }},
+      {"ParcelFileDescriptor[]",
+       [](const CodeGeneratorContext& c) {
+         c.writer << c.parcel << ".readTypedArray(" << c.var
+                  << ", android.os.ParcelFileDescriptor.CREATOR);\n";
+       }},
   };
   const string type_name = c.type.GetName() + (c.type.IsArray() ? "[]" : "");
   const auto& found = method_map.find(type_name);
diff --git a/aidl_typenames.cpp b/aidl_typenames.cpp
index 1086285..ad85a1d 100644
--- a/aidl_typenames.cpp
+++ b/aidl_typenames.cpp
@@ -45,9 +45,9 @@
 
 // The built-in AIDL types..
 static const set<string> kBuiltinTypes = {
-    "void",           "boolean",      "byte",           "char",         "int", "long",
-    "float",          "double",       "String",         "List",         "Map", "IBinder",
-    "FileDescriptor", "CharSequence"};
+    "void", "boolean", "byte",           "char",         "int",
+    "long", "float",   "double",         "String",       "List",
+    "Map",  "IBinder", "FileDescriptor", "CharSequence", "ParcelFileDescriptor"};
 
 // Note: these types may look wrong because they look like Java
 // types, but they have long been supported from the time when Java
@@ -55,8 +55,9 @@
 // backwards compatibility, but we internally treat them as List and Map,
 // respectively.
 static const map<string, string> kJavaLikeTypeToAidlType = {
-  {"java.util.List", "List"},
-  {"java.util.Map", "Map"},
+    {"java.util.List", "List"},
+    {"java.util.Map", "Map"},
+    {"android.os.ParcelFileDescriptor", "ParcelFileDescriptor"},
 };
 
 // Package name and type name can't be one of these as they are keywords
@@ -154,11 +155,12 @@
   }
 }
 
-// Only T[], List, Map, and Parcelable can be an out parameter.
+// Only T[], List, Map, ParcelFileDescriptor and Parcelable can be an out parameter.
 bool AidlTypenames::CanBeOutParameter(const AidlTypeSpecifier& type) const {
   const string& name = type.GetName();
   if (IsBuiltinTypename(name)) {
-    return type.IsArray() || type.GetName() == "List" || type.GetName() == "Map";
+    return type.IsArray() || type.GetName() == "List" || type.GetName() == "Map" ||
+           type.GetName() == "ParcelFileDescriptor";
   }
   const AidlDefinedType* t = TryGetDefinedType(type.GetName());
   CHECK(t != nullptr) << "Unrecognized type: '" << type.GetName() << "'";
diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp
index 5a7c5d2..8ef9e72 100644
--- a/aidl_unittest.cpp
+++ b/aidl_unittest.cpp
@@ -1130,6 +1130,33 @@
   EXPECT_FALSE(::android::aidl::check_api(options, io_delegate_));
 }
 
+TEST_F(AidlTest, ParcelFileDescriptorIsBuiltinType) {
+  Options javaOptions = Options::From("aidl --lang=java -o out p/IFoo.aidl");
+  Options cppOptions = Options::From("aidl --lang=cpp -h out -o out p/IFoo.aidl");
+
+  // use without import
+  io_delegate_.SetFileContents("p/IFoo.aidl",
+                               "package p; interface IFoo{ void foo(in ParcelFileDescriptor fd);}");
+  EXPECT_EQ(0, ::android::aidl::compile_aidl(javaOptions, io_delegate_));
+  EXPECT_EQ(0, ::android::aidl::compile_aidl(cppOptions, io_delegate_));
+
+  // use without impot but with full name
+  io_delegate_.SetFileContents(
+      "p/IFoo.aidl",
+      "package p; interface IFoo{ void foo(in android.os.ParcelFileDescriptor fd);}");
+  EXPECT_EQ(0, ::android::aidl::compile_aidl(javaOptions, io_delegate_));
+  EXPECT_EQ(0, ::android::aidl::compile_aidl(cppOptions, io_delegate_));
+
+  // use with import (as before)
+  io_delegate_.SetFileContents("p/IFoo.aidl",
+                               "package p;"
+                               "import android.os.ParcelFileDescriptor;"
+                               "interface IFoo{"
+                               "  void foo(in ParcelFileDescriptor fd);"
+                               "}");
+  EXPECT_EQ(0, ::android::aidl::compile_aidl(javaOptions, io_delegate_));
+  EXPECT_EQ(0, ::android::aidl::compile_aidl(cppOptions, io_delegate_));
+}
 
 }  // namespace aidl
 }  // namespace android
diff --git a/build/test_package/IBaz.aidl b/build/test_package/IBaz.aidl
index 6ac0a0d..9dd58e6 100644
--- a/build/test_package/IBaz.aidl
+++ b/build/test_package/IBaz.aidl
@@ -21,4 +21,15 @@
 interface IBaz {
     void CanYouDealWithThisBar(in IBar bar);
     void MethodAddedInVersion2();
+    // TODO(b/115607973) uncomment these when binder_ndk has support for
+    // ParcelFileDescriptor
+    //ParcelFileDescriptor readPFD();
+    //void writePFD(in ParcelFileDescriptor fd);
+    //void readWritePFD(inout ParcelFileDescriptor fd);
+
+    // TODO(b/112664205) uncomment these when we have the support for array type in
+    // the ndk backend
+    //ParcelFileDescriptor[] readPFDArray();
+    //void writePFDArray(in ParcelFileDescriptor[] fds);
+    //void readWritePFDArray(inout ParcelFileDescriptor[] fds);
 }
diff --git a/tests/aidl_test_client.cpp b/tests/aidl_test_client.cpp
index f484c1e..f4850b0 100644
--- a/tests/aidl_test_client.cpp
+++ b/tests/aidl_test_client.cpp
@@ -96,6 +96,10 @@
 
   if (!client_tests::ConfirmFileDescriptorArrays(service)) return 1;
 
+  if (!client_tests::ConfirmParcelFileDescriptors(service)) return 1;
+
+  if (!client_tests::ConfirmParcelFileDescriptorArrays(service)) return 1;
+
   if (!client_tests::ConfirmServiceSpecificExceptions(service)) return 1;
 
   if (!client_tests::ConfirmNullables(service)) return 1;
diff --git a/tests/aidl_test_client_file_descriptors.cpp b/tests/aidl_test_client_file_descriptors.cpp
index b5913a3..e2d59a9 100644
--- a/tests/aidl_test_client_file_descriptors.cpp
+++ b/tests/aidl_test_client_file_descriptors.cpp
@@ -24,6 +24,7 @@
 #include <unistd.h>
 
 #include <android-base/unique_fd.h>
+#include <binder/ParcelFileDescriptor.h>
 
 // libbase
 using android::base::unique_fd;
@@ -37,6 +38,8 @@
 // generated
 using android::aidl::tests::ITestService;
 
+using android::os::ParcelFileDescriptor;
+
 using std::cerr;
 using std::cout;
 using std::endl;
@@ -165,6 +168,71 @@
   return ret;
 }
 
+bool ConfirmParcelFileDescriptors(const sp<ITestService>& s) {
+  Status status;
+  cout << "Confirming passing and returning parcel file descriptors works." << endl;
+
+  unique_fd read_fd;
+  unique_fd write_fd;
+
+  if (!DoPipe(&read_fd, &write_fd)) {
+    return false;
+  }
+
+  ParcelFileDescriptor return_fd;
+
+  status = s->RepeatParcelFileDescriptor(ParcelFileDescriptor(std::move(write_fd)), &return_fd);
+
+  if (!status.isOk()) {
+    cerr << "Could not repeat parcel file descriptors." << endl;
+    return false;
+  }
+
+  /* A note on some of the spookier stuff going on here: IIUC writes to pipes
+   * should be atomic and non-blocking so long as the total size doesn't exceed
+   * PIPE_BUF. We thus play a bit fast and loose with failure modes here.
+   */
+
+  bool ret = DoWrite(FdByName(return_fd.release()), "ReturnString") &&
+             DoRead(FdByName(read_fd), "ReturnString");
+
+  return ret;
+}
+
+bool ConfirmParcelFileDescriptorArrays(const sp<ITestService>& s) {
+  Status status;
+  cout << "Confirming passing and returning parcel file descriptor arrays works." << endl;
+
+  vector<unique_fd> array;
+  array.resize(2);
+
+  if (!DoPipe(&array[0], &array[1])) {
+    return false;
+  }
+
+  vector<ParcelFileDescriptor> input;
+  for (auto& fd : array) {
+    input.push_back(ParcelFileDescriptor(std::move(fd)));
+  }
+
+  vector<ParcelFileDescriptor> repeated;
+  vector<ParcelFileDescriptor> reversed;
+
+  status = s->ReverseParcelFileDescriptorArray(input, &repeated, &reversed);
+
+  if (!status.isOk()) {
+    cerr << "Could not reverse file descriptor array." << endl;
+    return false;
+  }
+
+  bool ret = DoWrite(FdByName(input[1].release()), "First") &&
+             DoWrite(FdByName(repeated[1].release()), "Second") &&
+             DoWrite(FdByName(reversed[0].release()), "Third") &&
+             DoRead(FdByName(input[0].release()), "FirstSecondThird");
+
+  return ret;
+}
+
 }  // namespace client
 }  // namespace tests
 }  // namespace aidl
diff --git a/tests/aidl_test_client_file_descriptors.h b/tests/aidl_test_client_file_descriptors.h
index 306e551..03da0f1 100644
--- a/tests/aidl_test_client_file_descriptors.h
+++ b/tests/aidl_test_client_file_descriptors.h
@@ -29,6 +29,8 @@
 
 bool ConfirmFileDescriptors(const sp<ITestService>& s);
 bool ConfirmFileDescriptorArrays(const sp<ITestService>& s);
+bool ConfirmParcelFileDescriptors(const sp<ITestService>& s);
+bool ConfirmParcelFileDescriptorArrays(const sp<ITestService>& s);
 
 }  // namespace client
 }  // namespace tests
diff --git a/tests/aidl_test_service.cpp b/tests/aidl_test_service.cpp
index 83eddae..4b4eb12 100644
--- a/tests/aidl_test_service.cpp
+++ b/tests/aidl_test_service.cpp
@@ -67,8 +67,9 @@
 using android::aidl::tests::BnTestService;
 using android::aidl::tests::INamedCallback;
 using android::aidl::tests::SimpleParcelable;
-using android::os::PersistableBundle;
 using android::binder::Map;
+using android::os::ParcelFileDescriptor;
+using android::os::PersistableBundle;
 
 // Standard library
 using std::map;
@@ -315,6 +316,27 @@
     return Status::ok();
   }
 
+  Status RepeatParcelFileDescriptor(const ParcelFileDescriptor& read,
+                                    ParcelFileDescriptor* _aidl_return) override {
+    ALOGE("Repeating parcel file descriptor");
+    _aidl_return->reset(unique_fd(dup(read.get())));
+    return Status::ok();
+  }
+
+  Status ReverseParcelFileDescriptorArray(const vector<ParcelFileDescriptor>& input,
+                                          vector<ParcelFileDescriptor>* repeated,
+                                          vector<ParcelFileDescriptor>* _aidl_return) override {
+    ALOGI("Reversing parcel descriptor array of length %zu", input.size());
+    for (const auto& item : input) {
+      repeated->push_back(ParcelFileDescriptor(unique_fd(dup(item.get()))));
+    }
+
+    for (auto i = input.rbegin(); i != input.rend(); i++) {
+      _aidl_return->push_back(ParcelFileDescriptor(unique_fd(dup(i->get()))));
+    }
+    return Status::ok();
+  }
+
   Status ThrowServiceException(int code) override {
     return Status::fromServiceSpecificError(code);
   }
diff --git a/tests/android/aidl/tests/ITestService.aidl b/tests/android/aidl/tests/ITestService.aidl
index fe0515a..cda2ff8 100644
--- a/tests/android/aidl/tests/ITestService.aidl
+++ b/tests/android/aidl/tests/ITestService.aidl
@@ -83,6 +83,10 @@
   FileDescriptor[] ReverseFileDescriptorArray(in FileDescriptor[] input,
                                               out FileDescriptor[] repeated);
 
+  ParcelFileDescriptor RepeatParcelFileDescriptor(in ParcelFileDescriptor read);
+  ParcelFileDescriptor[] ReverseParcelFileDescriptorArray(in ParcelFileDescriptor[] input,
+                                              out ParcelFileDescriptor[] repeated);
+
   // Test that service specific exceptions work correctly.
   void ThrowServiceException(int code);
 
diff --git a/tests/java_app/src/android/aidl/tests/TestServiceClient.java b/tests/java_app/src/android/aidl/tests/TestServiceClient.java
index 9de1ae5..02cb055 100644
--- a/tests/java_app/src/android/aidl/tests/TestServiceClient.java
+++ b/tests/java_app/src/android/aidl/tests/TestServiceClient.java
@@ -26,6 +26,7 @@
 import android.os.ServiceSpecificException;
 import android.os.Bundle;
 import android.os.IBinder;
+import android.os.ParcelFileDescriptor;
 import android.os.PersistableBundle;
 import android.os.RemoteException;
 import android.os.ServiceManager;
@@ -604,6 +605,41 @@
         mLog.log("...service can receive and return file descriptors.");
     }
 
+    private void checkParcelFileDescriptorPassing(ITestService service)
+            throws TestFailException {
+        mLog.log("Checking that service can receive and return parcel file descriptors...");
+        try {
+            ParcelFileDescriptor descriptor = ParcelFileDescriptor.open(
+                    getFileStreamPath("test-dummy"), ParcelFileDescriptor.MODE_CREATE |
+                        ParcelFileDescriptor.MODE_WRITE_ONLY);
+            ParcelFileDescriptor journeyed = service.RepeatParcelFileDescriptor(descriptor);
+
+            FileOutputStream journeyedStream = new ParcelFileDescriptor.AutoCloseOutputStream(journeyed);
+
+            String testData = "FrazzleSnazzleFlimFlamFlibbityGumboChops";
+            byte[] output = testData.getBytes();
+            journeyedStream.write(output);
+            journeyedStream.close();
+
+            FileInputStream fileInputStream = openFileInput("test-dummy");
+            byte[] input = new byte[output.length];
+            if (fileInputStream.read(input) != input.length) {
+                mLog.logAndThrow("Read short count from file");
+            }
+
+            if (!Arrays.equals(input, output)) {
+                mLog.logAndThrow("Read incorrect data");
+            }
+        } catch (RemoteException ex) {
+            mLog.log(ex.toString());
+            mLog.logAndThrow("Service failed to repeat a file descriptor.");
+        } catch (IOException ex) {
+            mLog.log(ex.toString());
+            mLog.logAndThrow("Exception while operating on temporary file");
+        }
+        mLog.log("...service can receive and return file descriptors.");
+    }
+
     private void checkServiceSpecificExceptions(
                 ITestService service) throws TestFailException {
         mLog.log("Checking application exceptions...");
@@ -806,6 +842,7 @@
           checkSimpleParcelables(service);
           checkPersistableBundles(service);
           checkFileDescriptorPassing(service);
+          checkParcelFileDescriptorPassing(service);
           checkServiceSpecificExceptions(service);
           checkUtf8Strings(service);
           checkStructuredParcelable(service);
diff --git a/type_cpp.cpp b/type_cpp.cpp
index 4f791c6..fd1ff05 100644
--- a/type_cpp.cpp
+++ b/type_cpp.cpp
@@ -465,6 +465,22 @@
       "readUniqueFileDescriptor", "writeUniqueFileDescriptor",
       fd_vector_type));
 
+  Type* pfd_vector_type =
+      new CppArrayType(ValidatableType::KIND_BUILT_IN, "android.os", "ParcelFileDescriptor",
+                       "binder/ParcelFileDescriptor.h", "::android::os::ParcelFileDescriptor",
+                       "::android::os::ParcelFileDescriptor", "readParcelableVector",
+                       "writeParcelableVector", false);
+
+  Type* nullable_pfd_type =
+      new Type(ValidatableType::KIND_BUILT_IN, "android.os", "ParcelFileDescriptor",
+               {"memory", "binder/ParcelFileDescriptor.h"},
+               "::std::unique_ptr<::android::os::ParcelFileDescriptor>", "readParcelable",
+               "writeNullableParcelable");
+
+  Add(new Type(ValidatableType::KIND_BUILT_IN, "android.os", "ParcelFileDescriptor",
+               {"binder/ParcelFileDescriptor.h"}, "::android::os::ParcelFileDescriptor",
+               "readParcelable", "writeParcelable", pfd_vector_type, nullable_pfd_type));
+
   void_type_ = new class VoidType();
   Add(void_type_);
 }
diff --git a/type_java.cpp b/type_java.cpp
index 0069531..dbc69f1 100644
--- a/type_java.cpp
+++ b/type_java.cpp
@@ -96,6 +96,16 @@
 
 // ================================================================
 
+ParcelFileDescriptorType::ParcelFileDescriptorType(const JavaTypeNamespace* types)
+    : Type(types, "android.os", "ParcelFileDescriptor", ValidatableType::KIND_BUILT_IN, true) {
+  m_array_type.reset(new ParcelFileDescriptorArrayType(types));
+}
+
+ParcelFileDescriptorArrayType::ParcelFileDescriptorArrayType(const JavaTypeNamespace* types)
+    : Type(types, "android.os", "ParcelFileDescriptor", ValidatableType::KIND_BUILT_IN, true) {}
+
+// ================================================================
+
 BooleanType::BooleanType(const JavaTypeNamespace* types)
     : Type(types, "boolean", ValidatableType::KIND_BUILT_IN, true) {
   m_array_type.reset(new BooleanArrayType(types));
@@ -274,6 +284,8 @@
 
   Add(new FileDescriptorType(this));
 
+  Add(new ParcelFileDescriptorType(this));
+
   Add(new CharSequenceType(this));
 
   Add(new MapType(this));
diff --git a/type_java.h b/type_java.h
index e0a8736..7beb5d5 100644
--- a/type_java.h
+++ b/type_java.h
@@ -107,6 +107,20 @@
   explicit FileDescriptorType(const JavaTypeNamespace* types);
 };
 
+class ParcelFileDescriptorArrayType : public Type {
+ public:
+  explicit ParcelFileDescriptorArrayType(const JavaTypeNamespace* types);
+
+  const ValidatableType* NullableType() const override { return this; }
+};
+
+class ParcelFileDescriptorType : public Type {
+ public:
+  explicit ParcelFileDescriptorType(const JavaTypeNamespace* types);
+
+  const ValidatableType* NullableType() const override { return this; }
+};
+
 class BooleanArrayType : public Type {
  public:
   explicit BooleanArrayType(const JavaTypeNamespace* types);
diff --git a/type_namespace.cpp b/type_namespace.cpp
index 3d9fa7b..c0dec44 100644
--- a/type_namespace.cpp
+++ b/type_namespace.cpp
@@ -35,16 +35,13 @@
 // Since packages cannot contain '-' normally, we cannot be asked
 // to create a type that conflicts with these strings.
 const char kAidlReservedTypePackage[] = "aidl-internal";
-const char kUtf8StringClass[] = "Utf8String";
 const char kUtf8InCppStringClass[] = "Utf8InCppString";
 
 // These *must* match the package and class names above.
-const char kUtf8StringCanonicalName[] = "aidl-internal.Utf8String";
 const char kUtf8InCppStringCanonicalName[] = "aidl-internal.Utf8InCppString";
 
 const char kStringCanonicalName[] = "java.lang.String";
 
-const char kUtf8Annotation[] = "@utf8";
 const char kUtf8InCppAnnotation[] = "@utfInCpp";
 
 namespace {
diff --git a/type_namespace.h b/type_namespace.h
index e4a2a92..947d0a1 100644
--- a/type_namespace.h
+++ b/type_namespace.h
@@ -31,11 +31,9 @@
 
 // Special reserved type names.
 extern const char kAidlReservedTypePackage[];
-extern const char kUtf8StringClass[];  // UTF8 wire format string
 extern const char kUtf8InCppStringClass[];  // UTF16 wire format, UTF8 in C++
 
 // Helpful aliases defined to be <kAidlReservedTypePackage>.<class name>
-extern const char kUtf8StringCanonicalName[];
 extern const char kUtf8InCppStringCanonicalName[];
 
 // We sometimes special case this class.
@@ -43,7 +41,6 @@
 
 // Note that these aren't the strings recognized by the parser, we just keep
 // here for the sake of logging a common string constant.
-extern const char kUtf8Annotation[];
 extern const char kUtf8InCppAnnotation[];
 
 class ValidatableType {
@@ -331,9 +328,7 @@
     // Now get the canonical names for these contained types, remapping them if
     // necessary.
     type_name = arg_type->CanonicalName();
-    if (aidl_type.IsUtf8() && type_name == "java.lang.String") {
-      type_name = kUtf8StringCanonicalName;
-    } else if (aidl_type.IsUtf8InCpp() && type_name == "java.lang.String") {
+    if (aidl_type.IsUtf8InCpp() && type_name == "java.lang.String") {
       type_name = kUtf8InCppStringCanonicalName;
     }
     args.emplace_back(type_name);
@@ -375,8 +370,7 @@
       *error_msg = "void type cannot be an array";
       return nullptr;
     }
-    if (aidl_type.IsNullable() || aidl_type.IsUtf8() ||
-        aidl_type.IsUtf8InCpp()) {
+    if (aidl_type.IsNullable() || aidl_type.IsUtf8InCpp()) {
       *error_msg = "void type cannot be annotated";
       return nullptr;
     }
@@ -384,14 +378,6 @@
     return type;
   }
 
-  // No type may be annotated with both these annotations.
-  if (aidl_type.IsUtf8() && aidl_type.IsUtf8InCpp()) {
-    *error_msg = StringPrintf("Type cannot be marked as both %s and %s.",
-                              kUtf8Annotation, kUtf8InCppAnnotation);
-    return nullptr;
-  }
-
-  bool utf8 = aidl_type.IsUtf8();
   bool utf8InCpp = aidl_type.IsUtf8InCpp();
 
   // Strings inside containers get remapped to appropriate utf8 versions when
@@ -399,34 +385,24 @@
   // type.  However, for non-compound types (i.e. those not in a container) we
   // must patch them up here.
   if (IsContainerType(type->CanonicalName())) {
-    utf8 = false;
     utf8InCpp = false;
   } else if (aidl_type.GetName() == "String" ||
              aidl_type.GetName() == "java.lang.String") {
-    utf8 = utf8 || context.IsUtf8();
     utf8InCpp = utf8InCpp || context.IsUtf8InCpp();
-  } else if (utf8 || utf8InCpp) {
-    const char* annotation_literal =
-        (utf8) ? kUtf8Annotation : kUtf8InCppAnnotation;
-    *error_msg = StringPrintf("type '%s' may not be annotated as %s.",
-                              aidl_type.GetName().c_str(),
-                              annotation_literal);
+  } else if (utf8InCpp) {
+    *error_msg = StringPrintf("type '%s' may not be annotated as %s.", aidl_type.GetName().c_str(),
+                              kUtf8InCppAnnotation);
     return nullptr;
   }
 
-  if (utf8) {
-    type = FindTypeByCanonicalName(kUtf8StringCanonicalName);
-  } else if (utf8InCpp) {
+  if (utf8InCpp) {
     type = FindTypeByCanonicalName(kUtf8InCppStringCanonicalName);
   }
 
   // One of our UTF8 transforms made type null
   if (type == nullptr) {
-    const char* annotation_literal =
-        (utf8) ? kUtf8Annotation : kUtf8InCppAnnotation;
-    *error_msg = StringPrintf(
-        "%s is unsupported when generating code for this language.",
-        annotation_literal);
+    *error_msg = StringPrintf("%s is unsupported when generating code for this language.",
+                              kUtf8InCppAnnotation);
     return nullptr;
   }