diff options
author | Martijn Coenen <maco@google.com> | 2016-08-09 12:20:27 +0200 |
---|---|---|
committer | gitbuildkicker <android-build@google.com> | 2016-08-11 17:43:56 -0700 |
commit | 8e66f73ce244a6ff114fa5803a7c77423d69ee46 (patch) | |
tree | 850b957355f5b9cf5da2bdc34fd6b2a0bf4f71b6 | |
parent | bf51e01ed1b2c49571140ba6d0b9b92398d7eaac (diff) | |
download | android_packages_apps_Nfc-8e66f73ce244a6ff114fa5803a7c77423d69ee46.tar.gz android_packages_apps_Nfc-8e66f73ce244a6ff114fa5803a7c77423d69ee46.tar.bz2 android_packages_apps_Nfc-8e66f73ce244a6ff114fa5803a7c77423d69ee46.zip |
Allow for ignore() to work with random UID tags.
By also verifying the NDEF message has changed.
Bug: 30201458
Change-Id: I7349d3d26c63b993ec07ce0c5c55a61a3a396f6e
-rwxr-xr-x | src/com/android/nfc/NfcService.java | 74 |
1 files changed, 43 insertions, 31 deletions
diff --git a/src/com/android/nfc/NfcService.java b/src/com/android/nfc/NfcService.java index 8cf4b50b..6e5af15f 100755 --- a/src/com/android/nfc/NfcService.java +++ b/src/com/android/nfc/NfcService.java @@ -210,6 +210,9 @@ public class NfcService implements DeviceHostListener { int mDebounceTagDebounceMs; ITagRemovedCallback mDebounceTagRemovedCallback; + // Only accessed on one thread so doesn't need locking + NdefMessage mLastReadNdefMessage; + // Metrics AtomicInteger mNumTagsDetected; AtomicInteger mNumP2pDetected; @@ -1828,26 +1831,6 @@ public class NfcService implements DeviceHostListener { debounceTagMs = mDebounceTagDebounceMs; debounceTagRemovedCallback = mDebounceTagRemovedCallback; } - if (debounceTagUid != null) { - if (Arrays.equals(debounceTagUid, tag.getUid())) { - // Still ignoring this tag...poll again and reset debounce timer - mHandler.removeMessages(MSG_TAG_DEBOUNCE); - mHandler.sendEmptyMessageDelayed(MSG_TAG_DEBOUNCE, debounceTagMs); - tag.disconnect(); - return; - } else { - synchronized (NfcService.this) { - mDebounceTagUid = null; - } - if (debounceTagRemovedCallback != null) { - try { - debounceTagRemovedCallback.onTagRemoved(); - } catch (RemoteException e) { - // Ignore - } - } - } - } ReaderModeParams readerParams = null; int presenceCheckDelay = DEFAULT_PRESENCE_CHECK_DELAY; DeviceHost.TagDisconnectedCallback callback = @@ -1870,8 +1853,9 @@ public class NfcService implements DeviceHostListener { } } - boolean playSound = readerParams == null || - (readerParams.flags & NfcAdapter.FLAG_READER_NO_PLATFORM_SOUNDS) == 0; + boolean playSound = (readerParams == null || + (readerParams.flags & NfcAdapter.FLAG_READER_NO_PLATFORM_SOUNDS) == 0) && + debounceTagUid == null; if (mScreenState == ScreenStateHelper.SCREEN_STATE_ON_UNLOCKED && playSound) { playSound(SOUND_START); } @@ -1887,18 +1871,45 @@ public class NfcService implements DeviceHostListener { } NdefMessage ndefMsg = tag.findAndReadNdef(); - if (ndefMsg != null) { - tag.startPresenceChecking(presenceCheckDelay, callback); - dispatchTagEndpoint(tag, readerParams); - } else { - if (tag.reconnect()) { - tag.startPresenceChecking(presenceCheckDelay, callback); - dispatchTagEndpoint(tag, readerParams); - } else { + if (ndefMsg == null) { + // First try to see if this was a bad tag read + if (!tag.reconnect()) { + tag.disconnect(); + if (playSound) { + playSound(SOUND_ERROR); + } + break; + } + } + + if (debounceTagUid != null) { + // If we're debouncing and the UID or the NDEF message of the tag match, + // don't dispatch but drop it. + if (Arrays.equals(debounceTagUid, tag.getUid()) || + (ndefMsg != null && ndefMsg.equals(mLastReadNdefMessage))) { + mHandler.removeMessages(MSG_TAG_DEBOUNCE); + mHandler.sendEmptyMessageDelayed(MSG_TAG_DEBOUNCE, debounceTagMs); tag.disconnect(); - playSound(SOUND_ERROR); + return; + } else { + synchronized (NfcService.this) { + mDebounceTagUid = null; + mDebounceTagRemovedCallback = null; + } + if (debounceTagRemovedCallback != null) { + try { + debounceTagRemovedCallback.onTagRemoved(); + } catch (RemoteException e) { + // Ignore + } + } } } + + mLastReadNdefMessage = ndefMsg; + + tag.startPresenceChecking(presenceCheckDelay, callback); + dispatchTagEndpoint(tag, readerParams); break; case MSG_LLCP_LINK_ACTIVATION: if (mIsDebugBuild) { @@ -1955,6 +1966,7 @@ public class NfcService implements DeviceHostListener { synchronized (NfcService.this) { mDebounceTagUid = null; tagRemovedCallback = mDebounceTagRemovedCallback; + mDebounceTagRemovedCallback = null; } if (tagRemovedCallback != null) { try { |