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

Commit 0069f128 authored by Arthur Ishiguro's avatar Arthur Ishiguro
Browse files

Handles load and unload lifecycle callbacks

Bug: 67734082
Test: Create test app to load/unload a nanoapp after client
registration, verify listener callbacks are invoked
Change-Id: Ibf8cd200307ace0b3dcc9431166f61fc2929cff4
parent 6d47c54a
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -178,6 +178,38 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
        }
    }

    /**
     * Handles a nanoapp load event.
     *
     * @param nanoAppId the ID of the nanoapp that was loaded.
     */
    /* package */ void onNanoAppLoaded(long nanoAppId) {
        if (mConnectionOpen.get()) {
            try {
                mCallbackInterface.onNanoAppLoaded(nanoAppId);
            } catch (RemoteException e) {
                Log.e(TAG, "RemoteException while calling onNanoAppLoaded on client"
                        + " (host endpoint ID = " + mHostEndPointId + ")", e);
            }
        }
    }

    /**
     * Handles a nanoapp unload event.
     *
     * @param nanoAppId the ID of the nanoapp that was unloaded.
     */
    /* package */ void onNanoAppUnloaded(long nanoAppId) {
        if (mConnectionOpen.get()) {
            try {
                mCallbackInterface.onNanoAppUnloaded(nanoAppId);
            } catch (RemoteException e) {
                Log.e(TAG, "RemoteException while calling onNanoAppUnloaded on client"
                        + " (host endpoint ID = " + mHostEndPointId + ")", e);
            }
        }
    }

    /**
     * Handles a hub reset for this client.
     */
+20 −0
Original line number Diff line number Diff line
@@ -148,6 +148,26 @@ import java.util.function.Consumer;
        }
    }

    /**
     * Handles a nanoapp load event.
     *
     * @param contextHubId the ID of the hub where the nanoapp was loaded.
     * @param nanoAppId    the ID of the nanoapp that was loaded.
     */
    /* package */ void onNanoAppLoaded(int contextHubId, long nanoAppId) {
        forEachClientOfHub(contextHubId, client -> client.onNanoAppLoaded(nanoAppId));
    }

    /**
     * Handles a nanoapp unload event.
     *
     * @param contextHubId the ID of the hub where the nanoapp was unloaded.
     * @param nanoAppId    the ID of the nanoapp that was unloaded.
     */
    /* package */ void onNanoAppUnloaded(int contextHubId, long nanoAppId) {
        forEachClientOfHub(contextHubId, client -> client.onNanoAppUnloaded(nanoAppId));
    }

    /**
     * Handles a hub reset.
     *
+1 −1
Original line number Diff line number Diff line
@@ -160,7 +160,7 @@ public class ContextHubService extends IContextHubService.Stub {
        }

        mClientManager = new ContextHubClientManager(mContext, mContextHubProxy);
        mTransactionManager = new ContextHubTransactionManager(mContextHubProxy);
        mTransactionManager = new ContextHubTransactionManager(mContextHubProxy, mClientManager);

        List<ContextHub> hubList;
        try {
+14 −1
Original line number Diff line number Diff line
@@ -57,6 +57,11 @@ import java.util.concurrent.atomic.AtomicInteger;
     */
    private final IContexthub mContextHubProxy;

    /*
     * The manager for all clients for the service.
     */
    private final ContextHubClientManager mClientManager;

    /*
     * A queue containing the current transactions
     */
@@ -73,8 +78,10 @@ import java.util.concurrent.atomic.AtomicInteger;
    private final ScheduledThreadPoolExecutor mTimeoutExecutor = new ScheduledThreadPoolExecutor(1);
    private ScheduledFuture<?> mTimeoutFuture = null;

    /* package */ ContextHubTransactionManager(IContexthub contextHubProxy) {
    /* package */ ContextHubTransactionManager(
            IContexthub contextHubProxy, ContextHubClientManager clientManager) {
        mContextHubProxy = contextHubProxy;
        mClientManager = clientManager;
    }

    /**
@@ -113,6 +120,9 @@ import java.util.concurrent.atomic.AtomicInteger;
            /* package */ void onTransactionComplete(int result) {
                try {
                    onCompleteCallback.onTransactionComplete(result);
                    if (result == Result.OK) {
                        mClientManager.onNanoAppLoaded(contextHubId, nanoAppBinary.getNanoAppId());
                    }
                } catch (RemoteException e) {
                    Log.e(TAG, "RemoteException while calling client onTransactionComplete");
                }
@@ -153,6 +163,9 @@ import java.util.concurrent.atomic.AtomicInteger;
            /* package */ void onTransactionComplete(int result) {
                try {
                    onCompleteCallback.onTransactionComplete(result);
                    if (result == Result.OK) {
                        mClientManager.onNanoAppUnloaded(contextHubId, nanoAppId);
                    }
                } catch (RemoteException e) {
                    Log.e(TAG, "RemoteException while calling client onTransactionComplete");
                }