Support 'debug' in Java.
Now that there are NativeHandles. Note that this affects the in-process
ABI of HIDL objects by adding a new method, but this isn't an ABI we
are relying on for the GSI.
Example:
class Foo extends IFoo.Stub {
@Override
public void debug(NativeHandle handle, ArrayList<String> args) {
FileDescriptor fd = handle.getFileDescriptor();
...
}
...
}
Fixes: 112334405
Test: manual
Change-Id: I2da714451dbc5094c1722dff19f195e98e0b22dc
diff --git a/Interface.cpp b/Interface.cpp
index 44eb872..dae7535 100644
--- a/Interface.cpp
+++ b/Interface.cpp
@@ -424,20 +424,18 @@
return false;
}
- method->fillImplementation(
- HIDL_DEBUG_TRANSACTION,
- {
- {IMPL_INTERFACE,
- [](auto &out) {
- out << "(void)fd;\n"
- << "(void)options;\n"
- << "return ::android::hardware::Void();\n";
- }
- },
- }, /* cppImpl */
- {
- /* unused, as the debug method is hidden from Java */
- } /* javaImpl */
+ method->fillImplementation(HIDL_DEBUG_TRANSACTION,
+ {
+ {IMPL_INTERFACE,
+ [](auto& out) {
+ out << "(void)fd;\n"
+ << "(void)options;\n"
+ << "return ::android::hardware::Void();\n";
+ }},
+ }, /* cppImpl */
+ {
+ {IMPL_INTERFACE, [](auto& out) { out << "return;\n"; }},
+ } /* javaImpl */
);
return true;
diff --git a/Method.cpp b/Method.cpp
index 64a9a65..d81af7c 100644
--- a/Method.cpp
+++ b/Method.cpp
@@ -139,10 +139,6 @@
}
}
-bool Method::isHiddenFromJava() const {
- return isHidlReserved() && name() == "debug";
-}
-
bool Method::overridesCppImpl(MethodImplType type) const {
CHECK(mIsHidlReserved);
return mCppImpl.find(type) != mCppImpl.end();
@@ -257,10 +253,6 @@
}
bool Method::deepIsJavaCompatible(std::unordered_set<const Type*>* visited) const {
- if (isHiddenFromJava()) {
- return true;
- }
-
if (!std::all_of(mArgs->begin(), mArgs->end(),
[&](const auto* arg) { return (*arg)->isJavaCompatible(visited); })) {
return false;
diff --git a/Method.h b/Method.h
index 711f087..22dd08f 100644
--- a/Method.h
+++ b/Method.h
@@ -65,7 +65,6 @@
void cppImpl(MethodImplType type, Formatter &out) const;
void javaImpl(MethodImplType type, Formatter &out) const;
bool isHidlReserved() const { return mIsHidlReserved; }
- bool isHiddenFromJava() const;
const std::vector<Annotation *> &annotations() const;
std::vector<Reference<Type>*> getReferences();
diff --git a/generateJava.cpp b/generateJava.cpp
index fcc1823..33bd289 100644
--- a/generateJava.cpp
+++ b/generateJava.cpp
@@ -216,10 +216,6 @@
emitJavaTypeDeclarations(out);
for (const auto &method : iface->methods()) {
- if (method->isHiddenFromJava()) {
- continue;
- }
-
const bool returnsValue = !method->results().empty();
const bool needsCallback = method->results().size() > 1;
@@ -312,10 +308,6 @@
for (const auto &tuple : iface->allMethodsFromRoot()) {
const Method *method = tuple.method();
- if (method->isHiddenFromJava()) {
- continue;
- }
-
const Interface *superInterface = tuple.interface();
if (prevInterface != superInterface) {
out << "// Methods from "
@@ -457,19 +449,15 @@
out << "}\n\n";
for (Method *method : iface->hidlReservedMethods()) {
- if (method->isHiddenFromJava()) {
- continue;
- }
-
// b/32383557 this is a hack. We need to change this if we have more reserved methods.
CHECK_LE(method->results().size(), 1u);
std::string resultType = method->results().size() == 0 ? "void" :
method->results()[0]->type().getJavaType();
- out << "@Override\npublic final "
- << resultType
- << " "
- << method->name()
- << "(";
+
+ bool canBeOverriden = method->name() == "debug";
+
+ out << "@Override\npublic " << (canBeOverriden ? "" : "final ") << resultType << " "
+ << method->name() << "(";
method->emitJavaArgSignature(out);
out << ") {\n";
@@ -556,19 +544,6 @@
<< superInterface->fullJavaName()
<< ".kInterfaceName);\n\n";
- if (method->isHiddenFromJava()) {
- // This is a method hidden from the Java side of things, it must not
- // return any value and will simply signal success.
- CHECK(!returnsValue);
-
- out << "_hidl_reply.writeStatus(android.os.HwParcel.STATUS_SUCCESS);\n";
- out << "_hidl_reply.send();\n";
- out << "break;\n";
- out.unindent();
- out << "}\n\n";
- continue;
- }
-
for (const auto &arg : method->args()) {
emitJavaReaderWriter(
out,