diff options
author | Ruchi Kandoi <kandoiruchi@google.com> | 2018-02-05 10:48:27 -0800 |
---|---|---|
committer | Ruchi Kandoi <kandoiruchi@google.com> | 2018-02-07 16:56:55 +0000 |
commit | e6556339e7843be665238dd9b53a22a37d4eddb7 (patch) | |
tree | 50d1a382532a4c51d10d5be5fa3471a335937d29 | |
parent | 77676c035362ecc3d02fb72bb5de74ba57dddf8a (diff) | |
download | SecureElement-e6556339e7843be665238dd9b53a22a37d4eddb7.tar.gz |
Fix return types and exceptions
Throw an exception when NO_SUCH_ELEMENT_ERROR is encountered.
selectResponse should be null if SELECT has not been performed.
mDefaultApplicationSelectedOnBasicChannel should only be reset if the
Secure Element has gone through a reset.
Test: Secure Element initializes
Change-Id: Ibd7f44b1b999d265e39336b764cd729f0156d468
-rw-r--r-- | src/com/android/se/Channel.java | 2 | ||||
-rwxr-xr-x | src/com/android/se/Terminal.java | 19 |
2 files changed, 15 insertions, 6 deletions
diff --git a/src/com/android/se/Channel.java b/src/com/android/se/Channel.java index 56d4f9d..9dff38a 100644 --- a/src/com/android/se/Channel.java +++ b/src/com/android/se/Channel.java @@ -269,7 +269,7 @@ public class Channel implements IBinder.DeathRecipient { * implementation. */ public byte[] getSelectResponse() { - return mSelectResponse; + return (mHasSelectedAid ? mSelectResponse : null); } public boolean isBasicChannel() { diff --git a/src/com/android/se/Terminal.java b/src/com/android/se/Terminal.java index c7348cd..2733a6e 100755 --- a/src/com/android/se/Terminal.java +++ b/src/com/android/se/Terminal.java @@ -82,6 +82,9 @@ public class Terminal { } } else { initializeAccessControl(); + synchronized (mLock) { + mDefaultApplicationSelectedOnBasicChannel = true; + } } } } @@ -202,9 +205,6 @@ public class Terminal { } } catch (RemoteException ignore) { } - synchronized (mLock) { - mDefaultApplicationSelectedOnBasicChannel = true; - } } private void select(byte[] aid) throws RemoteException { @@ -225,8 +225,8 @@ public class Terminal { selectResponse = null; throw new NoSuchElementException("Response length is too small"); } - int sw1 = selectResponse[selectResponse.length - 2]; - int sw2 = selectResponse[selectResponse.length - 1]; + int sw1 = selectResponse[selectResponse.length - 2] & 0xFF; + int sw2 = selectResponse[selectResponse.length - 1] & 0xFF; if (sw1 != 0x90 || sw2 != 0x00) { selectResponse = null; throw new NoSuchElementException("Status word is incorrect"); @@ -276,7 +276,11 @@ public class Terminal { throw new UnsupportedOperationException("OpenBasicChannel() failed"); } else if (status[0] == SecureElementStatus.IOERROR) { throw new ServiceSpecificException(SEService.IO_ERROR, "OpenBasicChannel() failed"); + } else if (status[0] == SecureElementStatus.NO_SUCH_ELEMENT_ERROR) { + throw new ServiceSpecificException(SEService.NO_SUCH_ELEMENT_ERROR, + "OpenBasicChannel() failed"); } + Channel basicChannel = new Channel(session, this, 0, selectResponse, listener); basicChannel.setChannelAccess(channelAccess); @@ -622,6 +626,11 @@ public class Terminal { throw new NullPointerException("session is null"); } mSessions.remove(session); + synchronized (mLock) { + if (mSessions.size() == 0) { + mDefaultApplicationSelectedOnBasicChannel = true; + } + } } @Override |