Merge "Add ServiceSpecificExceptions for SecureElementService."

This commit is contained in:
Ruchi Kandoi
2018-02-02 16:43:11 +00:00
committed by Gerrit Code Review
4 changed files with 48 additions and 7 deletions

View File

@@ -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());
}
}
}

View File

@@ -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.");

View File

@@ -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();

View File

@@ -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());
}
}
}