Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1d0b1551 authored by Ruchi Kandoi's avatar Ruchi Kandoi
Browse files

Modify Open Mobile API to follow Android API guidelines

- Add @Nullable/@NonNull to input arguments for APIs
- Remove deprecated methods openBasicChannel(aid) and
  openLogicalChannel(aid)
- SecureElementListener is converted to a stand-alone interface
- serviceConnected() callback is renamed to onServiceConnected()

Bug: 64994044
Test: Run Cts Test
Change-Id: I503044a26a81dae8befb87fb8e8ac96d19de883b
(cherry picked from commit d785fc4f)
parent 47a0da6a
Loading
Loading
Loading
Loading
+2 −6
Original line number Diff line number Diff line
@@ -38324,10 +38324,8 @@ package android.se.omapi {
    method public void shutdown();
  }
  public static abstract class SEService.SecureElementListener extends android.os.Binder {
    ctor public SEService.SecureElementListener();
    method public android.os.IBinder asBinder();
    method public void serviceConnected();
  public static abstract interface SEService.SecureElementListener {
    method public abstract void onServiceConnected();
  }
  public class Session {
@@ -38337,9 +38335,7 @@ package android.se.omapi {
    method public android.se.omapi.Reader getReader();
    method public boolean isClosed();
    method public android.se.omapi.Channel openBasicChannel(byte[], byte) throws java.io.IOException;
    method public android.se.omapi.Channel openBasicChannel(byte[]) throws java.io.IOException;
    method public android.se.omapi.Channel openLogicalChannel(byte[], byte) throws java.io.IOException;
    method public android.se.omapi.Channel openLogicalChannel(byte[]) throws java.io.IOException;
  }
}
+3 −2
Original line number Diff line number Diff line
@@ -47,7 +47,8 @@ public class Channel {
    private final SEService mService;
    private final Object mLock = new Object();

    Channel(SEService service, Session session, ISecureElementChannel channel) {
    Channel(@NonNull SEService service, @NonNull Session session,
            @NonNull ISecureElementChannel channel) {
        if (service == null || session == null || channel == null) {
            throw new IllegalArgumentException("Parameters cannot be null");
        }
@@ -158,7 +159,7 @@ public class Channel {
     * @throws SecurityException if the command is filtered by the security policy.
     * @throws NullPointerException if command is NULL.
     */
    public @NonNull byte[] transmit(byte[] command) throws IOException {
    public @NonNull byte[] transmit(@NonNull byte[] command) throws IOException {
        if (!mService.isConnected()) {
            throw new IllegalStateException("service not connected to system");
        }
+0 −4
Original line number Diff line number Diff line
@@ -24,8 +24,4 @@ package android.se.omapi;
 * @hide
 */
interface ISecureElementListener {
  /**
   * Called by the framework when the service is connected.
   */
  void serviceConnected();
}
+1 −1
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ public class Reader {
    private final Object mLock = new Object();


    Reader(SEService service, String name, ISecureElementReader reader) {
    Reader(@NonNull SEService service, @NonNull String name, @NonNull ISecureElementReader reader) {
        if (reader == null || service == null || name == null) {
            throw new IllegalArgumentException("Parameters cannot be null");
        }
+26 −19
Original line number Diff line number Diff line
@@ -62,17 +62,32 @@ public class SEService {
    /**
     * Interface to send call-backs to the application when the service is connected.
     */
    public abstract static class SecureElementListener extends ISecureElementListener.Stub {
    public interface SecureElementListener {
        /**
         * Called by the framework when the service is connected.
         */
        void onServiceConnected();
    }

    /**
     * Listener object that allows the notification of the caller if this
     * SEService could be bound to the backend.
     */
    private class SEListener extends ISecureElementListener.Stub {
        public SecureElementListener mListener = null;

        @Override
        public IBinder asBinder() {
            return this;
        }

        /**
         * Called by the framework when the service is connected.
         */
        public void serviceConnected() {};
        public void onServiceConnected() {
            if (mListener != null) {
                mListener.onServiceConnected();
            }
        }
    }
    private SEListener mSEListener = new SEListener();

    private static final String TAG = "OMAPI.SEService";

@@ -94,12 +109,6 @@ public class SEService {
     */
    private final HashMap<String, Reader> mReaders = new HashMap<String, Reader>();

    /**
     * Listener object that allows the notification of the caller if this
     * SEService could be bound to the backend.
     */
    private ISecureElementListener mSEListener;

    /**
     * Establishes a new connection that can be used to connect to all the
     * Secure Elements available in the system. The connection process can be
@@ -107,22 +116,22 @@ public class SEService {
     * the specified listener is called or if isConnected() returns
     * <code>true</code>. <br>
     * The call-back object passed as a parameter will have its
     * serviceConnected() method called when the connection actually happen.
     * onServiceConnected() method called when the connection actually happen.
     *
     * @param context
     *            the context of the calling application. Cannot be
     *            <code>null</code>.
     * @param listener
     *            a SecureElementListener object. Can be <code>null</code>.
     *            a SecureElementListener object.
     */
    public SEService(Context context, SecureElementListener listener) {
    public SEService(@NonNull Context context, @NonNull SecureElementListener listener) {

        if (context == null) {
            throw new NullPointerException("context must not be null");
        }

        mContext = context;
        mSEListener = listener;
        mSEListener.mListener = listener;

        mConnection = new ServiceConnection() {

@@ -131,9 +140,7 @@ public class SEService {

                mSecureElementService = ISecureElementService.Stub.asInterface(service);
                if (mSEListener != null) {
                    try {
                        mSEListener.serviceConnected();
                    } catch (RemoteException ignore) { }
                    mSEListener.onServiceConnected();
                }
                Log.i(TAG, "Service onServiceConnected");
            }
@@ -233,7 +240,7 @@ public class SEService {
     *
     * @return String containing the OpenMobile API version (e.g. "3.0").
     */
    public String getVersion() {
    public @NonNull String getVersion() {
        return "3.2";
    }

Loading