diff options
| author | 2018-11-08 03:15:58 +0000 | |
|---|---|---|
| committer | 2018-11-08 03:15:58 +0000 | |
| commit | 74514bcbccd9e068589b683e35eac5897c24ee50 (patch) | |
| tree | b960c0b7a3926d6dc77d77326f8682c86aa5c652 | |
| parent | aff190599c23180800a5933153197be48edd346c (diff) | |
| parent | 72c676e343e4598cfdf2b3f5543c780a03e7ac6e (diff) | |
Merge "Reject PendingIntents owned by another client"
3 files changed, 22 insertions, 4 deletions
diff --git a/core/java/android/hardware/location/ContextHubClient.java b/core/java/android/hardware/location/ContextHubClient.java index 9f11246d7372..2717c4ee5313 100644 --- a/core/java/android/hardware/location/ContextHubClient.java +++ b/core/java/android/hardware/location/ContextHubClient.java @@ -107,9 +107,10 @@ public class ContextHubClient implements Closeable { * 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 * 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 - * 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 + * registered at a time for a single ContextHubClient, and the PendingIntent cannot be + * registered if already registered by a ContextHubClient. If registered successfully, intents + * 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 * 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 diff --git a/services/core/java/com/android/server/location/ContextHubClientBroker.java b/services/core/java/com/android/server/location/ContextHubClientBroker.java index 642347021201..002d4e1049fb 100644 --- a/services/core/java/com/android/server/location/ContextHubClientBroker.java +++ b/services/core/java/com/android/server/location/ContextHubClientBroker.java @@ -211,6 +211,10 @@ public class ContextHubClientBroker extends IContextHubClient.Stub @Override public boolean registerIntent(PendingIntent pendingIntent, long nanoAppId) { ContextHubServiceUtil.checkPermissions(mContext); + if (mClientManager.isPendingIntentRegistered(pendingIntent)) { + Log.e(TAG, "Failed to register PendingIntent: already registered"); + return false; + } boolean success = false; synchronized (this) { diff --git a/services/core/java/com/android/server/location/ContextHubClientManager.java b/services/core/java/com/android/server/location/ContextHubClientManager.java index 72879ddc2018..fe93a1a0f613 100644 --- a/services/core/java/com/android/server/location/ContextHubClientManager.java +++ b/services/core/java/com/android/server/location/ContextHubClientManager.java @@ -24,7 +24,6 @@ import android.hardware.location.ContextHubInfo; import android.hardware.location.IContextHubClient; import android.hardware.location.IContextHubClientCallback; import android.hardware.location.NanoAppMessage; -import android.os.RemoteException; import android.util.Log; import java.util.concurrent.ConcurrentHashMap; @@ -204,6 +203,20 @@ import java.util.function.Consumer; } /** + * @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 * manager. * |