summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartijn Coenen <maco@google.com>2013-04-25 17:19:40 -0700
committerMartijn Coenen <maco@google.com>2013-04-25 17:29:10 -0700
commit476ee8a64404b7ee042ba1a70400bcb1dd5ace10 (patch)
tree0b18943889d962430922345dcac0afadde15f4fe
parent7a499e775021bafefbe890d079e2a43f4a54482c (diff)
downloadandroid_packages_apps_Nfc-476ee8a64404b7ee042ba1a70400bcb1dd5ace10.tar.gz
android_packages_apps_Nfc-476ee8a64404b7ee042ba1a70400bcb1dd5ace10.tar.bz2
android_packages_apps_Nfc-476ee8a64404b7ee042ba1a70400bcb1dd5ace10.zip
Fix more race conditions.
In the old NXP JNI: - We can be in the process of discovering a tag/p2p target when we try to configure discovery. In case ConfigureDiscovery returns BUSY, don't immediately call abort(), but retry a few times. - Completely disable Tag/P2P discovery *before* opening a pipe to the SMX. This avoids nasty races with opening the SMX while a P2P/Tag device enters the field. Bug: 8552749 Change-Id: I433a40c918373c661abda3bc40dd36db7b233245
-rw-r--r--nxp/jni/com_android_nfc_NativeNfcManager.cpp20
-rwxr-xr-xsrc/com/android/nfc/NfcService.java16
2 files changed, 34 insertions, 2 deletions
diff --git a/nxp/jni/com_android_nfc_NativeNfcManager.cpp b/nxp/jni/com_android_nfc_NativeNfcManager.cpp
index 098f8a72..e144ea99 100644
--- a/nxp/jni/com_android_nfc_NativeNfcManager.cpp
+++ b/nxp/jni/com_android_nfc_NativeNfcManager.cpp
@@ -1305,6 +1305,7 @@ static void nfc_jni_start_discovery_locked(struct nfc_jni_native_data *nat, bool
{
NFCSTATUS ret;
struct nfc_jni_callback_data cb_data;
+ int numRetries = 3;
/* Create the local semaphore */
if (!nfc_cb_data_init(&cb_data, NULL))
@@ -1321,7 +1322,7 @@ static void nfc_jni_start_discovery_locked(struct nfc_jni_native_data *nat, bool
/* Reset device connected flag */
device_connected_flag = 0;
-
+configure:
/* Start Polling loop */
TRACE("****** Start NFC Discovery ******");
REENTRANCE_LOCK();
@@ -1338,6 +1339,13 @@ static void nfc_jni_start_discovery_locked(struct nfc_jni_native_data *nat, bool
nat->discovery_cfg.PollDevInfo.PollCfgInfo.DisableCardEmulation==FALSE?"CE":"",
nat->discovery_cfg.NfcIP_Mode, nat->discovery_cfg.Duration, ret);
+ if (ret == NFCSTATUS_BUSY && numRetries-- > 0)
+ {
+ TRACE("ConfigDiscovery BUSY, retrying");
+ usleep(1000000);
+ goto configure;
+ }
+
if(ret != NFCSTATUS_PENDING)
{
emergency_recovery(nat);
@@ -1360,6 +1368,7 @@ static void nfc_jni_stop_discovery_locked(struct nfc_jni_native_data *nat)
phLibNfc_sADD_Cfg_t discovery_cfg;
NFCSTATUS ret;
struct nfc_jni_callback_data cb_data;
+ int numRetries = 3;
/* Create the local semaphore */
if (!nfc_cb_data_init(&cb_data, NULL))
@@ -1372,6 +1381,7 @@ static void nfc_jni_stop_discovery_locked(struct nfc_jni_native_data *nat)
discovery_cfg.NfcIP_Target_Mode = 0;
discovery_cfg.NfcIP_Tgt_Disable = TRUE;
+configure:
/* Start Polling loop */
TRACE("****** Stop NFC Discovery ******");
REENTRANCE_LOCK();
@@ -1387,8 +1397,16 @@ static void nfc_jni_stop_discovery_locked(struct nfc_jni_native_data *nat)
discovery_cfg.PollDevInfo.PollCfgInfo.DisableCardEmulation==FALSE?"CE":"",
discovery_cfg.NfcIP_Mode, discovery_cfg.Duration, ret);
+ if (ret == NFCSTATUS_BUSY && numRetries-- > 0)
+ {
+ TRACE("ConfigDiscovery BUSY, retrying");
+ usleep(1000000);
+ goto configure;
+ }
+
if(ret != NFCSTATUS_PENDING)
{
+ ALOGE("[STOP] ConfigDiscovery returned %x", ret);
emergency_recovery(nat);
}
diff --git a/src/com/android/nfc/NfcService.java b/src/com/android/nfc/NfcService.java
index 306b7066..f6ca3b55 100755
--- a/src/com/android/nfc/NfcService.java
+++ b/src/com/android/nfc/NfcService.java
@@ -1406,8 +1406,23 @@ public class NfcService implements DeviceHostListener {
return EE_ERROR_ALREADY_OPEN;
}
+ boolean restorePolling = false;
+ if (mDeviceHost.enablePN544Quirks() && mNfcPollingEnabled) {
+ // Disable polling for tags/P2P when connecting to the SMX
+ // on PN544-based devices. Whenever nfceeClose is called,
+ // the polling configuration will be restored.
+ mDeviceHost.disableDiscovery();
+ mNfcPollingEnabled = false;
+ restorePolling = true;
+ }
+
int handle = doOpenSecureElementConnection();
if (handle < 0) {
+
+ if (restorePolling) {
+ mDeviceHost.enableDiscovery();
+ mNfcPollingEnabled = true;
+ }
return handle;
}
mDeviceHost.setTimeout(TagTechnology.ISO_DEP, 30000);
@@ -1938,7 +1953,6 @@ public class NfcService implements DeviceHostListener {
sendSeBroadcast(listenModeDeactivated);
break;
}
-
default:
Log.e(TAG, "Unknown message received");
break;