INfcTag isPresent() should not block and not cause RF activity.
Use a cached value instead, which is based on the presence check that is running
anyway.
Change-Id: Ifa50ff38e884fa865bb7ba95dde45da39bebf7e8
diff --git a/src/com/android/nfc/NativeNfcTag.java b/src/com/android/nfc/NativeNfcTag.java
index 1d05f25..ffebb62 100755
--- a/src/com/android/nfc/NativeNfcTag.java
+++ b/src/com/android/nfc/NativeNfcTag.java
@@ -45,6 +45,8 @@
private final String TAG = "NativeNfcTag";
+ private boolean mIsPresent; // Whether the tag is known to be still present
+
private PresenceCheckWatchdog mWatchdog;
class PresenceCheckWatchdog extends Thread {
@@ -178,16 +180,26 @@
}
public synchronized void startPresenceChecking() {
+ // Once we start presence checking, we allow the upper layers
+ // to know the tag is in the field.
+ mIsPresent = true;
if (mWatchdog == null) {
mWatchdog = new PresenceCheckWatchdog();
mWatchdog.start();
}
}
+ public synchronized boolean isPresent() {
+ // Returns whether the tag is still in the field to the best
+ // of our knowledge.
+ return mIsPresent;
+ }
+
native boolean doDisconnect();
public synchronized boolean disconnect() {
boolean result = false;
+ mIsPresent = false;
if (mWatchdog != null) {
// Watchdog has already disconnected or will do it
mWatchdog.end();
diff --git a/src/com/android/nfc/NfcService.java b/src/com/android/nfc/NfcService.java
index 6d627de..9c14303 100755
--- a/src/com/android/nfc/NfcService.java
+++ b/src/com/android/nfc/NfcService.java
@@ -1432,7 +1432,7 @@
return false;
}
- return tag.presenceCheck();
+ return tag.isPresent();
}
@Override