Loading core/java/android/permission/PermissionUsageHelper.java +58 −50 Original line number Diff line number Diff line Loading @@ -199,6 +199,7 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis // if any link in the chain is finished, remove the chain. Then, find any other chains that // contain this op/package/uid/tag combination, and remove them, as well. // TODO ntmyren: be smarter about this synchronized(mAttributionChains) { mAttributionChains.remove(attributionChainId); int numChains = mAttributionChains.size(); ArrayList<Integer> toRemove = new ArrayList<>(); Loading @@ -216,6 +217,7 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis } mAttributionChains.removeAll(toRemove); } } @Override public void onOpStarted(int op, int uid, String packageName, String attributionTag, Loading @@ -234,9 +236,11 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis // If this is not a successful start, or it is not a chain, or it is untrusted, return return; } synchronized(mAttributionChains) { addLinkToChainIfNotPresent(AppOpsManager.opToPublicName(op), packageName, uid, attributionTag, attributionFlags, attributionChainId); } } private void addLinkToChainIfNotPresent(String op, String packageName, int uid, String attributionTag, int attributionFlags, int attributionChainId) { Loading Loading @@ -310,7 +314,7 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis String permGroup = usedPermGroups.get(permGroupNum); ArrayMap<OpUsage, CharSequence> usagesWithLabels = getUniqueUsagesWithLabels(rawUsages.get(permGroup)); getUniqueUsagesWithLabels(permGroup, rawUsages.get(permGroup)); if (permGroup.equals(OPSTR_PHONE_CALL_MICROPHONE)) { isPhone = true; Loading Loading @@ -431,7 +435,8 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis return ListFormatter.getInstance().format(labels); } private ArrayMap<OpUsage, CharSequence> getUniqueUsagesWithLabels(List<OpUsage> usages) { private ArrayMap<OpUsage, CharSequence> getUniqueUsagesWithLabels(String permGroup, List<OpUsage> usages) { ArrayMap<OpUsage, CharSequence> usagesAndLabels = new ArrayMap<>(); if (usages == null || usages.isEmpty()) { Loading Loading @@ -466,7 +471,7 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis // If this usage has a proxy, but is not a proxy, it is the end of a chain. // TODO remove once camera converted if (!proxies.containsKey(usageAttr) && usage.proxy != null && !usage.op.equals(OPSTR_RECORD_AUDIO)) { && !MICROPHONE.equals(permGroup)) { proxyLabels.put(usage, new ArrayList<>()); proxyPackages.add(usage.getPackageIdHash()); } Loading Loading @@ -538,12 +543,13 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis // TODO ntmyren: remove this proxy logic once camera is converted to AttributionSource // For now: don't add mic proxy usages if (!start.op.equals(OPSTR_RECORD_AUDIO)) { if (!MICROPHONE.equals(permGroup)) { usagesAndLabels.put(start, proxyLabelList.isEmpty() ? null : formatLabelList(proxyLabelList)); } } synchronized (mAttributionChains) { for (int i = 0; i < mAttributionChains.size(); i++) { List<AccessChainLink> usageList = mAttributionChains.valueAt(i); int lastVisible = usageList.size() - 1; Loading @@ -551,7 +557,8 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis // if the list is empty or incomplete, do not show it. if (usageList.isEmpty() || !usageList.get(lastVisible).isEnd() || !usageList.get(0).isStart() || !usageList.get(lastVisible).usage.op.equals(OPSTR_RECORD_AUDIO)) { || !permGroup.equals(getGroupForOp(usageList.get(0).usage.op)) || !MICROPHONE.equals(permGroup)) { continue; } Loading Loading @@ -581,6 +588,7 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis } usagesAndLabels.put(start.usage, proxyLabel); } } for (int packageHash : mostRecentUsages.keySet()) { if (!proxyPackages.contains(packageHash)) { Loading Loading
core/java/android/permission/PermissionUsageHelper.java +58 −50 Original line number Diff line number Diff line Loading @@ -199,6 +199,7 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis // if any link in the chain is finished, remove the chain. Then, find any other chains that // contain this op/package/uid/tag combination, and remove them, as well. // TODO ntmyren: be smarter about this synchronized(mAttributionChains) { mAttributionChains.remove(attributionChainId); int numChains = mAttributionChains.size(); ArrayList<Integer> toRemove = new ArrayList<>(); Loading @@ -216,6 +217,7 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis } mAttributionChains.removeAll(toRemove); } } @Override public void onOpStarted(int op, int uid, String packageName, String attributionTag, Loading @@ -234,9 +236,11 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis // If this is not a successful start, or it is not a chain, or it is untrusted, return return; } synchronized(mAttributionChains) { addLinkToChainIfNotPresent(AppOpsManager.opToPublicName(op), packageName, uid, attributionTag, attributionFlags, attributionChainId); } } private void addLinkToChainIfNotPresent(String op, String packageName, int uid, String attributionTag, int attributionFlags, int attributionChainId) { Loading Loading @@ -310,7 +314,7 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis String permGroup = usedPermGroups.get(permGroupNum); ArrayMap<OpUsage, CharSequence> usagesWithLabels = getUniqueUsagesWithLabels(rawUsages.get(permGroup)); getUniqueUsagesWithLabels(permGroup, rawUsages.get(permGroup)); if (permGroup.equals(OPSTR_PHONE_CALL_MICROPHONE)) { isPhone = true; Loading Loading @@ -431,7 +435,8 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis return ListFormatter.getInstance().format(labels); } private ArrayMap<OpUsage, CharSequence> getUniqueUsagesWithLabels(List<OpUsage> usages) { private ArrayMap<OpUsage, CharSequence> getUniqueUsagesWithLabels(String permGroup, List<OpUsage> usages) { ArrayMap<OpUsage, CharSequence> usagesAndLabels = new ArrayMap<>(); if (usages == null || usages.isEmpty()) { Loading Loading @@ -466,7 +471,7 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis // If this usage has a proxy, but is not a proxy, it is the end of a chain. // TODO remove once camera converted if (!proxies.containsKey(usageAttr) && usage.proxy != null && !usage.op.equals(OPSTR_RECORD_AUDIO)) { && !MICROPHONE.equals(permGroup)) { proxyLabels.put(usage, new ArrayList<>()); proxyPackages.add(usage.getPackageIdHash()); } Loading Loading @@ -538,12 +543,13 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis // TODO ntmyren: remove this proxy logic once camera is converted to AttributionSource // For now: don't add mic proxy usages if (!start.op.equals(OPSTR_RECORD_AUDIO)) { if (!MICROPHONE.equals(permGroup)) { usagesAndLabels.put(start, proxyLabelList.isEmpty() ? null : formatLabelList(proxyLabelList)); } } synchronized (mAttributionChains) { for (int i = 0; i < mAttributionChains.size(); i++) { List<AccessChainLink> usageList = mAttributionChains.valueAt(i); int lastVisible = usageList.size() - 1; Loading @@ -551,7 +557,8 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis // if the list is empty or incomplete, do not show it. if (usageList.isEmpty() || !usageList.get(lastVisible).isEnd() || !usageList.get(0).isStart() || !usageList.get(lastVisible).usage.op.equals(OPSTR_RECORD_AUDIO)) { || !permGroup.equals(getGroupForOp(usageList.get(0).usage.op)) || !MICROPHONE.equals(permGroup)) { continue; } Loading Loading @@ -581,6 +588,7 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis } usagesAndLabels.put(start.usage, proxyLabel); } } for (int packageHash : mostRecentUsages.keySet()) { if (!proxyPackages.contains(packageHash)) { Loading