Merge "Ensure only microphone attribution chains are recorded" into sc-v2-dev
This commit is contained in:
@@ -199,22 +199,24 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis
|
|||||||
// if any link in the chain is finished, remove the chain. Then, find any other chains that
|
// 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.
|
// contain this op/package/uid/tag combination, and remove them, as well.
|
||||||
// TODO ntmyren: be smarter about this
|
// TODO ntmyren: be smarter about this
|
||||||
mAttributionChains.remove(attributionChainId);
|
synchronized(mAttributionChains) {
|
||||||
int numChains = mAttributionChains.size();
|
mAttributionChains.remove(attributionChainId);
|
||||||
ArrayList<Integer> toRemove = new ArrayList<>();
|
int numChains = mAttributionChains.size();
|
||||||
for (int i = 0; i < numChains; i++) {
|
ArrayList<Integer> toRemove = new ArrayList<>();
|
||||||
int chainId = mAttributionChains.keyAt(i);
|
for (int i = 0; i < numChains; i++) {
|
||||||
ArrayList<AccessChainLink> chain = mAttributionChains.valueAt(i);
|
int chainId = mAttributionChains.keyAt(i);
|
||||||
int chainSize = chain.size();
|
ArrayList<AccessChainLink> chain = mAttributionChains.valueAt(i);
|
||||||
for (int j = 0; j < chainSize; j++) {
|
int chainSize = chain.size();
|
||||||
AccessChainLink link = chain.get(j);
|
for (int j = 0; j < chainSize; j++) {
|
||||||
if (link.packageAndOpEquals(op, packageName, attributionTag, uid)) {
|
AccessChainLink link = chain.get(j);
|
||||||
toRemove.add(chainId);
|
if (link.packageAndOpEquals(op, packageName, attributionTag, uid)) {
|
||||||
break;
|
toRemove.add(chainId);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mAttributionChains.removeAll(toRemove);
|
||||||
}
|
}
|
||||||
mAttributionChains.removeAll(toRemove);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -234,8 +236,10 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis
|
|||||||
// If this is not a successful start, or it is not a chain, or it is untrusted, return
|
// If this is not a successful start, or it is not a chain, or it is untrusted, return
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
addLinkToChainIfNotPresent(AppOpsManager.opToPublicName(op), packageName, uid,
|
synchronized(mAttributionChains) {
|
||||||
attributionTag, attributionFlags, attributionChainId);
|
addLinkToChainIfNotPresent(AppOpsManager.opToPublicName(op), packageName, uid,
|
||||||
|
attributionTag, attributionFlags, attributionChainId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addLinkToChainIfNotPresent(String op, String packageName, int uid,
|
private void addLinkToChainIfNotPresent(String op, String packageName, int uid,
|
||||||
@@ -310,7 +314,7 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis
|
|||||||
String permGroup = usedPermGroups.get(permGroupNum);
|
String permGroup = usedPermGroups.get(permGroupNum);
|
||||||
|
|
||||||
ArrayMap<OpUsage, CharSequence> usagesWithLabels =
|
ArrayMap<OpUsage, CharSequence> usagesWithLabels =
|
||||||
getUniqueUsagesWithLabels(rawUsages.get(permGroup));
|
getUniqueUsagesWithLabels(permGroup, rawUsages.get(permGroup));
|
||||||
|
|
||||||
if (permGroup.equals(OPSTR_PHONE_CALL_MICROPHONE)) {
|
if (permGroup.equals(OPSTR_PHONE_CALL_MICROPHONE)) {
|
||||||
isPhone = true;
|
isPhone = true;
|
||||||
@@ -431,7 +435,8 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis
|
|||||||
return ListFormatter.getInstance().format(labels);
|
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<>();
|
ArrayMap<OpUsage, CharSequence> usagesAndLabels = new ArrayMap<>();
|
||||||
|
|
||||||
if (usages == null || usages.isEmpty()) {
|
if (usages == null || usages.isEmpty()) {
|
||||||
@@ -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.
|
// If this usage has a proxy, but is not a proxy, it is the end of a chain.
|
||||||
// TODO remove once camera converted
|
// TODO remove once camera converted
|
||||||
if (!proxies.containsKey(usageAttr) && usage.proxy != null
|
if (!proxies.containsKey(usageAttr) && usage.proxy != null
|
||||||
&& !usage.op.equals(OPSTR_RECORD_AUDIO)) {
|
&& !MICROPHONE.equals(permGroup)) {
|
||||||
proxyLabels.put(usage, new ArrayList<>());
|
proxyLabels.put(usage, new ArrayList<>());
|
||||||
proxyPackages.add(usage.getPackageIdHash());
|
proxyPackages.add(usage.getPackageIdHash());
|
||||||
}
|
}
|
||||||
@@ -538,48 +543,51 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis
|
|||||||
|
|
||||||
// TODO ntmyren: remove this proxy logic once camera is converted to AttributionSource
|
// TODO ntmyren: remove this proxy logic once camera is converted to AttributionSource
|
||||||
// For now: don't add mic proxy usages
|
// For now: don't add mic proxy usages
|
||||||
if (!start.op.equals(OPSTR_RECORD_AUDIO)) {
|
if (!MICROPHONE.equals(permGroup)) {
|
||||||
usagesAndLabels.put(start,
|
usagesAndLabels.put(start,
|
||||||
proxyLabelList.isEmpty() ? null : formatLabelList(proxyLabelList));
|
proxyLabelList.isEmpty() ? null : formatLabelList(proxyLabelList));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < mAttributionChains.size(); i++) {
|
synchronized (mAttributionChains) {
|
||||||
List<AccessChainLink> usageList = mAttributionChains.valueAt(i);
|
for (int i = 0; i < mAttributionChains.size(); i++) {
|
||||||
int lastVisible = usageList.size() - 1;
|
List<AccessChainLink> usageList = mAttributionChains.valueAt(i);
|
||||||
// TODO ntmyren: remove this mic code once camera is converted to AttributionSource
|
int lastVisible = usageList.size() - 1;
|
||||||
// if the list is empty or incomplete, do not show it.
|
// TODO ntmyren: remove this mic code once camera is converted to AttributionSource
|
||||||
if (usageList.isEmpty() || !usageList.get(lastVisible).isEnd()
|
// if the list is empty or incomplete, do not show it.
|
||||||
|| !usageList.get(0).isStart()
|
if (usageList.isEmpty() || !usageList.get(lastVisible).isEnd()
|
||||||
|| !usageList.get(lastVisible).usage.op.equals(OPSTR_RECORD_AUDIO)) {
|
|| !usageList.get(0).isStart()
|
||||||
continue;
|
|| !permGroup.equals(getGroupForOp(usageList.get(0).usage.op))
|
||||||
}
|
|| !MICROPHONE.equals(permGroup)) {
|
||||||
|
continue;
|
||||||
//TODO ntmyren: remove once camera etc. etc.
|
|
||||||
for (AccessChainLink link: usageList) {
|
|
||||||
proxyPackages.add(link.usage.getPackageIdHash());
|
|
||||||
}
|
|
||||||
|
|
||||||
AccessChainLink start = usageList.get(0);
|
|
||||||
AccessChainLink lastVisibleLink = usageList.get(lastVisible);
|
|
||||||
while (lastVisible > 0 && !shouldShowPackage(lastVisibleLink.usage.packageName)) {
|
|
||||||
lastVisible--;
|
|
||||||
lastVisibleLink = usageList.get(lastVisible);
|
|
||||||
}
|
|
||||||
String proxyLabel = null;
|
|
||||||
if (!lastVisibleLink.usage.packageName.equals(start.usage.packageName)) {
|
|
||||||
try {
|
|
||||||
PackageManager userPkgManager =
|
|
||||||
getUserContext(lastVisibleLink.usage.getUser()).getPackageManager();
|
|
||||||
ApplicationInfo appInfo = userPkgManager.getApplicationInfo(
|
|
||||||
lastVisibleLink.usage.packageName, 0);
|
|
||||||
proxyLabel = appInfo.loadLabel(userPkgManager).toString();
|
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
// do nothing
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO ntmyren: remove once camera etc. etc.
|
||||||
|
for (AccessChainLink link : usageList) {
|
||||||
|
proxyPackages.add(link.usage.getPackageIdHash());
|
||||||
|
}
|
||||||
|
|
||||||
|
AccessChainLink start = usageList.get(0);
|
||||||
|
AccessChainLink lastVisibleLink = usageList.get(lastVisible);
|
||||||
|
while (lastVisible > 0 && !shouldShowPackage(lastVisibleLink.usage.packageName)) {
|
||||||
|
lastVisible--;
|
||||||
|
lastVisibleLink = usageList.get(lastVisible);
|
||||||
|
}
|
||||||
|
String proxyLabel = null;
|
||||||
|
if (!lastVisibleLink.usage.packageName.equals(start.usage.packageName)) {
|
||||||
|
try {
|
||||||
|
PackageManager userPkgManager =
|
||||||
|
getUserContext(lastVisibleLink.usage.getUser()).getPackageManager();
|
||||||
|
ApplicationInfo appInfo = userPkgManager.getApplicationInfo(
|
||||||
|
lastVisibleLink.usage.packageName, 0);
|
||||||
|
proxyLabel = appInfo.loadLabel(userPkgManager).toString();
|
||||||
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
usagesAndLabels.put(start.usage, proxyLabel);
|
||||||
}
|
}
|
||||||
usagesAndLabels.put(start.usage, proxyLabel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int packageHash : mostRecentUsages.keySet()) {
|
for (int packageHash : mostRecentUsages.keySet()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user