diff options
| author | 2018-02-02 17:58:58 +0000 | |
|---|---|---|
| committer | 2018-02-02 17:58:58 +0000 | |
| commit | e09ba38a972f3eef8d228aa127f16d365baff652 (patch) | |
| tree | 0b0730abdd760cd4839422a49fb69b86a0056d4d | |
| parent | 515a54a93e077b879f5c8a479ad5e2ac4d20ff6e (diff) | |
| parent | 73e7a1a739c311ec1eab0895652601d646743d5c (diff) | |
Merge "Add ServiceSpecificExceptions for SecureElementService."
am: 73e7a1a739
Change-Id: Ib3122c4a0bcc233f6be734af4af9edad4a5c63e8
| -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());              }          }      } |