OSDN Git Service

PackageParser: Disable package cache on "eng" builds.
authorNarayan Kamath <narayan@google.com>
Fri, 13 Jan 2017 10:34:29 +0000 (10:34 +0000)
committerNarayan Kamath <narayan@google.com>
Fri, 13 Jan 2017 16:09:05 +0000 (16:09 +0000)
- Catch a wider variety of exceptions from the package parse
  stage. Ignore and delete the cache entry if we catch *any*
  exceptions from deserializing the parse result.

- Rename the system property pm.boot and not ro.boot, since the
  former needs less effort to change back and forth.

- Finally, add a heuristic to wipe caches on non-numbered
  userdebug builds when changes to the system partition are detected.

Also re-enable the cache by reverting commit
20274d15d8f40112dd13d01980c210b49f78cda9.

Test: Manual
Change-Id: I7b5b71ac60d8c438398c354be50b207e80550148

core/java/android/content/pm/PackageParser.java
services/core/java/com/android/server/pm/PackageManagerService.java

index a48762b..083e4cc 100644 (file)
@@ -950,8 +950,8 @@ public class PackageParser {
         try {
             final byte[] bytes = IoUtils.readFileAsByteArray(cacheFile.getAbsolutePath());
             return fromCacheEntry(bytes);
-        } catch (IOException ioe) {
-            Slog.w(TAG, "Error reading package cache: ", ioe);
+        } catch (Exception e) {
+            Slog.w(TAG, "Error reading package cache: ", e);
 
             // If something went wrong while reading the cache entry, delete the cache file
             // so that we regenerate it the next time.
index b29bf7b..7ede0f8 100644 (file)
@@ -576,7 +576,7 @@ public class PackageManagerService extends IPackageManager.Stub {
     /**
      * Whether the package parser cache is enabled.
      */
-    private static final boolean DEFAULT_PACKAGE_PARSER_CACHE_ENABLED = false;
+    private static final boolean DEFAULT_PACKAGE_PARSER_CACHE_ENABLED = true;
 
     final ServiceThread mHandlerThread;
 
@@ -2842,7 +2842,12 @@ public class PackageManagerService extends IPackageManager.Stub {
             return null;
         }
 
-        if (SystemProperties.getBoolean("ro.boot.disable_package_cache", false)) {
+        // Disable package parsing on eng builds to allow for faster incremental development.
+        if ("eng".equals(Build.TYPE)) {
+            return null;
+        }
+
+        if (SystemProperties.getBoolean("pm.boot.disable_package_cache", false)) {
             Slog.i(TAG, "Disabling package parser cache due to system property.");
             return null;
         }
@@ -2861,9 +2866,33 @@ public class PackageManagerService extends IPackageManager.Stub {
             FileUtils.deleteContents(cacheBaseDir);
         }
 
+
         // Return the versioned package cache directory. This is something like
         // "/data/system/package_cache/1"
-        return FileUtils.createDir(cacheBaseDir, PACKAGE_PARSER_CACHE_VERSION);
+        File cacheDir = FileUtils.createDir(cacheBaseDir, PACKAGE_PARSER_CACHE_VERSION);
+
+        // The following is a workaround to aid development on non-numbered userdebug
+        // builds or cases where "adb sync" is used on userdebug builds. If we detect that
+        // the system partition is newer.
+        //
+        // NOTE: When no BUILD_NUMBER is set by the build system, it defaults to a build
+        // that starts with "eng." to signify that this is an engineering build and not
+        // destined for release.
+        if ("userdebug".equals(Build.TYPE) && Build.VERSION.INCREMENTAL.startsWith("eng.")) {
+            Slog.w(TAG, "Wiping cache directory because the system partition changed.");
+
+            // Heuristic: If the /system directory has been modified recently due to an "adb sync"
+            // or a regular make, then blow away the cache. Note that mtimes are *NOT* reliable
+            // in general and should not be used for production changes. In this specific case,
+            // we know that they will work.
+            File frameworkDir = new File(Environment.getRootDirectory(), "framework");
+            if (cacheDir.lastModified() < frameworkDir.lastModified()) {
+                FileUtils.deleteContents(cacheBaseDir);
+                cacheDir = FileUtils.createDir(cacheBaseDir, PACKAGE_PARSER_CACHE_VERSION);
+            }
+        }
+
+        return cacheDir;
     }
 
     @Override