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

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

Merge "Reject PendingIntents owned by another client"

parents aff19059 72c676e3
Loading
Loading
Loading
Loading
+4 −3
Original line number Original line Diff line number Diff line
@@ -107,9 +107,10 @@ public class ContextHubClient implements Closeable {
     * This method should be used if the caller wants to receive notifications even after the
     * This method should be used if the caller wants to receive notifications even after the
     * process exits. The client must have an open connection with the Context Hub Service (i.e. it
     * process exits. The client must have an open connection with the Context Hub Service (i.e. it
     * cannot have been closed through the {@link #close()} method). Only one PendingIntent can be
     * cannot have been closed through the {@link #close()} method). Only one PendingIntent can be
     * registered at a time for a single ContextHubClient. If registered successfully, intents will
     * registered at a time for a single ContextHubClient, and the PendingIntent cannot be
     * be delivered regarding events for the specified nanoapp from the attached Context Hub. Any
     * registered if already registered by a ContextHubClient. If registered successfully, intents
     * unicast messages for this client will also be delivered. The intent will have an extra
     * will be delivered regarding events for the specified nanoapp from the attached Context Hub.
     * Any unicast messages for this client will also be delivered. The intent will have an extra
     * {@link ContextHubManager.EXTRA_CONTEXT_HUB_INFO} of type {@link ContextHubInfo}, which
     * {@link ContextHubManager.EXTRA_CONTEXT_HUB_INFO} of type {@link ContextHubInfo}, which
     * describes the Context Hub the intent event was for. The intent will also have an extra
     * describes the Context Hub the intent event was for. The intent will also have an extra
     * {@link ContextHubManager.EXTRA_EVENT_TYPE} of type {@link ContextHubManager.Event}, which
     * {@link ContextHubManager.EXTRA_EVENT_TYPE} of type {@link ContextHubManager.Event}, which
+4 −0
Original line number Original line Diff line number Diff line
@@ -211,6 +211,10 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
    @Override
    @Override
    public boolean registerIntent(PendingIntent pendingIntent, long nanoAppId) {
    public boolean registerIntent(PendingIntent pendingIntent, long nanoAppId) {
        ContextHubServiceUtil.checkPermissions(mContext);
        ContextHubServiceUtil.checkPermissions(mContext);
        if (mClientManager.isPendingIntentRegistered(pendingIntent)) {
            Log.e(TAG, "Failed to register PendingIntent: already registered");
            return false;
        }


        boolean success = false;
        boolean success = false;
        synchronized (this) {
        synchronized (this) {
+14 −1
Original line number Original line Diff line number Diff line
@@ -24,7 +24,6 @@ import android.hardware.location.ContextHubInfo;
import android.hardware.location.IContextHubClient;
import android.hardware.location.IContextHubClient;
import android.hardware.location.IContextHubClientCallback;
import android.hardware.location.IContextHubClientCallback;
import android.hardware.location.NanoAppMessage;
import android.hardware.location.NanoAppMessage;
import android.os.RemoteException;
import android.util.Log;
import android.util.Log;


import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentHashMap;
@@ -203,6 +202,20 @@ import java.util.function.Consumer;
        forEachClientOfHub(contextHubId, client -> client.onNanoAppAborted(nanoAppId, abortCode));
        forEachClientOfHub(contextHubId, client -> client.onNanoAppAborted(nanoAppId, abortCode));
    }
    }


    /**
     * @param pendingIntent the PendingIntent to check
     * @return true if the given PendingIntent is registered by a client, false otherwise
     */
    /* package */ boolean isPendingIntentRegistered(PendingIntent pendingIntent) {
        for (ContextHubClientBroker broker : mHostEndPointIdToClientMap.values()) {
            if (broker.hasPendingIntent(pendingIntent)) {
                return true;
            }
        }

        return false;
    }

    /**
    /**
     * Creates a new ContextHubClientBroker object for a client and registers it with the client
     * Creates a new ContextHubClientBroker object for a client and registers it with the client
     * manager.
     * manager.