Loading core/java/android/nfc/INfcTag.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ import android.nfc.NdefMessage; interface INfcTag { int close(int nativeHandle); int connect(int nativeHandle); int connect(int nativeHandle, int technology); int reconnect(int nativeHandle); int[] getTechList(int nativeHandle); byte[] getUid(int nativeHandle); Loading core/java/android/nfc/Tag.java +29 −0 Original line number Diff line number Diff line Loading @@ -63,6 +63,8 @@ public class Tag implements Parcelable { /*package*/ final Bundle[] mTechExtras; /*package*/ final int mServiceHandle; // for use by NFC service, 0 indicates a mock /*package*/ int mConnectedTechnology; /** * Hidden constructor to be used by NFC service and internal classes. * @hide Loading @@ -76,6 +78,8 @@ public class Tag implements Parcelable { // Ensure mTechExtras is as long as mTechList mTechExtras = Arrays.copyOf(techListExtras, techList.length); mServiceHandle = serviceHandle; mConnectedTechnology = -1; } /** Loading Loading @@ -244,4 +248,29 @@ public class Tag implements Parcelable { return new Tag[size]; } }; /* * @hide */ public synchronized void setConnectedTechnology(int technology) { if (mConnectedTechnology == -1) { mConnectedTechnology = technology; } else { throw new IllegalStateException("Close other technology first!"); } } /* * @hide */ public int getConnectedTechnology() { return mConnectedTechnology; } /* * @hide */ public void setTechnologyDisconnected() { mConnectedTechnology = -1; } } core/java/android/nfc/technology/BasicTagTechnology.java +26 −3 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.nfc.INfcAdapter; import android.nfc.INfcTag; import android.nfc.NfcAdapter; import android.nfc.Tag; import android.nfc.ErrorCodes; import android.os.RemoteException; import android.util.Log; Loading Loading @@ -101,6 +102,13 @@ import android.util.Log; return mTag; } public void checkConnected() { if ((mTag.getConnectedTechnology() != getTechnologyId()) || (mTag.getConnectedTechnology() == -1)) { throw new IllegalStateException("Call connect() first!"); } } /** * <p>Requires {@link android.Manifest.permission#NFC} permission. */ Loading Loading @@ -144,8 +152,19 @@ import android.util.Log; */ @Override public void connect() throws IOException { //TODO(nxp): enforce exclusivity try { int errorCode = mTagService.connect(mTag.getServiceHandle(), getTechnologyId()); if (errorCode == ErrorCodes.SUCCESS) { // Store this in the tag object mTag.setConnectedTechnology(getTechnologyId()); mIsConnected = true; } else { throw new IOException(); } } catch (RemoteException e) { attemptDeadServiceRecovery(e); } } /** Loading @@ -160,7 +179,6 @@ import android.util.Log; */ @Override public void close() { mIsConnected = false; try { /* Note that we don't want to physically disconnect the tag, * but just reconnect to it to reset its state Loading @@ -168,6 +186,9 @@ import android.util.Log; mTagService.reconnect(mTag.getServiceHandle()); } catch (RemoteException e) { attemptDeadServiceRecovery(e); } finally { mIsConnected = false; mTag.setTechnologyDisconnected(); } } Loading @@ -183,6 +204,8 @@ import android.util.Log; * @throws IOException if the target is lost or connection closed */ public byte[] transceive(byte[] data) throws IOException { checkConnected(); try { byte[] response = mTagService.transceive(mTag.getServiceHandle(), data, true); if (response == null) { Loading core/java/android/nfc/technology/IsoDep.java +2 −0 Original line number Diff line number Diff line Loading @@ -75,6 +75,8 @@ public final class IsoDep extends BasicTagTechnology { * @throws IOException, UnsupportedOperationException */ public void selectAid(byte[] aid) throws IOException, UnsupportedOperationException { checkConnected(); throw new UnsupportedOperationException(); } } core/java/android/nfc/technology/MifareClassic.java +6 −0 Original line number Diff line number Diff line Loading @@ -229,6 +229,8 @@ public final class MifareClassic extends BasicTagTechnology { * Authenticate for a given sector. */ public boolean authenticateSector(int sector, byte[] key, boolean keyA) { checkConnected(); byte[] cmd = new byte[12]; // First byte is the command Loading Loading @@ -264,6 +266,8 @@ public final class MifareClassic extends BasicTagTechnology { * @throws IOException */ public byte[] readBlock(int sector, int block) throws IOException { checkConnected(); byte addr = (byte) ((firstBlockInSector(sector) + block) & 0xff); byte[] blockread_cmd = { 0x30, addr }; // phHal_eMifareRead Loading Loading @@ -300,6 +304,8 @@ public final class MifareClassic extends BasicTagTechnology { */ @Override public byte[] transceive(byte[] data) throws IOException { checkConnected(); try { byte[] response = mTagService.transceive(mTag.getServiceHandle(), data, false); if (response == null) { Loading Loading
core/java/android/nfc/INfcTag.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ import android.nfc.NdefMessage; interface INfcTag { int close(int nativeHandle); int connect(int nativeHandle); int connect(int nativeHandle, int technology); int reconnect(int nativeHandle); int[] getTechList(int nativeHandle); byte[] getUid(int nativeHandle); Loading
core/java/android/nfc/Tag.java +29 −0 Original line number Diff line number Diff line Loading @@ -63,6 +63,8 @@ public class Tag implements Parcelable { /*package*/ final Bundle[] mTechExtras; /*package*/ final int mServiceHandle; // for use by NFC service, 0 indicates a mock /*package*/ int mConnectedTechnology; /** * Hidden constructor to be used by NFC service and internal classes. * @hide Loading @@ -76,6 +78,8 @@ public class Tag implements Parcelable { // Ensure mTechExtras is as long as mTechList mTechExtras = Arrays.copyOf(techListExtras, techList.length); mServiceHandle = serviceHandle; mConnectedTechnology = -1; } /** Loading Loading @@ -244,4 +248,29 @@ public class Tag implements Parcelable { return new Tag[size]; } }; /* * @hide */ public synchronized void setConnectedTechnology(int technology) { if (mConnectedTechnology == -1) { mConnectedTechnology = technology; } else { throw new IllegalStateException("Close other technology first!"); } } /* * @hide */ public int getConnectedTechnology() { return mConnectedTechnology; } /* * @hide */ public void setTechnologyDisconnected() { mConnectedTechnology = -1; } }
core/java/android/nfc/technology/BasicTagTechnology.java +26 −3 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.nfc.INfcAdapter; import android.nfc.INfcTag; import android.nfc.NfcAdapter; import android.nfc.Tag; import android.nfc.ErrorCodes; import android.os.RemoteException; import android.util.Log; Loading Loading @@ -101,6 +102,13 @@ import android.util.Log; return mTag; } public void checkConnected() { if ((mTag.getConnectedTechnology() != getTechnologyId()) || (mTag.getConnectedTechnology() == -1)) { throw new IllegalStateException("Call connect() first!"); } } /** * <p>Requires {@link android.Manifest.permission#NFC} permission. */ Loading Loading @@ -144,8 +152,19 @@ import android.util.Log; */ @Override public void connect() throws IOException { //TODO(nxp): enforce exclusivity try { int errorCode = mTagService.connect(mTag.getServiceHandle(), getTechnologyId()); if (errorCode == ErrorCodes.SUCCESS) { // Store this in the tag object mTag.setConnectedTechnology(getTechnologyId()); mIsConnected = true; } else { throw new IOException(); } } catch (RemoteException e) { attemptDeadServiceRecovery(e); } } /** Loading @@ -160,7 +179,6 @@ import android.util.Log; */ @Override public void close() { mIsConnected = false; try { /* Note that we don't want to physically disconnect the tag, * but just reconnect to it to reset its state Loading @@ -168,6 +186,9 @@ import android.util.Log; mTagService.reconnect(mTag.getServiceHandle()); } catch (RemoteException e) { attemptDeadServiceRecovery(e); } finally { mIsConnected = false; mTag.setTechnologyDisconnected(); } } Loading @@ -183,6 +204,8 @@ import android.util.Log; * @throws IOException if the target is lost or connection closed */ public byte[] transceive(byte[] data) throws IOException { checkConnected(); try { byte[] response = mTagService.transceive(mTag.getServiceHandle(), data, true); if (response == null) { Loading
core/java/android/nfc/technology/IsoDep.java +2 −0 Original line number Diff line number Diff line Loading @@ -75,6 +75,8 @@ public final class IsoDep extends BasicTagTechnology { * @throws IOException, UnsupportedOperationException */ public void selectAid(byte[] aid) throws IOException, UnsupportedOperationException { checkConnected(); throw new UnsupportedOperationException(); } }
core/java/android/nfc/technology/MifareClassic.java +6 −0 Original line number Diff line number Diff line Loading @@ -229,6 +229,8 @@ public final class MifareClassic extends BasicTagTechnology { * Authenticate for a given sector. */ public boolean authenticateSector(int sector, byte[] key, boolean keyA) { checkConnected(); byte[] cmd = new byte[12]; // First byte is the command Loading Loading @@ -264,6 +266,8 @@ public final class MifareClassic extends BasicTagTechnology { * @throws IOException */ public byte[] readBlock(int sector, int block) throws IOException { checkConnected(); byte addr = (byte) ((firstBlockInSector(sector) + block) & 0xff); byte[] blockread_cmd = { 0x30, addr }; // phHal_eMifareRead Loading Loading @@ -300,6 +304,8 @@ public final class MifareClassic extends BasicTagTechnology { */ @Override public byte[] transceive(byte[] data) throws IOException { checkConnected(); try { byte[] response = mTagService.transceive(mTag.getServiceHandle(), data, false); if (response == null) { Loading