Merge "Throw IOException on multiple connects."

This commit is contained in:
Alisher Alikhodjaev
2020-01-22 01:27:04 +00:00
committed by Gerrit Code Review
2 changed files with 9 additions and 6 deletions

View File

@@ -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;
}
/**

View File

@@ -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 " +