From 1f78c988291fc168e7eef849fcd663501476c3ec Mon Sep 17 00:00:00 2001 From: Anthony Stange Date: Fri, 12 Mar 2021 15:35:28 +0000 Subject: [PATCH] Maintain map of nanoapps that are permanently denied If a broker's authentication state with a nanoapp is "force denied" via CLI, it's possible that a future nanoapp permissions state check could cause the client to transition back to the granted state which can cause issues with tests. Remove this corner case by maintaining a map of force denials that can be used to ensure that the authenitcation state is always left as denied. Bug: 179948640 Test: Run PTS Change-Id: Ibe23764fb4a2f08d521a0b5d483f7afb01e1bf4b --- .../contexthub/ContextHubClientBroker.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/location/contexthub/ContextHubClientBroker.java b/services/core/java/com/android/server/location/contexthub/ContextHubClientBroker.java index e1c011d821a7f..c8c212b3109c8 100644 --- a/services/core/java/com/android/server/location/contexthub/ContextHubClientBroker.java +++ b/services/core/java/com/android/server/location/contexthub/ContextHubClientBroker.java @@ -47,9 +47,11 @@ import android.util.proto.ProtoOutputStream; import com.android.server.location.ClientBrokerProto; import java.util.Collections; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Supplier; @@ -205,14 +207,19 @@ public class ContextHubClientBroker extends IContextHubClient.Stub * allowed to communicate over that channel. A channel is defined to have been opened if the * client has sent or received messages from the particular nanoapp. */ - private final Map mMessageChannelNanoappIdMap = - new ConcurrentHashMap(); + private final Map mMessageChannelNanoappIdMap = new ConcurrentHashMap<>(); + + /** + * Set containing all nanoapps that have been forcefully transitioned to the denied + * authorization state (via CLI) to ensure they don't transition back to the granted state + * later if, for example, a permission check is performed due to another nanoapp + */ + private final Set mForceDeniedNapps = new HashSet<>(); /** * Map containing all nanoapps that have active auth state denial timers. */ - private final Map mNappToAuthTimerMap = - new ConcurrentHashMap(); + private final Map mNappToAuthTimerMap = new ConcurrentHashMap<>(); /** * Callback used to obtain the latest set of nanoapp permissions and verify this client has @@ -637,7 +644,8 @@ public class ContextHubClientBroker extends IContextHubClient.Stub private int updateNanoAppAuthState( long nanoAppId, List nanoappPermissions, boolean gracePeriodExpired) { return updateNanoAppAuthState( - nanoAppId, nanoappPermissions, gracePeriodExpired, false /* forceDenied */); + nanoAppId, nanoappPermissions, gracePeriodExpired, + mForceDeniedNapps.contains(nanoAppId) /* forceDenied */); } /** @@ -679,6 +687,7 @@ public class ContextHubClientBroker extends IContextHubClient.Stub // any state -> DENIED if "forceDenied" is true if (forceDenied) { newAuthState = AUTHORIZATION_DENIED; + mForceDeniedNapps.add(nanoAppId); } else if (gracePeriodExpired) { if (curAuthState == AUTHORIZATION_DENIED_GRACE_PERIOD) { newAuthState = AUTHORIZATION_DENIED;