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

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

Move dump shared libraries into the ComputerEngine

Reduce package manager lock contention in the dump function by
moving the dumps to the ComputerEngine.

Test: adb bugreport
Bug: 178304105
Change-Id: Ief726e2e0c2aae54d5594d79a3e6e7e2cb46b0b5
parent 53863bbc
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ public final class DumpState {

    private boolean mTitlePrinted;
    private boolean mFullPreferred;
    private boolean mCheckIn;

    private String mTargetPackageName;

@@ -118,4 +119,12 @@ public final class DumpState {
    public void setFullPreferred(boolean fullPreferred) {
        mFullPreferred = fullPreferred;
    }

    public boolean isCheckIn() {
        return mCheckIn;
    }

    public void setCheckIn(boolean checkIn) {
        mCheckIn = checkIn;
    }
}
+54 −55
Original line number Diff line number Diff line
@@ -4403,6 +4403,7 @@ public class PackageManagerService extends IPackageManager.Stub
        public void dump(int type, FileDescriptor fd, PrintWriter pw, DumpState dumpState) {
            final String packageName = dumpState.getTargetPackageName();
            final boolean checkin = dumpState.isCheckIn();
            switch (type) {
                case DumpState.DUMP_VERSION:
@@ -4415,6 +4416,56 @@ public class PackageManagerService extends IPackageManager.Stub
                    break;
                }
                case DumpState.DUMP_LIBS:
                {
                    boolean printedHeader = false;
                    final int numSharedLibraries = mSharedLibraries.size();
                    for (int index = 0; index < numSharedLibraries; index++) {
                        final String libName = mSharedLibraries.keyAt(index);
                        final WatchedLongSparseArray<SharedLibraryInfo> versionedLib =
                                mSharedLibraries.get(libName);
                        if (versionedLib == null) {
                            continue;
                        }
                        final int versionCount = versionedLib.size();
                        for (int i = 0; i < versionCount; i++) {
                            SharedLibraryInfo libraryInfo = versionedLib.valueAt(i);
                            if (!checkin) {
                                if (!printedHeader) {
                                    if (dumpState.onTitlePrinted()) {
                                        pw.println();
                                    }
                                    pw.println("Libraries:");
                                    printedHeader = true;
                                }
                                pw.print("  ");
                            } else {
                                pw.print("lib,");
                            }
                            pw.print(libraryInfo.getName());
                            if (libraryInfo.isStatic()) {
                                pw.print(" version=" + libraryInfo.getLongVersion());
                            }
                            if (!checkin) {
                                pw.print(" -> ");
                            }
                            if (libraryInfo.getPath() != null) {
                                if (libraryInfo.isNative()) {
                                    pw.print(" (so) ");
                                } else {
                                    pw.print(" (jar) ");
                                }
                                pw.print(libraryInfo.getPath());
                            } else {
                                pw.print(" (apk) ");
                                pw.print(libraryInfo.getPackageName());
                            }
                            pw.println();
                        }
                    }
                    break;
                }
                case DumpState.DUMP_PREFERRED_XML:
                {
                    pw.flush();
@@ -23699,8 +23750,6 @@ public class PackageManagerService extends IPackageManager.Stub
        if (!DumpUtils.checkDumpAndUsageStatsPermission(mContext, TAG, pw)) return;
        DumpState dumpState = new DumpState();
        boolean checkin = false;
        ArraySet<String> permissionNames = null;
        int opti = 0;
@@ -23750,7 +23799,7 @@ public class PackageManagerService extends IPackageManager.Stub
                pw.println("    <package.name>: info about given package");
                return;
            } else if ("--checkin".equals(opt)) {
                checkin = true;
                dumpState.setCheckIn(true);
            } else if ("--all-components".equals(opt)) {
                dumpState.setOptionEnabled(DumpState.OPTION_DUMP_ALL_COMPONENTS);
            } else if ("-f".equals(opt)) {
@@ -23904,6 +23953,7 @@ public class PackageManagerService extends IPackageManager.Stub
        }
        final String packageName = dumpState.getTargetPackageName();
        final boolean checkin = dumpState.isCheckIn();
        if (checkin) {
            pw.println("vers,1");
        }
@@ -23992,11 +24042,7 @@ public class PackageManagerService extends IPackageManager.Stub
        }
        if (dumpState.isDumping(DumpState.DUMP_LIBS) && packageName == null) {
            // TODO: Move it to ComputerEngine once LongSparseArray<SharedLibraryInfo> is copied
            //  in snapshot.
            synchronized (mLock) {
                dumpSharedLibrariesLPr(pw, dumpState, checkin);
            }
            dump(DumpState.DUMP_LIBS, fd, pw, dumpState);
        }
        if (dumpState.isDumping(DumpState.DUMP_FEATURES) && packageName == null) {
@@ -24337,53 +24383,6 @@ public class PackageManagerService extends IPackageManager.Stub
        }
    }
    private void dumpSharedLibrariesLPr(PrintWriter pw, DumpState dumpState, boolean checkin) {
        boolean printedHeader = false;
        final int numSharedLibraries = mSharedLibraries.size();
        for (int index = 0; index < numSharedLibraries; index++) {
            final String libName = mSharedLibraries.keyAt(index);
            WatchedLongSparseArray<SharedLibraryInfo> versionedLib = mSharedLibraries.get(libName);
            if (versionedLib == null) {
                continue;
            }
            final int versionCount = versionedLib.size();
            for (int i = 0; i < versionCount; i++) {
                SharedLibraryInfo libraryInfo = versionedLib.valueAt(i);
                if (!checkin) {
                    if (!printedHeader) {
                        if (dumpState.onTitlePrinted()) {
                            pw.println();
                        }
                        pw.println("Libraries:");
                        printedHeader = true;
                    }
                    pw.print("  ");
                } else {
                    pw.print("lib,");
                }
                pw.print(libraryInfo.getName());
                if (libraryInfo.isStatic()) {
                    pw.print(" version=" + libraryInfo.getLongVersion());
                }
                if (!checkin) {
                    pw.print(" -> ");
                }
                if (libraryInfo.getPath() != null) {
                    if (libraryInfo.isNative()) {
                        pw.print(" (so) ");
                    } else {
                        pw.print(" (jar) ");
                    }
                    pw.print(libraryInfo.getPath());
                } else {
                    pw.print(" (apk) ");
                    pw.print(libraryInfo.getPackageName());
                }
                pw.println();
            }
        }
    }
    // ------- apps on sdcard specific code -------
    static final boolean DEBUG_SD_INSTALL = false;