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

Commit 8ebb80bb authored by Shawn Willden's avatar Shawn Willden
Browse files

Use already-launched OMAPI service

The Java OMAPI APK was launch-on-demand, triggered by an intent.  The
new native service is launched by init and registered with
ServiceManager.  This CL modifies SEService to check with ServiceManager
before sending the intent to launch the on-demand OMAPI service.

Note that this CL does not reference the build flag, but unless the flag
is set there will be no OMAPI service registered with ServiceManager so
it will follow the pre-existing logic.

Bug: 380331467
Flag: build.RELEASE_NATIVE_OMAPI
Test: atest VtsAidlKeyMintTargetTest
Change-Id: I8f2b0a814274660868bdab509fc7ffd22090d761
parent 18e2e91f
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;

import java.util.HashMap;
@@ -63,6 +64,9 @@ public final class SEService {
     */
    public static final int NO_SUCH_ELEMENT_ERROR = 2;

    /** @hide */
    private static final String SERVICE_NAME = "android.se.omapi.ISecureElementService/default";

    /**
     * Interface to send call-backs to the application when the service is connected.
     */
@@ -181,6 +185,14 @@ public final class SEService {
        mSEListener.mListener = listener;
        mSEListener.mExecutor = executor;

        IBinder seService = ServiceManager.checkService(SERVICE_NAME);
        if (seService != null) {
            mSecureElementService = ISecureElementService.Stub.asInterface(seService);
            Log.i(TAG, "Got SecureElementService from system, not sending intent.");
            executor.execute(listener::onConnected);
            return;
        }

        mConnection = new ServiceConnection() {

            public synchronized void onServiceConnected(
@@ -199,6 +211,8 @@ public final class SEService {
            }
        };

        Log.i(TAG,
                "No SecureElementService available from system, sending intent to start it");
        Intent intent = new Intent(ISecureElementService.class.getName());
        intent.setClassName("com.android.se",
                            "com.android.se.SecureElementService");
@@ -206,6 +220,8 @@ public final class SEService {
                mContext.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
        if (bindingSuccessful) {
            Log.i(TAG, "bindService successful");
        } else {
            Log.e(TAG, "bindService failed");
        }
    }