Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 10b225f9 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Lock mAttributionChains in PermissionUsageHelper"

parents 8c40ca74 8fb048ae
Loading
Loading
Loading
Loading
+58 −48
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@ import android.telephony.TelephonyManager;
import android.util.ArrayMap;
import android.util.ArraySet;

import com.android.internal.annotations.GuardedBy;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -150,7 +152,9 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis
    private ArrayMap<UserHandle, Context> mUserContexts;
    private PackageManager mPkgManager;
    private AppOpsManager mAppOpsManager;
    private ArrayMap<Integer, ArrayList<AccessChainLink>> mAttributionChains = new ArrayMap<>();
    @GuardedBy("mAttributionChains")
    private final ArrayMap<Integer, ArrayList<AccessChainLink>> mAttributionChains =
            new ArrayMap<>();

    /**
     * Constructor for PermissionUsageHelper
@@ -199,6 +203,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<>();
@@ -216,6 +221,7 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis
            }
            mAttributionChains.removeAll(toRemove);
        }
    }

    @Override
    public void onOpStarted(int op, int uid, String packageName, String attributionTag,
@@ -234,11 +240,13 @@ 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;
        }
        addLinkToChainIfNotPresent(AppOpsManager.opToPublicName(op), packageName, uid,
        synchronized (mAttributionChains) {
            addLinkToChainIfNotPresentLocked(AppOpsManager.opToPublicName(op), packageName, uid,
                    attributionTag, attributionFlags, attributionChainId);
        }
    }

    private void addLinkToChainIfNotPresent(String op, String packageName, int uid,
    private void addLinkToChainIfNotPresentLocked(String op, String packageName, int uid,
            String attributionTag, int attributionFlags, int attributionChainId) {

        ArrayList<AccessChainLink> currentChain = mAttributionChains.computeIfAbsent(
@@ -544,6 +552,7 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis
            }
        }

        synchronized (mAttributionChains) {
            for (int i = 0; i < mAttributionChains.size(); i++) {
                List<AccessChainLink> usageList = mAttributionChains.valueAt(i);
                int lastVisible = usageList.size() - 1;
@@ -581,6 +590,7 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis
                }
                usagesAndLabels.put(start.usage, proxyLabel);
            }
        }

        for (int packageHash : mostRecentUsages.keySet()) {
            if (!proxyPackages.contains(packageHash)) {