diff options
| author | George Chang <georgekgchang@google.com> | 2019-12-30 14:53:16 +0800 |
|---|---|---|
| committer | Alisher Alikhodjaev <alisher@google.com> | 2020-01-21 23:46:05 +0000 |
| commit | 3eb265ae00f8032b93f09cb5ef35f2fe196ea37c (patch) | |
| tree | 9c1a82604fe4115847eda48e4dd107e7eb59bb77 /core/java | |
| parent | 046d9393995099335d28af1ba6ce67d3dd2a4e17 (diff) | |
Throw IOException on multiple connects.
Only one TagTechnology can be connected at a time.
Other calls to connect() will return IOException.
Bug: 144398423
Test: check error on multiple connects
Change-Id: I19a5f33c7f0d3e7592fe7791c1e04ddc2c9d6125
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/nfc/Tag.java | 10 | ||||
| -rw-r--r-- | core/java/android/nfc/tech/BasicTagTechnology.java | 5 |
2 files changed, 9 insertions, 6 deletions
diff --git a/core/java/android/nfc/Tag.java b/core/java/android/nfc/Tag.java index 8bb2df0bba58..b9e6ff4a5a9e 100644 --- a/core/java/android/nfc/Tag.java +++ b/core/java/android/nfc/Tag.java @@ -455,12 +455,12 @@ public final class Tag implements Parcelable { * * @hide */ - public synchronized void setConnectedTechnology(int technology) { - if (mConnectedTechnology == -1) { - mConnectedTechnology = technology; - } else { - throw new IllegalStateException("Close other technology first!"); + public synchronized boolean setConnectedTechnology(int technology) { + if (mConnectedTechnology != -1) { + return false; } + mConnectedTechnology = technology; + return true; } /** diff --git a/core/java/android/nfc/tech/BasicTagTechnology.java b/core/java/android/nfc/tech/BasicTagTechnology.java index b6b347ca0619..ae468fead7a2 100644 --- a/core/java/android/nfc/tech/BasicTagTechnology.java +++ b/core/java/android/nfc/tech/BasicTagTechnology.java @@ -75,7 +75,10 @@ abstract class BasicTagTechnology implements TagTechnology { if (errorCode == ErrorCodes.SUCCESS) { // Store this in the tag object - mTag.setConnectedTechnology(mSelectedTechnology); + if (!mTag.setConnectedTechnology(mSelectedTechnology)) { + Log.e(TAG, "Close other technology first!"); + throw new IOException("Only one TagTechnology can be connected at a time."); + } mIsConnected = true; } else if (errorCode == ErrorCodes.ERROR_NOT_SUPPORTED) { throw new UnsupportedOperationException("Connecting to " + |
