From 5e85167c221e4d6a908115f5088ed1590763ec0a Mon Sep 17 00:00:00 2001 From: Nate Myren Date: Mon, 22 Mar 2021 14:47:55 -0700 Subject: [PATCH] Handle proxy chains including the system package Ensure that usages with the system package are not filtered entirely. Instead, they should not be shown on their own, and the "system" label should not be included in proxy label chains Bug: 172868375 Test: manual Change-Id: If9812ce915de0ca1ac47d93d96f199a8bb768bce --- .../permission/PermissionUsageHelper.java | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/core/java/android/permission/PermissionUsageHelper.java b/core/java/android/permission/PermissionUsageHelper.java index 80a3e1693ab17..921911bbf4796 100644 --- a/core/java/android/permission/PermissionUsageHelper.java +++ b/core/java/android/permission/PermissionUsageHelper.java @@ -283,9 +283,7 @@ public class PermissionUsageHelper { continue; } - if (packageName.equals(SYSTEM_PKG) - || (!shouldShowPermissionsHub() - && !isUserSensitive(packageName, user, op))) { + if (!shouldShowPermissionsHub() && !isUserSensitive(packageName, user, op)) { continue; } @@ -372,8 +370,10 @@ public class PermissionUsageHelper { proxyLabels.put(usage, new ArrayList<>()); proxyUids.add(usage.uid); } - if (!mostRecentUsages.containsKey(usage.uid) || usage.lastAccessTime - > mostRecentUsages.get(usage.uid).lastAccessTime) { + // If this usage is not by the system, and is more recent than the next-most recent + // for it's uid, save it. + if (!usage.packageName.equals(SYSTEM_PKG) && (!mostRecentUsages.containsKey(usage.uid) + || usage.lastAccessTime > mostRecentUsages.get(usage.uid).lastAccessTime)) { mostRecentUsages.put(usage.uid, usage); } } @@ -416,20 +416,22 @@ public class PermissionUsageHelper { } proxyUids.add(currentUsage.uid); - try { - PackageManager userPkgManager = - getUserContext(currentUsage.getUser()).getPackageManager(); - ApplicationInfo appInfo = userPkgManager.getApplicationInfo( - currentUsage.packageName, 0); - CharSequence appLabel = appInfo.loadLabel(userPkgManager); - // If we don't already have the app label, and it's not the same as the main - // app, add it - if (!proxyLabelList.contains(appLabel) - && !currentUsage.packageName.equals(start.packageName)) { - proxyLabelList.add(appLabel); + // Don't add an app label for the main app, or the system app + if (!currentUsage.packageName.equals(start.packageName) + && !currentUsage.packageName.equals(SYSTEM_PKG)) { + try { + PackageManager userPkgManager = + getUserContext(currentUsage.getUser()).getPackageManager(); + ApplicationInfo appInfo = userPkgManager.getApplicationInfo( + currentUsage.packageName, 0); + CharSequence appLabel = appInfo.loadLabel(userPkgManager); + // If we don't already have the app label add it + if (!proxyLabelList.contains(appLabel)) { + proxyLabelList.add(appLabel); + } + } catch (PackageManager.NameNotFoundException e) { + // Ignore } - } catch (PackageManager.NameNotFoundException e) { - // Ignore } iterNum++; }