OSDN Git Service

PackageManager: Move compilation reasons to PMS
authorAndreas Gampe <agampe@google.com>
Fri, 25 Mar 2016 03:13:34 +0000 (20:13 -0700)
committerAndreas Gampe <agampe@google.com>
Fri, 25 Mar 2016 03:13:34 +0000 (20:13 -0700)
Move the reasons to PackageManagerService (making them public) so
they can be used by clients.

Bug: 27189430
Change-Id: I30e1f823f9297e95c5b1e389004a4fd3052d5702

services/core/java/com/android/server/pm/BackgroundDexOptService.java
services/core/java/com/android/server/pm/OtaDexoptService.java
services/core/java/com/android/server/pm/PackageManagerService.java
services/core/java/com/android/server/pm/PackageManagerServiceCompilerMapping.java
services/core/java/com/android/server/pm/PackageManagerShellCommand.java

index d449ce5..eae2eaa 100644 (file)
@@ -16,8 +16,6 @@
 
 package com.android.server.pm;
 
-import static com.android.server.pm.PackageManagerServiceCompilerMapping.REASON_BACKGROUND_DEXOPT;
-
 import android.app.AlarmManager;
 import android.app.job.JobInfo;
 import android.app.job.JobParameters;
@@ -26,7 +24,6 @@ import android.app.job.JobService;
 import android.content.ComponentName;
 import android.content.Context;
 import android.os.ServiceManager;
-import android.os.SystemProperties;
 import android.util.ArraySet;
 import android.util.Log;
 
@@ -94,7 +91,7 @@ public class BackgroundDexOptService extends JobService {
                         continue;
                     }
                     if (!pm.performDexOpt(pkg, /* instruction set */ null, /* checkProfiles */ true,
-                            REASON_BACKGROUND_DEXOPT, /* force */ false)) {
+                            PackageManagerService.REASON_BACKGROUND_DEXOPT, /* force */ false)) {
                         // there was a problem running dexopt,
                         // remember this so we do not keep retrying.
                         sFailedPackageNames.add(pkg);
index 03e838b..c3a9226 100644 (file)
@@ -20,7 +20,6 @@ import static com.android.server.pm.Installer.DEXOPT_OTA;
 import static com.android.server.pm.InstructionSets.getAppDexInstructionSets;
 import static com.android.server.pm.InstructionSets.getDexCodeInstructionSets;
 import static com.android.server.pm.PackageManagerServiceCompilerMapping.getCompilerFilterForReason;
-import static com.android.server.pm.PackageManagerServiceCompilerMapping.REASON_AB_OTA;
 
 import android.content.Context;
 import android.content.pm.IOtaDexopt;
@@ -144,7 +143,7 @@ public class OtaDexoptService extends IOtaDexopt.Stub {
         }
 
         mPackageDexOptimizer.performDexOpt(nextPackage, null /* ISAs */, false /* useProfiles */,
-                getCompilerFilterForReason(REASON_AB_OTA));
+                getCompilerFilterForReason(PackageManagerService.REASON_AB_OTA));
     }
 
     private void moveAbArtifacts(Installer installer) {
index b73d8f3..79932ad 100644 (file)
@@ -94,11 +94,6 @@ import static com.android.server.pm.InstructionSets.getPreferredInstructionSet;
 import static com.android.server.pm.InstructionSets.getPrimaryInstructionSet;
 import static com.android.server.pm.PackageManagerServiceCompilerMapping.getCompilerFilterForReason;
 import static com.android.server.pm.PackageManagerServiceCompilerMapping.getFullCompilerFilter;
-import static com.android.server.pm.PackageManagerServiceCompilerMapping.REASON_BOOT;
-import static com.android.server.pm.PackageManagerServiceCompilerMapping.REASON_FORCED_DEXOPT;
-import static com.android.server.pm.PackageManagerServiceCompilerMapping.REASON_INSTALL;
-import static com.android.server.pm.PackageManagerServiceCompilerMapping.REASON_NON_SYSTEM_LIBRARY;
-import static com.android.server.pm.PackageManagerServiceCompilerMapping.REASON_SHARED_APK;
 import static com.android.server.pm.PermissionsState.PERMISSION_OPERATION_FAILURE;
 import static com.android.server.pm.PermissionsState.PERMISSION_OPERATION_SUCCESS;
 import static com.android.server.pm.PermissionsState.PERMISSION_OPERATION_SUCCESS_GIDS_CHANGED;
@@ -448,6 +443,17 @@ public class PackageManagerService extends IPackageManager.Stub {
         sBrowserIntent.setData(Uri.parse("http:"));
     }
 
+    // Compilation reasons.
+    public static final int REASON_BOOT = 0;
+    public static final int REASON_INSTALL = 1;
+    public static final int REASON_BACKGROUND_DEXOPT = 2;
+    public static final int REASON_AB_OTA = 3;
+    public static final int REASON_NON_SYSTEM_LIBRARY = 4;
+    public static final int REASON_SHARED_APK = 5;
+    public static final int REASON_FORCED_DEXOPT = 6;
+
+    public static final int REASON_LAST = REASON_FORCED_DEXOPT;
+
     final ServiceThread mHandlerThread;
 
     final PackageHandler mHandler;
index b53f8d1..238e410 100644 (file)
@@ -24,17 +24,6 @@ import dalvik.system.DexFile;
  * Manage (retrieve) mappings from compilation reason to compilation filter.
  */
 class PackageManagerServiceCompilerMapping {
-    // Compilation reasons.
-    public static final int REASON_BOOT = 0;
-    public static final int REASON_INSTALL = 1;
-    public static final int REASON_BACKGROUND_DEXOPT = 2;
-    public static final int REASON_AB_OTA = 3;
-    public static final int REASON_NON_SYSTEM_LIBRARY = 4;
-    public static final int REASON_SHARED_APK = 5;
-    public static final int REASON_FORCED_DEXOPT = 6;
-
-    private static final int REASON_LAST = REASON_FORCED_DEXOPT;
-
     // Names for compilation reasons.
     static final String REASON_STRINGS[] = {
             "boot", "install", "bg-dexopt", "ab-ota", "nsys-library", "shared-apk", "forced-dexopt"
@@ -42,7 +31,7 @@ class PackageManagerServiceCompilerMapping {
 
     // Static block to ensure the strings array is of the right length.
     static {
-        if (REASON_LAST + 1 != REASON_STRINGS.length) {
+        if (PackageManagerService.REASON_LAST + 1 != REASON_STRINGS.length) {
             throw new IllegalStateException("REASON_STRINGS not correct");
         }
     }
@@ -67,8 +56,8 @@ class PackageManagerServiceCompilerMapping {
 
         // Ensure that some reasons are not mapped to profile-guided filters.
         switch (reason) {
-            case REASON_SHARED_APK:
-            case REASON_FORCED_DEXOPT:
+            case PackageManagerService.REASON_SHARED_APK:
+            case PackageManagerService.REASON_FORCED_DEXOPT:
                 if (DexFile.isProfileGuidedCompilerFilter(sysPropValue)) {
                     throw new IllegalStateException("\"" + sysPropValue + "\" is profile-guided, "
                             + "but not allowed for " + REASON_STRINGS[reason]);
@@ -86,7 +75,7 @@ class PackageManagerServiceCompilerMapping {
         // overview. Store the exceptions here.
         RuntimeException toThrow = null;
 
-        for (int reason = 0; reason <= REASON_LAST; reason++) {
+        for (int reason = 0; reason <= PackageManagerService.REASON_LAST; reason++) {
             try {
                 // Check that the system property name is legal.
                 String sysPropName = getSystemPropertyName(reason);
index 7f626b2..bf44b0f 100644 (file)
@@ -44,7 +44,6 @@ import android.os.Build;
 import android.os.Bundle;
 import android.os.RemoteException;
 import android.os.ShellCommand;
-import android.os.SystemProperties;
 import android.os.UserHandle;
 import android.text.TextUtils;
 import android.util.PrintWriterPrinter;
@@ -331,12 +330,12 @@ class PackageManagerShellCommand extends ShellCommand {
                 // Use the default mode for background dexopt.
                 targetCompilerFilter =
                         PackageManagerServiceCompilerMapping.getCompilerFilterForReason(
-                                PackageManagerServiceCompilerMapping.REASON_BACKGROUND_DEXOPT);
+                                PackageManagerService.REASON_BACKGROUND_DEXOPT);
             } else if ("reset".equals(compilerFilter)) {
                 // Use the default mode for install.
                 targetCompilerFilter =
                         PackageManagerServiceCompilerMapping.getCompilerFilterForReason(
-                                PackageManagerServiceCompilerMapping.REASON_INSTALL);
+                                PackageManagerService.REASON_INSTALL);
             } else {
                 if (!DexFile.isValidCompilerFilter(compilerFilter)) {
                     pw.println("Error: \"" + compilerFilter +