Fix Beam&Tag failures after opening NFC-EE.
An earlier MR1 checkin stopped re-registering the remote
device notification callback with libnfc on start_discovery.
This causes a regression since opening the NFC-EE will change
the callback. So Tag&Beam notifications end up going to
the secure element callback - causing crashes or missed tags.
Bug: 5725521
Change-Id: Idddba26b7babae095c124fda44e5b1da37549acd
diff --git a/jni/com_android_nfc_NativeNfcManager.cpp b/jni/com_android_nfc_NativeNfcManager.cpp
index d0a6ed2..34fb838 100644
--- a/jni/com_android_nfc_NativeNfcManager.cpp
+++ b/jni/com_android_nfc_NativeNfcManager.cpp
@@ -599,34 +599,13 @@
nat->discovery_cfg.Duration = 300000; /* in ms */
nat->discovery_cfg.NfcIP_Tgt_Disable = get_p2p_target_disable();
- TRACE("****** NFC Config Mode Reader ******");
-
- /* Register for the reader mode */
- REENTRANCE_LOCK();
- ret = phLibNfc_RemoteDev_NtfRegister(&nat->registry_info, nfc_jni_Discovery_notification_callback, (void *)nat);
- REENTRANCE_UNLOCK();
- if(ret != NFCSTATUS_SUCCESS)
- {
- LOGD("pphLibNfc_RemoteDev_NtfRegister returned 0x%02x",ret);
- goto clean_and_return;
- }
- TRACE("phLibNfc_RemoteDev_NtfRegister(%s-%s-%s-%s-%s-%s-%s-%s) returned 0x%x\n",
- nat->registry_info.Jewel==TRUE?"J":"",
- nat->registry_info.MifareUL==TRUE?"UL":"",
- nat->registry_info.MifareStd==TRUE?"Mi":"",
- nat->registry_info.Felica==TRUE?"F":"",
- nat->registry_info.ISO14443_4A==TRUE?"4A":"",
- nat->registry_info.ISO14443_4B==TRUE?"4B":"",
- nat->registry_info.NFC==TRUE?"P2P":"",
- nat->registry_info.ISO15693==TRUE?"R":"", ret);
-
/* Register for the card emulation mode */
REENTRANCE_LOCK();
ret = phLibNfc_SE_NtfRegister(nfc_jni_transaction_callback,(void *)nat);
REENTRANCE_UNLOCK();
if(ret != NFCSTATUS_SUCCESS)
{
- LOGD("pphLibNfc_RemoteDev_NtfRegister returned 0x%02x",ret);
+ LOGD("phLibNfc_SE_NtfRegister returned 0x%02x",ret);
goto clean_and_return;
}
TRACE("phLibNfc_SE_NtfRegister returned 0x%x\n", ret);
@@ -1429,6 +1408,28 @@
/* Reset device connected flag */
device_connected_flag = 0;
+ /* Register callback for remote device notifications.
+ * Must re-register every time we turn on discovery, since other operations
+ * (such as opening the Secure Element) can change the remote device
+ * notification callback*/
+ REENTRANCE_LOCK();
+ ret = phLibNfc_RemoteDev_NtfRegister(&nat->registry_info, nfc_jni_Discovery_notification_callback, (void *)nat);
+ REENTRANCE_UNLOCK();
+ if(ret != NFCSTATUS_SUCCESS)
+ {
+ LOGD("pphLibNfc_RemoteDev_NtfRegister returned 0x%02x",ret);
+ goto clean_and_return;
+ }
+ TRACE("phLibNfc_RemoteDev_NtfRegister(%s-%s-%s-%s-%s-%s-%s-%s) returned 0x%x\n",
+ nat->registry_info.Jewel==TRUE?"J":"",
+ nat->registry_info.MifareUL==TRUE?"UL":"",
+ nat->registry_info.MifareStd==TRUE?"Mi":"",
+ nat->registry_info.Felica==TRUE?"F":"",
+ nat->registry_info.ISO14443_4A==TRUE?"4A":"",
+ nat->registry_info.ISO14443_4B==TRUE?"4B":"",
+ nat->registry_info.NFC==TRUE?"P2P":"",
+ nat->registry_info.ISO15693==TRUE?"R":"", ret);
+
/* Start Polling loop */
TRACE("****** Start NFC Discovery ******");
REENTRANCE_LOCK();