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

Commit 34ce411f authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Only send PendingIntent events for intended nanoapp"

parents 9212963a bb8ca1ae
Loading
Loading
Loading
Loading
+40 −16
Original line number Diff line number Diff line
@@ -237,7 +237,7 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
        Supplier<Intent> supplier =
                () -> createIntent(ContextHubManager.EVENT_NANOAPP_MESSAGE, message.getNanoAppId())
                        .putExtra(ContextHubManager.EXTRA_MESSAGE, message);
        sendPendingIntent(supplier);
        sendPendingIntent(supplier, message.getNanoAppId());
    }

    /**
@@ -247,7 +247,8 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
     */
    /* package */ void onNanoAppLoaded(long nanoAppId) {
        invokeCallback(callback -> callback.onNanoAppLoaded(nanoAppId));
        sendPendingIntent(() -> createIntent(ContextHubManager.EVENT_NANOAPP_LOADED, nanoAppId));
        sendPendingIntent(
                () -> createIntent(ContextHubManager.EVENT_NANOAPP_LOADED, nanoAppId), nanoAppId);
    }

    /**
@@ -257,7 +258,8 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
     */
    /* package */ void onNanoAppUnloaded(long nanoAppId) {
        invokeCallback(callback -> callback.onNanoAppUnloaded(nanoAppId));
        sendPendingIntent(() -> createIntent(ContextHubManager.EVENT_NANOAPP_UNLOADED, nanoAppId));
        sendPendingIntent(
                () -> createIntent(ContextHubManager.EVENT_NANOAPP_UNLOADED, nanoAppId), nanoAppId);
    }

    /**
@@ -280,7 +282,7 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
        Supplier<Intent> supplier =
                () -> createIntent(ContextHubManager.EVENT_NANOAPP_ABORTED, nanoAppId)
                        .putExtra(ContextHubManager.EXTRA_NANOAPP_ABORT_CODE, abortCode);
        sendPendingIntent(supplier);
        sendPendingIntent(supplier, nanoAppId);
    }

    /**
@@ -360,9 +362,32 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
     */
    private synchronized void sendPendingIntent(Supplier<Intent> supplier) {
        if (mPendingIntentRequest.hasPendingIntent()) {
            Intent intent = supplier.get();
            doSendPendingIntent(mPendingIntentRequest.getPendingIntent(), supplier.get());
        }
    }

    /**
     * Sends an intent to any existing PendingIntent
     *
     * @param supplier method to create the extra Intent
     * @param nanoAppId the ID of the nanoapp which this event is for
     */
    private synchronized void sendPendingIntent(Supplier<Intent> supplier, long nanoAppId) {
        if (mPendingIntentRequest.hasPendingIntent()
                && mPendingIntentRequest.getNanoAppId() == nanoAppId) {
            doSendPendingIntent(mPendingIntentRequest.getPendingIntent(), supplier.get());
        }
    }

    /**
     * Sends a PendingIntent with extra Intent data
     *
     * @param pendingIntent the PendingIntent
     * @param intent the extra Intent data
     */
    private void doSendPendingIntent(PendingIntent pendingIntent, Intent intent) {
        try {
                mPendingIntentRequest.getPendingIntent().send(
            pendingIntent.send(
                    mContext, 0 /* code */, intent, null /* onFinished */, null /* Handler */,
                    Manifest.permission.LOCATION_HARDWARE /* requiredPermission */,
                    null /* options */);
@@ -373,7 +398,6 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
            close();
        }
    }
    }

    /**
     * @return true if the client is still registered with the service, false otherwise