OSDN Git Service

Add a shell command to force the background dexopt job
authorCalin Juravle <calin@google.com>
Thu, 26 Jan 2017 01:16:08 +0000 (17:16 -0800)
committerCalin Juravle <calin@google.com>
Thu, 2 Mar 2017 21:13:12 +0000 (13:13 -0800)
Add 'bg-dexopt-job' command to 'adb shell cmd package' which will force
the background  dexopt job to run the optimizations immediately.

Note that the command only runs the background optimizer logic. It may
overlap with the actual job but the job scheduler will not be able to
cancel it. It will also run even if the device is not in the idle
maintenance mode.

Test: adb shell cmd package bg-dexopt-job
Bug: 32871170

(cherry picked from commit cb5f41ea11b1a6fcd0977a64ee146dde8f537076)

Change-Id: I82c781d46fe16e7b7566a5b5ee91be723a2125cb

Merged-In: I8b0112074220b2e09baf13d842401ee1cf306a89

core/java/android/content/pm/IPackageManager.aidl
services/core/java/com/android/server/pm/BackgroundDexOptService.java
services/core/java/com/android/server/pm/PackageManagerService.java
services/core/java/com/android/server/pm/PackageManagerShellCommand.java

index d27b0df..46b981e 100644 (file)
@@ -510,6 +510,11 @@ interface IPackageManager {
     void forceDexOpt(String packageName);
 
     /**
+     * Execute the background dexopt job immediately.
+     */
+    boolean runBackgroundDexoptJob();
+
+    /**
      * Reconcile the information we have about the secondary dex files belonging to
      * {@code packagName} and the actual dex files. For all dex files that were
      * deleted, update the internal records and delete the generated oat files.
index 28151ab..a2f29c9 100644 (file)
@@ -280,6 +280,17 @@ public class BackgroundDexOptService extends JobService {
         return false;
     }
 
+    /**
+     * Execute the idle optimizations immediately.
+     */
+    public static boolean runIdleOptimizationsNow(PackageManagerService pm, Context context) {
+        // Create a new object to make sure we don't interfere with the scheduled jobs.
+        // Note that this may still run at the same time with the job scheduled by the
+        // JobScheduler but the scheduler will not be able to cancel it.
+        BackgroundDexOptService bdos = new BackgroundDexOptService();
+        return bdos.idleOptimization(pm, pm.getOptimizablePackages(), context);
+    }
+
     @Override
     public boolean onStartJob(JobParameters params) {
         if (DEBUG_DEXOPT) {
index 328109e..84cb1bc 100644 (file)
@@ -7527,6 +7527,14 @@ public class PackageManagerService extends IPackageManager.Stub {
         mDexManager.reconcileSecondaryDexFiles(packageName);
     }
 
+    /**
+     * Execute the background dexopt job immediately.
+     */
+    @Override
+    public boolean runBackgroundDexoptJob() {
+        return BackgroundDexOptService.runIdleOptimizationsNow(this, mContext);
+    }
+
     Collection<PackageParser.Package> findSharedNonSystemLibraries(PackageParser.Package p) {
         if (p.usesLibraries != null || p.usesOptionalLibraries != null) {
             ArrayList<PackageParser.Package> retValue = new ArrayList<>();
index 5b2bf80..44b372b 100644 (file)
@@ -112,6 +112,8 @@ class PackageManagerShellCommand extends ShellCommand {
                     return runCompile();
                 case "reconcile-secondary-dex-files":
                     return runreconcileSecondaryDexFiles();
+                case "bg-dexopt-job":
+                    return runDexoptJob();
                 case "dump-profiles":
                     return runDumpProfiles();
                 case "list":
@@ -424,6 +426,11 @@ class PackageManagerShellCommand extends ShellCommand {
         return 0;
     }
 
+    private int runDexoptJob() throws RemoteException {
+        boolean result = mInterface.runBackgroundDexoptJob();
+        return result ? 0 : -1;
+    }
+
     private int runDumpProfiles() throws RemoteException {
         String packageName = getNextArg();
         mInterface.dumpProfiles(packageName);
@@ -1456,7 +1463,13 @@ class PackageManagerShellCommand extends ShellCommand {
         }
         pw.println("      --reset: restore package to its post-install state");
         pw.println("      --check-prof (true | false): look at profiles when doing dexopt?");
-        pw.println("      --secondary-dex: copmile app secondary dex files");
+        pw.println("      --secondary-dex: compile app secondary dex files");
+        pw.println("  bg-dexopt-job");
+        pw.println("    Execute the background optimizations immediately.");
+        pw.println("    Note that the command only runs the background optimizer logic. It may");
+        pw.println("    overlap with the actual job but the job scheduler will not be able to");
+        pw.println("    cancel it. It will also run even if the device is not in the idle");
+        pw.println("    maintenance mode.");
         pw.println("  list features");
         pw.println("    Prints all features of the system.");
         pw.println("  list instrumentation [-f] [TARGET-PACKAGE]");