Merge "Prevent multiple outstanding permission queries per client" into sc-qpr1-dev am: 373ed0127e am: fec4a09642

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15993917

Change-Id: I9a6109a61587c070ed807a4d715292b75acd058e
This commit is contained in:
TreeHugger Robot
2021-10-07 23:59:46 +00:00
committed by Automerger Merge Worker

View File

@@ -209,6 +209,12 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
*/ */
private AtomicBoolean mIsPendingIntentCancelled = new AtomicBoolean(false); 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. * 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 = private final IContextHubTransactionCallback mQueryPermsCallback =
new IContextHubTransactionCallback.Stub() { new IContextHubTransactionCallback.Stub() {
@Override @Override
public void onTransactionComplete(int result) { public void onTransactionComplete(int result) {}
}
@Override @Override
public void onQueryResponse(int result, List<NanoAppState> nanoAppStateList) { public void onQueryResponse(int result, List<NanoAppState> nanoAppStateList) {
mIsPermQueryIssued.set(false);
if (result != ContextHubTransaction.RESULT_SUCCESS && nanoAppStateList != null) { if (result != ContextHubTransaction.RESULT_SUCCESS && nanoAppStateList != null) {
Log.e(TAG, "Permissions query failed, but still received nanoapp state"); Log.e(TAG, "Permissions query failed, but still received nanoapp state");
} else if (nanoAppStateList != null) { } else if (nanoAppStateList != null) {
@@ -656,10 +662,12 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
* communicated with in the past. * communicated with in the past.
*/ */
private void checkNanoappPermsAsync() { private void checkNanoappPermsAsync() {
if (!mIsPermQueryIssued.getAndSet(true)) {
ContextHubServiceTransaction transaction = mTransactionManager.createQueryTransaction( ContextHubServiceTransaction transaction = mTransactionManager.createQueryTransaction(
mAttachedContextHubInfo.getId(), mQueryPermsCallback, mPackage); mAttachedContextHubInfo.getId(), mQueryPermsCallback, mPackage);
mTransactionManager.addTransaction(transaction); mTransactionManager.addTransaction(transaction);
} }
}
private int updateNanoAppAuthState( private int updateNanoAppAuthState(
long nanoAppId, List<String> nanoappPermissions, boolean gracePeriodExpired) { long nanoAppId, List<String> nanoappPermissions, boolean gracePeriodExpired) {