libbinder_ndk: ABBinder objects are tagged.
This allows us to always cast an object directly to the underlying
object rather than temporarily putting it behind a proxy. This also
simplifies the AIBinder_associateClass API greatly.
As a side-effect, this also fixes reading null parcelables from
binder buffers due to a previously missing check.
Bug: 111445392
Test: runtests.sh
Change-Id: I0c9a75132f9da35a2500b1e83f218b180b2dda36
diff --git a/libs/binder/ndk/test/iface.cpp b/libs/binder/ndk/test/iface.cpp
index eed09f0..1317a74 100644
--- a/libs/binder/ndk/test/iface.cpp
+++ b/libs/binder/ndk/test/iface.cpp
@@ -118,12 +118,15 @@
sp<IFoo> IFoo::getService(const char* instance) {
AIBinder* binder = AServiceManager_getService(instance); // maybe nullptr
- AIBinder_associateClass(&binder, IFoo::kClass);
-
if (binder == nullptr) {
return nullptr;
}
+ if (!AIBinder_associateClass(binder, IFoo::kClass)) {
+ AIBinder_decStrong(binder);
+ return nullptr;
+ }
+
if (AIBinder_isRemote(binder)) {
sp<IFoo> ret = new BpFoo(binder); // takes ownership of binder
return ret;