Resolve some name conflict in auto-gen'd Java code.
HIDL can now use ArrayList, HwBlob etc. as type names.
Bug: 31527497
Test: mma
Change-Id: I76c62d14d4f19a73bbc1de76e88e5be6a7df5542
diff --git a/ArrayType.cpp b/ArrayType.cpp
index a506e0c..14e375a 100644
--- a/ArrayType.cpp
+++ b/ArrayType.cpp
@@ -350,7 +350,7 @@
out << "{\n";
out.indent();
- out << "HwBlob _hidl_blob = ";
+ out << "android.os.HwBlob _hidl_blob = ";
if (isReader) {
out << parcelObj
@@ -359,7 +359,7 @@
size_t align, size;
getAlignmentAndSize(&align, &size);
- out << "new HwBlob("
+ out << "new android.os.HwBlob("
<< size
<< " /* size */);\n";
}
diff --git a/CompoundType.cpp b/CompoundType.cpp
index 626e74f..2715f50 100644
--- a/CompoundType.cpp
+++ b/CompoundType.cpp
@@ -432,25 +432,25 @@
out << "\n";
}
- out << "public final void readFromParcel(HwParcel parcel) {\n";
+ out << "public final void readFromParcel(android.os.HwParcel parcel) {\n";
out.indent();
- out << "HwBlob blob = parcel.readBuffer();\n";
+ out << "android.os.HwBlob blob = parcel.readBuffer();\n";
out << "readEmbeddedFromParcel(parcel, blob, 0 /* parentOffset */);\n";
out.unindent();
out << "}\n\n";
////////////////////////////////////////////////////////////////////////////
- out << "public static final ArrayList<"
+ out << "public static final java.util.ArrayList<"
<< localName()
- << "> readVectorFromParcel(HwParcel parcel) {\n";
+ << "> readVectorFromParcel(android.os.HwParcel parcel) {\n";
out.indent();
- out << "ArrayList<"
+ out << "java.util.ArrayList<"
<< localName()
- << "> _hidl_vec = new ArrayList();\n";
+ << "> _hidl_vec = new java.util.ArrayList();\n";
- out << "HwBlob _hidl_blob = parcel.readBuffer();\n\n";
+ out << "android.os.HwBlob _hidl_blob = parcel.readBuffer();\n\n";
VectorType::EmitJavaFieldReaderWriterForElementType(
out,
@@ -471,7 +471,7 @@
out << "public final void readEmbeddedFromParcel(\n";
out.indent(2);
- out << "HwParcel parcel, HwBlob _hidl_blob, long _hidl_offset) {\n";
+ out << "android.os.HwParcel parcel, android.os.HwBlob _hidl_blob, long _hidl_offset) {\n";
out.unindent();
size_t offset = 0;
@@ -504,10 +504,10 @@
size_t structAlign, structSize;
getAlignmentAndSize(&structAlign, &structSize);
- out << "public final void writeToParcel(HwParcel parcel) {\n";
+ out << "public final void writeToParcel(android.os.HwParcel parcel) {\n";
out.indent();
- out << "HwBlob _hidl_blob = new HwBlob("
+ out << "android.os.HwBlob _hidl_blob = new android.os.HwBlob("
<< structSize
<< " /* size */);\n";
@@ -521,12 +521,12 @@
out << "public static final void writeVectorToParcel(\n";
out.indent(2);
- out << "HwParcel parcel, ArrayList<"
+ out << "android.os.HwParcel parcel, java.util.ArrayList<"
<< localName()
<< "> _hidl_vec) {\n";
out.unindent();
- out << "HwBlob _hidl_blob = new HwBlob(24 /* sizeof(hidl_vec<T>) */);\n";
+ out << "android.os.HwBlob _hidl_blob = new android.os.HwBlob(24 /* sizeof(hidl_vec<T>) */);\n";
VectorType::EmitJavaFieldReaderWriterForElementType(
out,
@@ -547,7 +547,7 @@
out << "public final void writeEmbeddedToBlob(\n";
out.indent(2);
- out << "HwBlob _hidl_blob, long _hidl_offset) {\n";
+ out << "android.os.HwBlob _hidl_blob, long _hidl_offset) {\n";
out.unindent();
offset = 0;
diff --git a/GenericBinder.cpp b/GenericBinder.cpp
index 5c5106e..935da31 100644
--- a/GenericBinder.cpp
+++ b/GenericBinder.cpp
@@ -50,7 +50,7 @@
}
std::string GenericBinder::getJavaType(bool /* forInitializer */) const {
- return "IHwBinder";
+ return "android.os.IHwBinder";
}
void GenericBinder::emitReaderWriter(
diff --git a/Interface.cpp b/Interface.cpp
index 317c18c..24d59ec 100644
--- a/Interface.cpp
+++ b/Interface.cpp
@@ -79,7 +79,7 @@
},
[this](auto &out) { /* javaImpl */
std::vector<const Interface *> chain = typeChain();
- out << "return new ArrayList<String>(Arrays.asList(\n";
+ out << "return new java.util.ArrayList<String>(java.util.Arrays.asList(\n";
out.indent(); out.indent();
for (size_t i = 0; i < chain.size(); ++i) {
if (i != 0)
diff --git a/VectorType.cpp b/VectorType.cpp
index 5b6caf1..a804b5f 100644
--- a/VectorType.cpp
+++ b/VectorType.cpp
@@ -73,7 +73,7 @@
elementJavaType = mElementType->getJavaWrapperType();
}
- return "ArrayList<"
+ return "java.util.ArrayList<"
+ elementJavaType
+ ">";
}
@@ -451,7 +451,7 @@
out << "{\n";
out.indent();
- out << "HwBlob _hidl_blob = ";
+ out << "android.os.HwBlob _hidl_blob = ";
if (isReader) {
out << parcelObj
@@ -460,7 +460,7 @@
size_t align, size;
getAlignmentAndSize(&align, &size);
- out << "new HwBlob("
+ out << "new android.os.HwBlob("
<< size
<< " /* size */);\n";
}
@@ -539,7 +539,7 @@
out << "{\n";
out.indent();
- out << "HwBlob childBlob = "
+ out << "android.os.HwBlob childBlob = "
<< parcelName
<< ".readEmbeddedBuffer(\n";
@@ -622,7 +622,7 @@
elementType->getAlignmentAndSize(&elementAlign, &elementSize);
// XXX make HwBlob constructor take a long instead of an int?
- out << "HwBlob childBlob = new HwBlob((int)(_hidl_vec_size * "
+ out << "android.os.HwBlob childBlob = new android.os.HwBlob((int)(_hidl_vec_size * "
<< elementSize
<< "));\n";
diff --git a/generateJava.cpp b/generateJava.cpp
index 4fa54d8..b4976a4 100644
--- a/generateJava.cpp
+++ b/generateJava.cpp
@@ -77,12 +77,6 @@
out << "package " << mPackage.javaPackage() << ";\n\n";
- out << "import android.os.HwBlob;\n";
- out << "import android.os.HwParcel;\n\n";
-
- out << "import java.util.Arrays;\n";
- out << "import java.util.ArrayList;\n\n";
-
for (const auto &item : mImportedNamesForJava) {
out << "import " << item.javaName() << ";\n";
}
@@ -142,15 +136,6 @@
out << "package " << mPackage.javaPackage() << ";\n\n";
- out << "import android.os.IHwBinder;\n";
- out << "import android.os.IHwInterface;\n";
- out << "import android.os.HwBinder;\n";
- out << "import android.os.HwBlob;\n";
- out << "import android.os.HwParcel;\n\n";
-
- out << "import java.util.Arrays;\n";
- out << "import java.util.ArrayList;\n\n";
-
for (const auto &item : mImportedNamesForJava) {
out << "import " << item.javaName() << ";\n";
}
@@ -168,7 +153,7 @@
if (superType != NULL) {
out << superType->fullJavaName();
} else {
- out << "IHwInterface";
+ out << "android.os.IHwInterface";
}
out << " {\n";
@@ -182,7 +167,7 @@
out << "public static "
<< ifaceName
- << " asInterface(IHwBinder binder) {\n";
+ << " asInterface(android.os.IHwBinder binder) {\n";
out.indent();
@@ -192,7 +177,7 @@
out.unindent();
out << "}\n\n";
- out << "IHwInterface iface =\n";
+ out << "android.os.IHwInterface iface =\n";
out.indent();
out.indent();
out << "binder.queryLocalInterface(kInterfaceName);\n\n";
@@ -213,7 +198,7 @@
out.unindent();
out << "}\n\n";
- out << "public IHwBinder asBinder();\n\n";
+ out << "public android.os.IHwBinder asBinder();\n\n";
out << "public static "
<< ifaceName
@@ -223,7 +208,7 @@
out << "return "
<< ifaceName
- << ".asInterface(HwBinder.getService(\""
+ << ".asInterface(android.os.HwBinder.getService(\""
<< iface->fqName().string()
<< "\",serviceName));\n";
@@ -285,14 +270,14 @@
out.indent();
- out << "private IHwBinder mRemote;\n\n";
- out << "public Proxy(IHwBinder remote) {\n";
+ out << "private android.os.IHwBinder mRemote;\n\n";
+ out << "public Proxy(android.os.IHwBinder remote) {\n";
out.indent();
out << "mRemote = remote;\n";
out.unindent();
out << "}\n\n";
- out << "public IHwBinder asBinder() {\n";
+ out << "public android.os.IHwBinder asBinder() {\n";
out.indent();
out << "return mRemote;\n";
out.unindent();
@@ -335,7 +320,7 @@
out << ") {\n";
out.indent();
- out << "HwParcel request = new HwParcel();\n";
+ out << "android.os.HwParcel request = new android.os.HwParcel();\n";
out << "request.writeInterfaceToken("
<< superInterface->fullJavaName()
<< ".kInterfaceName);\n";
@@ -348,7 +333,7 @@
false /* isReader */);
}
- out << "\nHwParcel reply = new HwParcel();\n"
+ out << "\nandroid.os.HwParcel reply = new android.os.HwParcel();\n"
<< "mRemote.transact("
<< method->getSerialId()
<< " /* "
@@ -356,7 +341,7 @@
<< " */, request, reply, ";
if (method->isOneway()) {
- out << "IHwBinder.FLAG_ONEWAY";
+ out << "android.os.IHwBinder.FLAG_ONEWAY";
} else {
out << "0 /* flags */";
}
@@ -411,13 +396,13 @@
////////////////////////////////////////////////////////////////////////////
- out << "\npublic static abstract class Stub extends HwBinder "
+ out << "\npublic static abstract class Stub extends android.os.HwBinder "
<< "implements "
<< ifaceName << " {\n";
out.indent();
- out << "public IHwBinder asBinder() {\n";
+ out << "public android.os.IHwBinder asBinder() {\n";
out.indent();
out << "return this;\n";
out.unindent();
@@ -436,7 +421,7 @@
out << "\n}\n\n";
}
- out << "public IHwInterface queryLocalInterface(String descriptor) {\n";
+ out << "public android.os.IHwInterface queryLocalInterface(String descriptor) {\n";
out.indent();
// XXX what about potential superClasses?
out << "if (kInterfaceName.equals(descriptor)) {\n";
@@ -457,7 +442,7 @@
out << "}\n\n";
out << "public void onTransact("
- << "int code, HwParcel request, final HwParcel reply, "
+ << "int code, android.os.HwParcel request, final android.os.HwParcel reply, "
<< "int flags) {\n";
out.indent();
@@ -529,7 +514,7 @@
<< ") {\n";
out.indent();
- out << "reply.writeStatus(HwParcel.STATUS_SUCCESS);\n";
+ out << "reply.writeStatus(android.os.HwParcel.STATUS_SUCCESS);\n";
for (const auto &arg : method->results()) {
emitJavaReaderWriter(
@@ -549,7 +534,7 @@
out << ");\n";
if (!needsCallback) {
- out << "reply.writeStatus(HwParcel.STATUS_SUCCESS);\n";
+ out << "reply.writeStatus(android.os.HwParcel.STATUS_SUCCESS);\n";
if (returnsValue) {
const TypedVar *returnArg = method->results()[0];