diff options
| author | 2017-07-27 16:05:25 -0700 | |
|---|---|---|
| committer | 2017-08-04 17:14:22 -0700 | |
| commit | eec18f41e2ecbdf95dab6584e72a64f827bb89f7 (patch) | |
| tree | 58727b89d16534318bf4ce1332cd75b02c92e09b | |
| parent | 39a9832df127bad58581f95b0476be93a2c70d4a (diff) | |
Change the location of current profiles for secondary dex files
Move the secondary dex profiles inside the oat folder. This makes it
easier to clean them up and "protects" them against apps which may delete
unknown files from their directories (e.g. search).
Bug: 62336157
Test: Manual: boot the device, use the app, check the profiles are
collected in the new location.
Change-Id: I2fbce7591589d162775e4652b12e4698083adcff
| -rw-r--r-- | core/java/android/app/DexLoadReporter.java | 52 |
1 files changed, 38 insertions, 14 deletions
diff --git a/core/java/android/app/DexLoadReporter.java b/core/java/android/app/DexLoadReporter.java index 371cd127bd5e..f99d1a8e06a4 100644 --- a/core/java/android/app/DexLoadReporter.java +++ b/core/java/android/app/DexLoadReporter.java @@ -19,6 +19,7 @@ package android.app; import android.os.FileUtils; import android.os.RemoteException; import android.os.SystemProperties; +import android.system.ErrnoException; import android.util.Slog; import com.android.internal.annotations.GuardedBy; @@ -26,6 +27,8 @@ import com.android.internal.annotations.GuardedBy; import dalvik.system.BaseDexClassLoader; import dalvik.system.VMRuntime; +import libcore.io.Libcore; + import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -151,22 +154,50 @@ import java.util.Set; // The dex path is not a secondary dex file. Nothing to do. return; } - File secondaryProfile = getSecondaryProfileFile(dexPath); + + File realDexPath; + try { + // Secondary dex profiles are stored in the oat directory, next to the real dex file + // and have the same name with 'cur.prof' appended. We use the realpath because that + // is what installd is using when processing the dex file. + // NOTE: Keep in sync with installd. + realDexPath = new File(Libcore.os.realpath(dexPath)); + } catch (ErrnoException ex) { + Slog.e(TAG, "Failed to get the real path of secondary dex " + dexPath + + ":" + ex.getMessage()); + // Do not continue with registration if we could not retrieve the real path. + return; + } + + // NOTE: Keep this in sync with installd expectations. + File secondaryProfileDir = new File(realDexPath.getParent(), "oat"); + File secondaryProfile = new File(secondaryProfileDir, realDexPath.getName() + ".cur.prof"); + + // Create the profile if not already there. + // Returns true if the file was created, false if the file already exists. + // or throws exceptions in case of errors. + if (!secondaryProfileDir.exists()) { + if (!secondaryProfileDir.mkdir()) { + Slog.e(TAG, "Could not create the profile directory: " + secondaryProfile); + // Do not continue with registration if we could not create the oat dir. + return; + } + } + try { - // Create the profile if not already there. - // Returns true if the file was created, false if the file already exists. - // or throws exceptions in case of errors. boolean created = secondaryProfile.createNewFile(); if (DEBUG && created) { Slog.i(TAG, "Created profile for secondary dex: " + secondaryProfile); } } catch (IOException ex) { - Slog.e(TAG, "Failed to create profile for secondary dex " + secondaryProfile + - ":" + ex.getMessage()); - // Don't move forward with the registration if we failed to create the profile. + Slog.e(TAG, "Failed to create profile for secondary dex " + dexPath + + ":" + ex.getMessage()); + // Do not continue with registration if we could not create the profile files. return; } + // If we got here, the dex paths is a secondary dex and we were able to create the profile. + // Register the path to the runtime. VMRuntime.registerAppInfo(secondaryProfile.getPath(), new String[] { dexPath }); } @@ -180,11 +211,4 @@ import java.util.Set; } return false; } - - // Secondary dex profiles are stored next to the dex file and have the same - // name with '.prof' appended. - // NOTE: Keep in sync with installd. - private File getSecondaryProfileFile(String dexPath) { - return new File(dexPath + ".prof"); - } } |