Remove the use of the death recipient cookie
It is unnecessary and we don't always know if the NfcAdaptation object
is still valid.
Test: atest CtsNfcTestCases
Test: adb shell svc nfc disable
Test: adb shell svc nfc enable
Test: adb shell kill `pid android.hardware.nfc-service.cuttlefish`
Bug: 319210610
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:61e85a0efb40101a67004bbdde92ecb3e2619245)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:f81fc62613265a286b8c1b8308c6f742e8329850)
Merged-In: I17c707adc4e47220754726c099f7c5449cd68d28
Change-Id: I17c707adc4e47220754726c099f7c5449cd68d28
diff --git a/src/adaptation/NfcAdaptation.cc b/src/adaptation/NfcAdaptation.cc
index 711ae00..7870ec5 100644
--- a/src/adaptation/NfcAdaptation.cc
+++ b/src/adaptation/NfcAdaptation.cc
@@ -140,6 +140,13 @@
DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf(
"%s: nfc_nci_reset_type=%u", __func__, nfc_nci_reset_type);
}
+
+// Abort nfc service when AIDL process died.
+void HalAidlBinderDied(void* /* cookie */) {
+ LOG(ERROR) << __func__ << "INfc aidl hal died, exiting procces to restart";
+ exit(0);
+}
+
} // namespace
class NfcClientCallback : public INfcClientCallback {
@@ -285,7 +292,7 @@
NfcAdaptation::NfcAdaptation() {
memset(&mHalEntryFuncs, 0, sizeof(mHalEntryFuncs));
mDeathRecipient = ::ndk::ScopedAIBinder_DeathRecipient(
- AIBinder_DeathRecipient_new(NfcAdaptation::HalAidlBinderDied));
+ AIBinder_DeathRecipient_new(HalAidlBinderDied));
}
/*******************************************************************************
@@ -578,7 +585,7 @@
if (mAidlHal != nullptr) {
AIBinder_unlinkToDeath(mAidlHal->asBinder().get(), mDeathRecipient.get(),
- this);
+ nullptr);
} else if (mHal != nullptr) {
mNfcHalDeathRecipient->finalize();
}
@@ -600,7 +607,7 @@
if (mAidlHal != nullptr) {
mAidlHal->close(NfcCloseType::HOST_SWITCHED_OFF);
AIBinder_unlinkToDeath(mAidlHal->asBinder().get(), mDeathRecipient.get(),
- this);
+ nullptr);
mAidlHal = nullptr;
} else {
if (mHal_1_2 != nullptr) {
@@ -734,7 +741,7 @@
if (mAidlHal != nullptr) {
use_aidl = true;
AIBinder_linkToDeath(mAidlHal->asBinder().get(), mDeathRecipient.get(),
- this /* cookie */);
+ nullptr /* cookie */);
mHal = mHal_1_1 = mHal_1_2 = nullptr;
LOG(INFO) << StringPrintf("%s: INfcAidl::fromBinder returned", func);
}
@@ -1051,31 +1058,6 @@
/*******************************************************************************
**
-** Function: NfcAdaptation::HalAidlBinderDiedImpl
-**
-** Description: Abort nfc service when AIDL process died.
-**
-** Returns: None.
-**
-*******************************************************************************/
-void NfcAdaptation::HalAidlBinderDiedImpl() {
- LOG(WARNING) << __func__ << "INfc aidl hal died, resetting the state";
- if (mAidlHal != nullptr) {
- AIBinder_unlinkToDeath(mAidlHal->asBinder().get(), mDeathRecipient.get(),
- this);
- mAidlHal = nullptr;
- }
- exit(0);
-}
-
-// static
-void NfcAdaptation::HalAidlBinderDied(void* cookie) {
- auto thiz = static_cast<NfcAdaptation*>(cookie);
- thiz->HalAidlBinderDiedImpl();
-}
-
-/*******************************************************************************
-**
** Function: ThreadMutex::ThreadMutex()
**
** Description: class constructor
diff --git a/src/include/NfcAdaptation.h b/src/include/NfcAdaptation.h
index 4c63ea3..3ea9cde 100644
--- a/src/include/NfcAdaptation.h
+++ b/src/include/NfcAdaptation.h
@@ -138,9 +138,4 @@
nfc_status_t event_status);
static void HalDownloadFirmwareDataCallback(uint16_t data_len,
uint8_t* p_data);
-
- // Death recipient callback that is called when INfcAidl dies.
- // The cookie is a pointer to a NfcAdaptation object.
- static void HalAidlBinderDied(void* cookie);
- void HalAidlBinderDiedImpl();
};