OSDN Git Service

Save package dex usage info after secondary dex reconciliation
authorCalin Juravle <calin@google.com>
Fri, 27 Jan 2017 02:53:23 +0000 (18:53 -0800)
committerCalin Juravle <calin@google.com>
Sat, 28 Jan 2017 03:31:41 +0000 (19:31 -0800)
Bug: 1833991
Test: add a bogus entry to /syste/data/package-dex-usage.list
      adb shell cmd package reconcile-secondary-dex-files
com.android.google.gms
      wait a bit and check the bogus entry is gone

Change-Id: Ic07126bfb8730933081a5e010e3c357d338786e8

services/core/java/com/android/server/pm/dex/DexManager.java
services/core/java/com/android/server/pm/dex/PackageDexUsage.java

index cc4b1c2..964ed98 100644 (file)
@@ -282,6 +282,7 @@ public class DexManager {
             return;
         }
         Set<String> dexFilesToRemove = new HashSet<>();
+        boolean updated = false;
         for (Map.Entry<String, DexUseInfo> entry : useInfo.getDexUseInfoMap().entrySet()) {
             String dexPath = entry.getKey();
             DexUseInfo dexUseInfo = entry.getValue();
@@ -302,7 +303,8 @@ public class DexManager {
                 Slog.d(TAG, "Could not find package when compiling secondary dex " + packageName
                         + " for user " + dexUseInfo.getOwnerUserId());
                 // Update the usage and continue, another user might still have the package.
-                mPackageDexUsage.removeUserPackage(packageName, dexUseInfo.getOwnerUserId());
+                updated = mPackageDexUsage.removeUserPackage(
+                        packageName, dexUseInfo.getOwnerUserId()) || updated;
                 continue;
             }
             ApplicationInfo info = pkg.applicationInfo;
@@ -313,7 +315,8 @@ public class DexManager {
                 flags |= StorageManager.FLAG_STORAGE_CE;
             } else {
                 Slog.e(TAG, "Could not infer CE/DE storage for package " + info.packageName);
-                mPackageDexUsage.removeUserPackage(packageName, dexUseInfo.getOwnerUserId());
+                updated = mPackageDexUsage.removeUserPackage(
+                        packageName, dexUseInfo.getOwnerUserId()) || updated;
                 continue;
             }
 
@@ -329,8 +332,13 @@ public class DexManager {
                 }
             }
             if (!dexStillExists) {
-                mPackageDexUsage.removeDexFile(packageName, dexPath, dexUseInfo.getOwnerUserId());
+                updated = mPackageDexUsage.removeDexFile(
+                        packageName, dexPath, dexUseInfo.getOwnerUserId()) || updated;
             }
+
+        }
+        if (updated) {
+            mPackageDexUsage.maybeWriteAsync();
         }
     }
 
index 2613416..3693bce 100644 (file)
@@ -378,6 +378,8 @@ public class PackageDexUsage extends AbstractStatsBase<Void> {
 
     /**
      * Remove all the records about package {@code packageName} belonging to user {@code userId}.
+     * @return true if the record was found and actually deleted,
+     *         false if the record doesn't exist
      */
     public boolean removeUserPackage(String packageName, int userId) {
         synchronized (mPackageUseInfoMap) {
@@ -402,6 +404,8 @@ public class PackageDexUsage extends AbstractStatsBase<Void> {
     /**
      * Remove the secondary dex file record belonging to the package {@code packageName}
      * and user {@code userId}.
+     * @return true if the record was found and actually deleted,
+     *         false if the record doesn't exist
      */
     public boolean removeDexFile(String packageName, String dexFile, int userId) {
         synchronized (mPackageUseInfoMap) {