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

Commit 20e0c50f authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Jeff Sharkey
Browse files

Offer force-dex-opt when running as root.

Recently we removed the PackageManager inotify triggers, meaning the
only supported ways of installing apps were:

-- adb install -r Foo.apk
-- adb shell stop && adb sync && adb shell start

Iterating on most system apps (like Settings) can use the first
approach, but it doesn't work for "persistent" processes like
SystemUI.  (ActivityManager is very particular about how it deals
with persistent apps, and it always sticks with the first
ApplicationInfo found at boot.)

So to enable rapid iteration on persistent apps, we now offer the
one missing piece of forcing a dexopt with a new pm force-dex-opt
command only available to -eng or -userdebug builds.  Typical use
for iterating on persistent apps now looks like this:

$ mmm frameworks/base/packages/SystemUI/ && adb sync &&
    adb shell pm force-dex-opt com.android.systemui &&
    adb shell kill `pid systemui`

Yay!

Change-Id: I0ae2467f1d7cda56c70ba20953cd25fa8ee766ff
parent a753f4c6
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -253,6 +253,11 @@ public final class Pm {
            return;
        }

        if ("force-dex-opt".equals(op)) {
            runForceDexOpt();
            return;
        }

        try {
            if (args.length == 1) {
                if (args[0].equalsIgnoreCase("-l")) {
@@ -1248,6 +1253,15 @@ public final class Pm {
        System.out.println("Maximum supported users: " + UserManager.getMaxSupportedUsers());
    }

    public void runForceDexOpt() {
        final String packageName = nextArg();
        try {
            mPm.forceDexOpt(packageName);
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
    }

    class PackageDeleteObserver extends IPackageDeleteObserver.Stub {
        boolean finished;
        boolean result;
+2 −0
Original line number Diff line number Diff line
@@ -397,6 +397,8 @@ interface IPackageManager {
     */
    boolean performDexOptIfNeeded(String packageName, String instructionSet);

    void forceDexOpt(String packageName);

    /**
     * Update status of external media on the package manager to scan and
     * install packages installed on the external media. Like say the
+22 −0
Original line number Diff line number Diff line
@@ -4728,6 +4728,28 @@ public class PackageManagerService extends IPackageManager.Stub {
        return allInstructionSets;
    }
    @Override
    public void forceDexOpt(String packageName) {
        enforceSystemOrRoot("forceDexOpt");
        PackageParser.Package pkg;
        synchronized (mPackages) {
            pkg = mPackages.get(packageName);
            if (pkg == null) {
                throw new IllegalArgumentException("Missing package: " + packageName);
            }
        }
        synchronized (mInstallLock) {
            final String[] instructionSets = new String[] {
                    getPrimaryInstructionSet(pkg.applicationInfo) };
            final int res = performDexOptLI(pkg, instructionSets, true, false, true);
            if (res != DEX_OPT_PERFORMED) {
                throw new IllegalStateException("Failed to dexopt: " + res);
            }
        }
    }
    private int performDexOptLI(PackageParser.Package pkg, String[] instructionSets,
                                boolean forceDex, boolean defer, boolean inclDependencies) {
        HashSet<String> done;