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

Commit ccf04851 authored by Rhed Jao's avatar Rhed Jao
Browse files

Reduce lock contention in the package manager dump

Applications frequently anr while the bugreport is capturing.
The problem is relevant to the package manager held the lock
contention long time in its dump. This patch removes the long
lock in the dump. Instead, it adds locks to each dump section.
A new `dump` function in the ComputerEngine is added also. The
sections which could be dumped withoud a lock are moved to it.

Bug: 178304105
Test: adb bugreport
Change-Id: Id3020ce335b81d79a1ce7ecb17d5a6cc1e428560
parent 3278c403
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ import java.util.Objects;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.concurrent.Executor;
import java.util.function.Function;

/**
 * The entity responsible for filtering visibility between apps based on declarations in their
@@ -1354,14 +1355,13 @@ public class AppsFilter implements Watchable, Snappable {
    }

    public void dumpQueries(
            PrintWriter pw, PackageManagerService pms, @Nullable Integer filteringAppId,
            DumpState dumpState,
            int[] users) {
            PrintWriter pw, @Nullable Integer filteringAppId, DumpState dumpState, int[] users,
            Function<Integer, String[]> getPackagesForUid) {
        final SparseArray<String> cache = new SparseArray<>();
        ToString<Integer> expandPackages = input -> {
            String cachedValue = cache.get(input);
            if (cachedValue == null) {
                final String[] packagesForUid = pms.getPackagesForUid(input);
                final String[] packagesForUid = getPackagesForUid.apply(input);
                if (packagesForUid == null) {
                    cachedValue = "[unknown app id " + input + "]";
                } else {
+19 −0
Original line number Diff line number Diff line
@@ -55,6 +55,9 @@ public final class DumpState {
    private int mOptions;

    private boolean mTitlePrinted;
    private boolean mFullPreferred;

    private String mTargetPackageName;

    private SharedUserSetting mSharedUser;

@@ -99,4 +102,20 @@ public final class DumpState {
    public void setSharedUser(SharedUserSetting user) {
        mSharedUser = user;
    }

    public String getTargetPackageName() {
        return mTargetPackageName;
    }

    public void setTargetPackageName(String packageName) {
        mTargetPackageName = packageName;
    }

    public boolean isFullPreferred() {
        return mFullPreferred;
    }

    public void setFullPreferred(boolean fullPreferred) {
        mFullPreferred = fullPreferred;
    }
}
+384 −291

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1
Original line number Diff line number Diff line
@@ -4877,7 +4877,7 @@ public final class Settings implements Watchable, Snappable {
        }
    }

    void dumpPermissionsLPr(PrintWriter pw, String packageName, ArraySet<String> permissionNames,
    void dumpPermissions(PrintWriter pw, String packageName, ArraySet<String> permissionNames,
            DumpState dumpState) {
        LegacyPermissionSettings.dumpPermissions(pw, packageName, permissionNames,
                mPermissionDataProvider.getLegacyPermissions(),