From e646b287b7aae3b0a9e4f6ef4a4b55535e4d753c Mon Sep 17 00:00:00 2001 From: Nadav Bar Date: Wed, 27 Mar 2019 10:16:02 +0200 Subject: [PATCH] Filter app-ops from for foreground notifications This fixes inconsistency of showing the app ops indicators in the status bar and foreground notifications. Specifically, the issue that were seen is that the microphone indicator was also shown for system apps without a launcher that have the recording pre-granted. Bug: 129263222. Change-Id: I6f6faf1552d3721f6fc34c650b5601e90d172db6 Test: Manually. --- .../systemui/appops/AppOpsControllerImpl.java | 54 +++++++++++++++---- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/appops/AppOpsControllerImpl.java b/packages/SystemUI/src/com/android/systemui/appops/AppOpsControllerImpl.java index ace086f7af2c2..3fc6689b2f195 100644 --- a/packages/SystemUI/src/com/android/systemui/appops/AppOpsControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/appops/AppOpsControllerImpl.java @@ -204,23 +204,58 @@ public class AppOpsControllerImpl implements AppOpsController, } /** - * Does the app-op item refer to a user sensitive permission. Only user sensitive permission - * should be shown to the user by default. + * Does the app-op code refer to a user sensitive permission for the specified user id + * and package. Only user sensitive permission should be shown to the user by default. * - * @param item The item + * @param appOpCode The code of the app-op. + * @param uid The uid of the user. + * @param packageName The name of the package. * * @return {@code true} iff the app-op item is user sensitive */ - private boolean isUserSensitive(AppOpItem item) { - String permission = AppOpsManager.opToPermission(item.getCode()); + private boolean isUserSensitive(int appOpCode, int uid, String packageName) { + String permission = AppOpsManager.opToPermission(appOpCode); if (permission == null) { return false; } int permFlags = mContext.getPackageManager().getPermissionFlags(permission, - item.getPackageName(), UserHandle.getUserHandleForUid(item.getUid())); + packageName, UserHandle.getUserHandleForUid(uid)); return (permFlags & PackageManager.FLAG_PERMISSION_USER_SENSITIVE_WHEN_GRANTED) != 0; } + /** + * Does the app-op item refer to an operation that should be shown to the user. + * Only specficic ops (like SYSTEM_ALERT_WINDOW) or ops that refer to user sensitive + * permission should be shown to the user by default. + * + * @param item The item + * + * @return {@code true} iff the app-op item should be shown to the user + */ + private boolean isUserVisible(AppOpItem item) { + return isUserVisible(item.getCode(), item.getUid(), item.getPackageName()); + } + + + /** + * Does the app-op, uid and package name, refer to an operation that should be shown to the + * user. Only specficic ops (like {@link AppOpsManager.OP_SYSTEM_ALERT_WINDOW}) or + * ops that refer to user sensitive permission should be shown to the user by default. + * + * @param item The item + * + * @return {@code true} iff the app-op for should be shown to the user + */ + private boolean isUserVisible(int appOpCode, int uid, String packageName) { + // currently OP_SYSTEM_ALERT_WINDOW does not correspond to a platform permission + // which may be user senstive, so for now always show it to the user. + if (appOpCode == AppOpsManager.OP_SYSTEM_ALERT_WINDOW) { + return true; + } + + return isUserSensitive(appOpCode, uid, packageName); + } + /** * Returns a copy of the list containing all the active AppOps that the controller tracks. * @@ -245,7 +280,7 @@ public class AppOpsControllerImpl implements AppOpsController, for (int i = 0; i < numActiveItems; i++) { AppOpItem item = mActiveItems.get(i); if ((userId == UserHandle.USER_ALL || UserHandle.getUserId(item.getUid()) == userId) - && isUserSensitive(item)) { + && isUserVisible(item)) { list.add(item); } } @@ -255,7 +290,7 @@ public class AppOpsControllerImpl implements AppOpsController, for (int i = 0; i < numNotedItems; i++) { AppOpItem item = mNotedItems.get(i); if ((userId == UserHandle.USER_ALL || UserHandle.getUserId(item.getUid()) == userId) - && isUserSensitive(item)) { + && isUserVisible(item)) { list.add(item); } } @@ -281,7 +316,8 @@ public class AppOpsControllerImpl implements AppOpsController, } private void notifySuscribers(int code, int uid, String packageName, boolean active) { - if (mCallbacksByCode.containsKey(code)) { + if (mCallbacksByCode.containsKey(code) + && isUserVisible(code, uid, packageName)) { for (Callback cb: mCallbacksByCode.get(code)) { cb.onActiveStateChanged(code, uid, packageName, active); }