Use a simulated code-cache for storing extracted files.
This should allow an automatic cleaning when updating to L without having to
check at each launch.
Bug: 10447095
Change-Id: I3c0ecc1430ced4592f630ec4c6d8a1a2219e8141
diff --git a/library/src/android/support/multidex/MultiDex.java b/library/src/android/support/multidex/MultiDex.java
index 68462c2..8d5e1ab 100644
--- a/library/src/android/support/multidex/MultiDex.java
+++ b/library/src/android/support/multidex/MultiDex.java
@@ -58,7 +58,10 @@
static final String TAG = "MultiDex";
- private static final String SECONDARY_FOLDER_NAME = "secondary-dexes";
+ private static final String OLD_SECONDARY_FOLDER_NAME = "secondary-dexes";
+
+ private static final String SECONDARY_FOLDER_NAME = "code_cache" + File.separator +
+ "secondary-dexes";
private static final int MAX_SUPPORTED_SDK_VERSION = 20;
@@ -89,12 +92,6 @@
Log.i(TAG, "install");
if (IS_VM_MULTIDEX_CAPABLE) {
Log.i(TAG, "VM has multidex support, MultiDex support library is disabled.");
- try {
- clearOldDexDir(context);
- } catch (Throwable t) {
- Log.w(TAG, "Something went wrong when trying to clear old MultiDex extraction, "
- + "continuing without cleaning.", t);
- }
return;
}
@@ -151,7 +148,14 @@
return;
}
- File dexDir = new File(context.getFilesDir(), SECONDARY_FOLDER_NAME);
+ try {
+ clearOldDexDir(context);
+ } catch (Throwable t) {
+ Log.w(TAG, "Something went wrong when trying to clear old MultiDex extraction, "
+ + "continuing without cleaning.", t);
+ }
+
+ File dexDir = new File(applicationInfo.dataDir, SECONDARY_FOLDER_NAME);
List<File> files = MultiDexExtractor.load(context, applicationInfo, dexDir, false);
if (checkValidZipFiles(files)) {
installSecondaryDexes(loader, dexDir, files);
@@ -334,20 +338,7 @@
}
private static void clearOldDexDir(Context context) throws Exception {
- ApplicationInfo applicationInfo = getApplicationInfo(context);
- if (applicationInfo == null) {
- // Looks like running on a test Context, so just return.
- return;
- }
-
- synchronized (installedApk) {
- String apkPath = applicationInfo.sourceDir;
- if (installedApk.contains(apkPath)) {
- return;
- }
- installedApk.add(apkPath);
- }
- File dexDir = new File(context.getFilesDir(), SECONDARY_FOLDER_NAME);
+ File dexDir = new File(context.getFilesDir(), OLD_SECONDARY_FOLDER_NAME);
if (dexDir.isDirectory()) {
Log.i(TAG, "Clearing old secondary dex dir (" + dexDir.getPath() + ").");
File[] files = dexDir.listFiles();