Expose reconnect(), to allow applications to reset tag state.
Change-Id: Ib5432e7f6b6aaf6ec1cb06693592cb7c6440a6f8
This commit is contained in:
committed by
Jeff Hamilton
parent
4049f9d00a
commit
0d27f999f4
@@ -164,6 +164,40 @@ import android.util.Log;
|
|||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
attemptDeadServiceRecovery(e);
|
attemptDeadServiceRecovery(e);
|
||||||
|
throw new IOException("NFC service died");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Re-connect to the {@link Tag} associated with this connection.
|
||||||
|
* <p>
|
||||||
|
* Reconnecting to a tag can be used to reset the state of the tag itself.
|
||||||
|
* This method blocks until the connection is re-established.
|
||||||
|
* <p>
|
||||||
|
* {@link #close} can be called from another thread to cancel this connection
|
||||||
|
* attempt.
|
||||||
|
* <p>Requires {@link android.Manifest.permission#NFC} permission.
|
||||||
|
* @throws IOException if the target is lost, or connect canceled
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void reconnect() throws IOException {
|
||||||
|
if (!mIsConnected) {
|
||||||
|
throw new IllegalStateException("Technology not connected yet");
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
int errorCode = mTagService.reconnect(mTag.getServiceHandle());
|
||||||
|
|
||||||
|
if (errorCode != ErrorCodes.SUCCESS) {
|
||||||
|
mIsConnected = false;
|
||||||
|
mTag.setTechnologyDisconnected();
|
||||||
|
throw new IOException();
|
||||||
|
}
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
mIsConnected = false;
|
||||||
|
mTag.setTechnologyDisconnected();
|
||||||
|
attemptDeadServiceRecovery(e);
|
||||||
|
throw new IOException("NFC service died");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,6 +81,11 @@ public interface TagTechnology {
|
|||||||
*/
|
*/
|
||||||
public void connect() throws IOException;
|
public void connect() throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public void reconnect() throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Non-blocking. Immediately causes all blocking calls
|
* Non-blocking. Immediately causes all blocking calls
|
||||||
* to throw IOException.
|
* to throw IOException.
|
||||||
|
|||||||
Reference in New Issue
Block a user