From a44514e9616cd7bcef7c31afaaebc1b3f4c1af2e Mon Sep 17 00:00:00 2001 From: Anthony Stange Date: Wed, 6 Oct 2021 19:21:43 +0000 Subject: [PATCH] Prevent multiple outstanding permission queries per client Under stress tests, it's possible for several messages to be sent before CHRE has time to respond to the permission query which can cause several permission queries to be sent and CHRE to be overwhelmed. Fixes: 202201157 Test: Flash device and run stress test Change-Id: I16871a116216cd288f0eba0e6c5572f5afa6b959 --- .../contexthub/ContextHubClientBroker.java | 18 +++++++++++++----- 1 file changed, 13 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 fa33338a61e72..03e421bfed677 100644 --- a/services/core/java/com/android/server/location/contexthub/ContextHubClientBroker.java +++ b/services/core/java/com/android/server/location/contexthub/ContextHubClientBroker.java @@ -209,6 +209,12 @@ public class ContextHubClientBroker extends IContextHubClient.Stub */ private AtomicBoolean mIsPendingIntentCancelled = new AtomicBoolean(false); + /** + * True if a permissions query has been issued and is being processed. Used to prevent too many + * queries from being issued by a single client at once. + */ + private AtomicBoolean mIsPermQueryIssued = new AtomicBoolean(false); + /* * True if the application creating the client has the ACCESS_CONTEXT_HUB permission. */ @@ -240,11 +246,11 @@ public class ContextHubClientBroker extends IContextHubClient.Stub private final IContextHubTransactionCallback mQueryPermsCallback = new IContextHubTransactionCallback.Stub() { @Override - public void onTransactionComplete(int result) { - } + public void onTransactionComplete(int result) {} @Override public void onQueryResponse(int result, List nanoAppStateList) { + mIsPermQueryIssued.set(false); if (result != ContextHubTransaction.RESULT_SUCCESS && nanoAppStateList != null) { Log.e(TAG, "Permissions query failed, but still received nanoapp state"); } else if (nanoAppStateList != null) { @@ -656,9 +662,11 @@ public class ContextHubClientBroker extends IContextHubClient.Stub * communicated with in the past. */ private void checkNanoappPermsAsync() { - ContextHubServiceTransaction transaction = mTransactionManager.createQueryTransaction( - mAttachedContextHubInfo.getId(), mQueryPermsCallback, mPackage); - mTransactionManager.addTransaction(transaction); + if (!mIsPermQueryIssued.getAndSet(true)) { + ContextHubServiceTransaction transaction = mTransactionManager.createQueryTransaction( + mAttachedContextHubInfo.getId(), mQueryPermsCallback, mPackage); + mTransactionManager.addTransaction(transaction); + } } private int updateNanoAppAuthState(