Log when AIBinder_linkToDeath is called before AIBinder_DeathRecipient_setOnUnlink
It is recommended to first call AIBinder_DeathRecipient_setOnUnlink
before AIBinder_linkToDeath if a cookie object is used.
Ignore-AOSP-First: b/334118276
Test: launch_cvd and look for log
Bug: 334118276
Change-Id: I824b601909b01825eacf26c2ff3a9033031ed535
diff --git a/libs/binder/ndk/ibinder.cpp b/libs/binder/ndk/ibinder.cpp
index c78b9fc..af280d3 100644
--- a/libs/binder/ndk/ibinder.cpp
+++ b/libs/binder/ndk/ibinder.cpp
@@ -487,6 +487,11 @@
"This will cause the onUnlinked callback to be called multiple times with the same "
"cookie, which is usually not intended.");
}
+ if (!mOnUnlinked && cookie) {
+ ALOGW("AIBinder_linkToDeath is being called with a non-null cookie and no onUnlink "
+ "callback set. This might not be intended. AIBinder_DeathRecipient_setOnUnlinked "
+ "should be called first.");
+ }
sp<TransferDeathRecipient> recipient =
new TransferDeathRecipient(binder, cookie, this, mOnDied, mOnUnlinked);