Nfc: deal with the framework going away.

By calling close() when the framework client dies.

Bug: 35624326
Test: NFC HAL stays alive and works after com.android.nfc is killed
Change-Id: I91fcf6685783cd630a44d19b4cb99127a2c0e89b
diff --git a/nfc/1.0/default/Nfc.cpp b/nfc/1.0/default/Nfc.cpp
index 3bd5e41..c610406 100644
--- a/nfc/1.0/default/Nfc.cpp
+++ b/nfc/1.0/default/Nfc.cpp
@@ -14,12 +14,14 @@
 
 sp<INfcClientCallback> Nfc::mCallback = NULL;
 
-Nfc::Nfc(nfc_nci_device_t* device) : mDevice(device) {
+Nfc::Nfc(nfc_nci_device_t* device) : mDevice(device),
+    mDeathRecipient(new NfcDeathRecipient(this)) {
 }
 
 // Methods from ::android::hardware::nfc::V1_0::INfc follow.
 ::android::hardware::Return<NfcStatus> Nfc::open(const sp<INfcClientCallback>& clientCallback)  {
     mCallback = clientCallback;
+    mCallback->linkToDeath(mDeathRecipient, 0 /*cookie*/);
     int ret = mDevice->open(mDevice, eventCallback, dataCallback);
     return ret == 0 ? NfcStatus::OK : NfcStatus::FAILED;
 }
@@ -39,6 +41,7 @@
 }
 
 ::android::hardware::Return<NfcStatus> Nfc::close()  {
+    mCallback->unlinkToDeath(mDeathRecipient);
     return mDevice->close(mDevice) ? NfcStatus::FAILED : NfcStatus::OK;
 }