Skip to content

Commit

Permalink
Merge "Fix dex file pruning logic."
Browse files Browse the repository at this point in the history
  • Loading branch information
narayank authored and Gerrit Code Review committed May 1, 2014
2 parents bcc3b31 + 5715657 commit 27f2bfc
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions services/java/com/android/server/pm/PackageManagerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -1289,24 +1289,7 @@ public PackageManagerService(Context context, Installer installer,
}

if (didDexOpt) {
File dalvikCacheDir = new File(dataDir, "dalvik-cache");

// If we had to do a dexopt of one of the previous
// things, then something on the system has changed.
// Consider this significant, and wipe away all other
// existing dexopt files to ensure we don't leave any
// dangling around.
String[] files = dalvikCacheDir.list();
if (files != null) {
for (int i=0; i<files.length; i++) {
String fn = files[i];
if (fn.startsWith("data@app@")
|| fn.startsWith("data@app-private@")) {
Slog.i(TAG, "Pruning dalvik file: " + fn);
(new File(dalvikCacheDir, fn)).delete();
}
}
}
pruneDexFiles(new File(dataDir, "dalvik-cache"));
}

// Collect vendor overlay packages.
Expand Down Expand Up @@ -1528,6 +1511,37 @@ public PackageManagerService(Context context, Installer installer,
} // synchronized (mInstallLock)
}

private static void pruneDexFiles(File cacheDir) {
// If we had to do a dexopt of one of the previous
// things, then something on the system has changed.
// Consider this significant, and wipe away all other
// existing dexopt files to ensure we don't leave any
// dangling around.
//
// Additionally, delete all dex files from the root directory
// since there shouldn't be any there anyway.
File[] files = cacheDir.listFiles();
if (files != null) {
for (File file : files) {
if (!file.isDirectory()) {
Slog.i(TAG, "Pruning dalvik file: " + file.getAbsolutePath());
file.delete();
} else {
File[] subDirList = file.listFiles();
if (subDirList != null) {
for (File subDirFile : subDirList) {
final String fn = subDirFile.getName();
if (fn.startsWith("data@app@") || fn.startsWith("data@app-private@")) {
Slog.i(TAG, "Pruning dalvik file: " + fn);
subDirFile.delete();
}
}
}
}
}
}
}

public boolean isFirstBoot() {
return !mRestoredSettings;
}
Expand Down

0 comments on commit 27f2bfc

Please sign in to comment.