diff options
| -rw-r--r-- | core/java/android/se/omapi/Channel.java | 9 | ||||
| -rw-r--r-- | core/java/android/se/omapi/Reader.java | 8 | ||||
| -rw-r--r-- | core/java/android/se/omapi/SEService.java | 17 | ||||
| -rw-r--r-- | core/java/android/se/omapi/Session.java | 21 |
4 files changed, 48 insertions, 7 deletions
diff --git a/core/java/android/se/omapi/Channel.java b/core/java/android/se/omapi/Channel.java index f0b9fa2de5d2..65ce67fcba8f 100644 --- a/core/java/android/se/omapi/Channel.java +++ b/core/java/android/se/omapi/Channel.java @@ -25,6 +25,7 @@ package android.se.omapi; import android.annotation.NonNull; import android.annotation.Nullable; import android.os.RemoteException; +import android.os.ServiceSpecificException; import android.util.Log; import java.io.IOException; @@ -168,8 +169,10 @@ public class Channel { throw new IOException("Error in communicating with Secure Element"); } return response; - } catch (RemoteException e) { + } catch (ServiceSpecificException e) { throw new IOException(e.getMessage()); + } catch (RemoteException e) { + throw new IllegalStateException(e.getMessage()); } } } @@ -244,8 +247,10 @@ public class Channel { synchronized (mLock) { return mChannel.selectNext(); } - } catch (RemoteException e) { + } catch (ServiceSpecificException e) { throw new IOException(e.getMessage()); + } catch (RemoteException e) { + throw new IllegalStateException(e.getMessage()); } } } diff --git a/core/java/android/se/omapi/Reader.java b/core/java/android/se/omapi/Reader.java index 9f1573973be4..3dec97631e9c 100644 --- a/core/java/android/se/omapi/Reader.java +++ b/core/java/android/se/omapi/Reader.java @@ -24,6 +24,7 @@ package android.se.omapi; import android.annotation.NonNull; import android.os.RemoteException; +import android.os.ServiceSpecificException; import android.util.Log; import java.io.IOException; @@ -45,8 +46,7 @@ public class Reader { private final Object mLock = new Object(); - Reader(SEService service, String name, ISecureElementReader reader) throws - IOException { + Reader(SEService service, String name, ISecureElementReader reader) { if (reader == null || service == null || name == null) { throw new IllegalArgumentException("Parameters cannot be null"); } @@ -96,8 +96,10 @@ public class Reader { ISecureElementSession session; try { session = mReader.openSession(); - } catch (RemoteException e) { + } catch (ServiceSpecificException e) { throw new IOException(e.getMessage()); + } catch (RemoteException e) { + throw new IllegalStateException(e.getMessage()); } if (session == null) { throw new IOException("service session is null."); diff --git a/core/java/android/se/omapi/SEService.java b/core/java/android/se/omapi/SEService.java index 1e37277dcd6d..b8937e69c143 100644 --- a/core/java/android/se/omapi/SEService.java +++ b/core/java/android/se/omapi/SEService.java @@ -42,6 +42,23 @@ import java.util.HashMap; */ public class SEService { + /** + * Error code used with ServiceSpecificException. + * Thrown if there was an error communicating with the Secure Element. + * + * @hide + */ + public static final int IO_ERROR = 1; + + /** + * Error code used with ServiceSpecificException. + * Thrown if AID cannot be selected or is not available when opening + * a logical channel. + * + * @hide + */ + public static final int NO_SUCH_ELEMENT_ERROR = 2; + private static final String TAG = "OMAPI.SEService"; private final Object mLock = new Object(); diff --git a/core/java/android/se/omapi/Session.java b/core/java/android/se/omapi/Session.java index bb2a0327ee0d..19a018ee01bb 100644 --- a/core/java/android/se/omapi/Session.java +++ b/core/java/android/se/omapi/Session.java @@ -25,6 +25,7 @@ package android.se.omapi; import android.annotation.NonNull; import android.annotation.Nullable; import android.os.RemoteException; +import android.os.ServiceSpecificException; import android.util.Log; import java.io.IOException; @@ -207,8 +208,16 @@ public class Session { return null; } return new Channel(mService, this, channel); + } catch (ServiceSpecificException e) { + if (e.errorCode == SEService.IO_ERROR) { + throw new IOException(e.getMessage()); + } else if (e.errorCode == SEService.NO_SUCH_ELEMENT_ERROR) { + throw new NoSuchElementException(e.getMessage()); + } else { + throw new IllegalStateException(e.getMessage()); + } } catch (RemoteException e) { - throw new IOException(e.getMessage()); + throw new IllegalStateException(e.getMessage()); } } } @@ -311,8 +320,16 @@ public class Session { return null; } return new Channel(mService, this, channel); + } catch (ServiceSpecificException e) { + if (e.errorCode == SEService.IO_ERROR) { + throw new IOException(e.getMessage()); + } else if (e.errorCode == SEService.NO_SUCH_ELEMENT_ERROR) { + throw new NoSuchElementException(e.getMessage()); + } else { + throw new IllegalStateException(e.getMessage()); + } } catch (RemoteException e) { - throw new IOException(e.getMessage()); + throw new IllegalStateException(e.getMessage()); } } } |