diff options
| -rw-r--r-- | libs/binder/ndk/ibinder.cpp | 13 | ||||
| -rw-r--r-- | libs/binder/ndk/ibinder_internal.h | 3 | ||||
| -rw-r--r-- | libs/binder/ndk/include_ndk/android/binder_ibinder.h | 15 | ||||
| -rw-r--r-- | libs/binder/ndk/libbinder_ndk.map.txt | 5 |
4 files changed, 34 insertions, 2 deletions
diff --git a/libs/binder/ndk/ibinder.cpp b/libs/binder/ndk/ibinder.cpp index 717beecff4..f88896f702 100644 --- a/libs/binder/ndk/ibinder.cpp +++ b/libs/binder/ndk/ibinder.cpp @@ -172,7 +172,7 @@ status_t ABBinder::dump(int fd, const ::android::Vector<String16>& args) { status_t ABBinder::onTransact(transaction_code_t code, const Parcel& data, Parcel* reply, binder_flags_t flags) { if (isUserCommand(code)) { - if (!data.checkInterface(this)) { + if (getClass()->writeHeader && !data.checkInterface(this)) { return STATUS_BAD_TYPE; } @@ -354,6 +354,12 @@ void AIBinder_Class_setOnDump(AIBinder_Class* clazz, AIBinder_onDump onDump) { clazz->onDump = onDump; } +void AIBinder_Class_disableInterfaceTokenHeader(AIBinder_Class* clazz) { + CHECK(clazz != nullptr) << "disableInterfaceTokenHeader requires non-null clazz"; + + clazz->writeHeader = false; +} + void AIBinder_Class_setHandleShellCommand(AIBinder_Class* clazz, AIBinder_handleShellCommand handleShellCommand) { CHECK(clazz != nullptr) << "setHandleShellCommand requires non-null clazz"; @@ -606,7 +612,10 @@ binder_status_t AIBinder_prepareTransaction(AIBinder* binder, AParcel** in) { *in = new AParcel(binder); (*in)->get()->markForBinder(binder->getBinder()); - status_t status = (*in)->get()->writeInterfaceToken(clazz->getInterfaceDescriptor()); + status_t status = android::OK; + if (clazz->writeHeader) { + status = (*in)->get()->writeInterfaceToken(clazz->getInterfaceDescriptor()); + } binder_status_t ret = PruneStatusT(status); if (ret != STATUS_OK) { diff --git a/libs/binder/ndk/ibinder_internal.h b/libs/binder/ndk/ibinder_internal.h index 3b515abaf7..3cb95ea837 100644 --- a/libs/binder/ndk/ibinder_internal.h +++ b/libs/binder/ndk/ibinder_internal.h @@ -116,6 +116,9 @@ struct AIBinder_Class { const ::android::String16& getInterfaceDescriptor() const { return mWideInterfaceDescriptor; } const char* getInterfaceDescriptorUtf8() const { return mInterfaceDescriptor.c_str(); } + // whether a transaction header should be written + bool writeHeader = true; + // required to be non-null, implemented for every class const AIBinder_Class_onCreate onCreate = nullptr; const AIBinder_Class_onDestroy onDestroy = nullptr; diff --git a/libs/binder/ndk/include_ndk/android/binder_ibinder.h b/libs/binder/ndk/include_ndk/android/binder_ibinder.h index 78f2d3af14..c82df8319a 100644 --- a/libs/binder/ndk/include_ndk/android/binder_ibinder.h +++ b/libs/binder/ndk/include_ndk/android/binder_ibinder.h @@ -219,6 +219,21 @@ typedef binder_status_t (*AIBinder_onDump)(AIBinder* binder, int fd, const char* void AIBinder_Class_setOnDump(AIBinder_Class* clazz, AIBinder_onDump onDump) __INTRODUCED_IN(29); /** + * This tells users of this class not to use a transaction header. By default, libbinder_ndk users + * read/write transaction headers implicitly (in the SDK, this must be manually written by + * android.os.Parcel#writeInterfaceToken, and it is read/checked with + * android.os.Parcel#enforceInterface). This method is provided in order to talk to legacy code + * which does not write an interface token. When this is disabled, type safety is reduced, so you + * must have a separate way of determining the binder you are talking to is the right type. Must + * be called before any instance of the class is created. + * + * Available since API level 32. + * + * \param clazz class to disable interface header on. + */ +void AIBinder_Class_disableInterfaceTokenHeader(AIBinder_Class* clazz) __INTRODUCED_IN(32); + +/** * Creates a new binder object of the appropriate class. * * Ownership of args is passed to this object. The lifecycle is implemented with AIBinder_incStrong diff --git a/libs/binder/ndk/libbinder_ndk.map.txt b/libs/binder/ndk/libbinder_ndk.map.txt index 685ebb5023..1975bdc52c 100644 --- a/libs/binder/ndk/libbinder_ndk.map.txt +++ b/libs/binder/ndk/libbinder_ndk.map.txt @@ -141,6 +141,11 @@ LIBBINDER_NDK31 { # introduced=31 AParcel_reset; }; +LIBBINDER_NDK32 { # introduced=32 + global: + AIBinder_Class_disableInterfaceTokenHeader; +}; + LIBBINDER_NDK_PLATFORM { global: AParcel_getAllowFds; |