diff options
-rw-r--r-- | jni/com_android_nfc_NativeNfcManager.cpp | 21 | ||||
-rwxr-xr-x | jni/com_android_nfc_NativeNfcSecureElement.cpp | 9 | ||||
-rw-r--r-- | jni/com_android_nfc_NativeNfcTag.cpp | 6 | ||||
-rw-r--r-- | jni/com_android_nfc_NativeP2pDevice.cpp | 5 |
4 files changed, 38 insertions, 3 deletions
diff --git a/jni/com_android_nfc_NativeNfcManager.cpp b/jni/com_android_nfc_NativeNfcManager.cpp index cbff102..127922d 100644 --- a/jni/com_android_nfc_NativeNfcManager.cpp +++ b/jni/com_android_nfc_NativeNfcManager.cpp @@ -33,6 +33,8 @@ void *gHWRef; static phNfc_sData_t gInputParam; static phNfc_sData_t gOutputParam; +uint8_t device_connected_flag; + static phLibNfc_Handle hLlcpHandle; static NFCSTATUS lastErrorStatus = NFCSTATUS_FAILED; static phLibNfc_Llcp_eLinkStatus_t g_eLinkStatus = phFriNfc_LlcpMac_eLinkDefault; @@ -371,6 +373,9 @@ static int nfc_jni_initialize(struct nfc_jni_native_data *nat) { goto clean_and_return; } + /* Reset device connected handle */ + device_connected_flag = 0; + /* Reset stored handle */ storedHandle = 0; @@ -660,6 +665,9 @@ void nfc_jni_restart_discovery_locked(struct nfc_jni_native_data *nat) /* Reset the PN544 ISO XCHG / sw watchdog timeouts */ nfc_jni_reset_timeout_values(); + /* Reset device connected flag */ + device_connected_flag = 0; + /* Restart Polling loop */ TRACE("****** Start NFC Discovery ******"); REENTRANCE_LOCK(); @@ -844,12 +852,15 @@ static void nfc_jni_llcp_linkStatus_callback(void *pContext, sLinkParams.miu, sLinkParams.option, sLinkParams.wks); + device_connected_flag = 1; } } else if(eLinkStatus == phFriNfc_LlcpMac_eLinkDeactivated) { LOGI("LLCP Link deactivated"); free(pContextData); + /* Reset device connected flag */ + device_connected_flag = 0; /* Reset incoming socket list */ while (!LIST_EMPTY(&pMonitor->incoming_socket_head)) @@ -987,7 +998,10 @@ static void nfc_jni_Discovery_notification_callback(void *pContext, { LOG_CALLBACK("nfc_jni_Discovery_notification_callback", status); TRACE("Discovered %d tags", uNofRemoteDev); - + + /* Reset device connected flag */ + device_connected_flag = 1; + if((psRemoteDevList->psRemoteDevInfo->RemDevType == phNfc_eNfcIP1_Initiator) || (psRemoteDevList->psRemoteDevInfo->RemDevType == phNfc_eNfcIP1_Target)) { @@ -1395,6 +1409,9 @@ static void nfc_jni_start_discovery_locked(struct nfc_jni_native_data *nat) /* Reset the PN544 ISO XCHG / sw watchdog timeouts */ nfc_jni_reset_timeout_values(); + /* Reset device connected flag */ + device_connected_flag = 0; + nat->discovery_cfg.NfcIP_Mode = get_p2p_mode(); //initiator nat->discovery_cfg.Duration = 300000; /* in ms */ nat->discovery_cfg.NfcIP_Tgt_Disable = get_p2p_target_disable(); @@ -1832,7 +1849,7 @@ static jboolean com_android_nfc_NfcManager_deinitialize(JNIEnv *e, jobject o) struct nfc_jni_callback_data cb_data; /* Retrieve native structure address */ - nat = nfc_jni_get_nat(e, o); + nat = nfc_jni_get_nat(e, o); /* Clear previous configuration */ memset(&nat->discovery_cfg, 0, sizeof(phLibNfc_sADD_Cfg_t)); diff --git a/jni/com_android_nfc_NativeNfcSecureElement.cpp b/jni/com_android_nfc_NativeNfcSecureElement.cpp index dc4d3ba..97417ea 100755 --- a/jni/com_android_nfc_NativeNfcSecureElement.cpp +++ b/jni/com_android_nfc_NativeNfcSecureElement.cpp @@ -24,6 +24,7 @@ static phNfc_sRemoteDevInformation_t* SecureElementInfo; static int secureElementHandle; extern void *gHWRef; static int SecureElementTech; +extern uint8_t device_connected_flag; namespace android { @@ -202,6 +203,13 @@ static jint com_android_nfc_NativeNfcSecureElement_doOpenSecureElementConnection TRACE("Open Secure Element"); + /* Check if NFC device is already connected to a tag or P2P peer */ + if (device_connected_flag == 1) + { + LOGD("Unable to open SE connection, device already connected to a P2P peer or a Tag"); + goto clean_and_return; + } + /* Test if External RF field is detected */ InParam.buffer = ExternalRFDetected; InParam.length = 3; @@ -213,6 +221,7 @@ static jint com_android_nfc_NativeNfcSecureElement_doOpenSecureElementConnection if(ret!=NFCSTATUS_PENDING) { LOGE("IOCTL status error"); + goto clean_and_return; } /* Wait for callback response */ diff --git a/jni/com_android_nfc_NativeNfcTag.cpp b/jni/com_android_nfc_NativeNfcTag.cpp index b9fcb21..e0b63cb 100644 --- a/jni/com_android_nfc_NativeNfcTag.cpp +++ b/jni/com_android_nfc_NativeNfcTag.cpp @@ -25,7 +25,7 @@ static phLibNfc_Handle handle; uint8_t *nfc_jni_ndef_buf = NULL; uint32_t nfc_jni_ndef_buf_len = 0; - +extern uint8_t device_connected_flag; namespace android { @@ -639,9 +639,12 @@ static jboolean com_android_nfc_NativeNfcTag_doDisconnect(JNIEnv *e, jobject o) { goto clean_and_return; } + result = JNI_TRUE; clean_and_return: + /* Reset device connected flag */ + device_connected_flag = 0; nfc_cb_data_deinit(&cb_data); CONCURRENCY_UNLOCK(); return result; @@ -1051,6 +1054,7 @@ static jboolean com_android_nfc_NativeNfcTag_doPresenceCheck(JNIEnv *e, jobject clean_and_return: nfc_cb_data_deinit(&cb_data); + CONCURRENCY_UNLOCK(); return result; diff --git a/jni/com_android_nfc_NativeP2pDevice.cpp b/jni/com_android_nfc_NativeP2pDevice.cpp index 568379e..78d0bd0 100644 --- a/jni/com_android_nfc_NativeP2pDevice.cpp +++ b/jni/com_android_nfc_NativeP2pDevice.cpp @@ -20,6 +20,8 @@ #include "com_android_nfc.h" +extern uint8_t device_connected_flag; + namespace android { extern void nfc_jni_restart_discovery_locked(struct nfc_jni_native_data *nat); @@ -252,9 +254,12 @@ static jboolean com_android_nfc_NativeP2pDevice_doDisconnect(JNIEnv *e, jobject { goto clean_and_return; } + result = JNI_TRUE; clean_and_return: + /* Reset device connected flag */ + device_connected_flag = 0; nfc_cb_data_deinit(&cb_data); CONCURRENCY_UNLOCK(); return result; |