[binder] Disable header in Parcel (#27229)

Java side implementation does not use header, so we need
AIBinder_Class_disableInterfaceTokenHeader to disable header.

The weak symbol will be resolved when the libbinder_ndk.so on device is
new enough. Otherwise, our transport implementation will keep using
header.

After SDK and NDK that support API level 32 get released, we will remove
this workaround and specify correct minSDKVersion in AndroidManifest
pull/27245/head
Ming-Chuan 4 years ago committed by GitHub
parent fd0a4624c9
commit e7461d002d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      src/core/ext/transport/binder/wire_format/binder_android.cc

@ -25,6 +25,15 @@
#include "absl/strings/str_cat.h"
#include "src/core/lib/gprpp/sync.h"
// TODO(mingcl): This function is introduced at API level 32 and is not
// available in any NDK release yet. So we export it weakly so that we can use
// it without triggering undefined reference error. Its purpose is to disable
// header in Parcel to conform to the BinderChannel wire format.
extern "C" {
extern void AIBinder_Class_disableInterfaceTokenHeader(AIBinder_Class* clazz)
__attribute__((weak));
}
namespace grpc_binder {
namespace {
@ -92,6 +101,16 @@ TransactionReceiverAndroid::TransactionReceiverAndroid(
/*interfaceDescriptor=*/"", f_onCreate_userdata, f_onDestroy_delete,
f_onTransact);
if (AIBinder_Class_disableInterfaceTokenHeader) {
AIBinder_Class_disableInterfaceTokenHeader(aibinder_class);
} else {
// TODO(mingcl): Make this a fatal error
gpr_log(GPR_ERROR,
"AIBinder_Class_disableInterfaceTokenHeader remain unresolved. "
"This BinderTransport implementation contains header and is not "
"compatible with Java's implementation");
}
// Pass the on-transact callback to the on-create function of the binder. The
// on-create function equips the callback with a mutex and gives it to the
// user data stored in the binder which can be retrieved later.
@ -124,6 +143,17 @@ void AssociateWithNoopClass(AIBinder* binder) {
// Need to associate class before using it
AIBinder_Class* aibinder_class = AIBinder_Class_define(
"", f_onCreate_noop, f_onDestroy_noop, f_onTransact_noop);
if (AIBinder_Class_disableInterfaceTokenHeader) {
AIBinder_Class_disableInterfaceTokenHeader(aibinder_class);
} else {
// TODO(mingcl): Make this a fatal error
gpr_log(GPR_ERROR,
"AIBinder_Class_disableInterfaceTokenHeader remain unresolved. "
"This BinderTransport implementation contains header and is not "
"compatible with Java's implementation");
}
gpr_log(GPR_INFO, "AIBinder_associateClass = %d",
static_cast<int>(AIBinder_associateClass(binder, aibinder_class)));
}

Loading…
Cancel
Save