Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b2963f33 authored by Calin Juravle's avatar Calin Juravle Committed by android-build-merger
Browse files

Merge "Change the location of current profiles for secondary dex files" into oc-mr1-dev

am: 284b5844

Change-Id: Ib8f8156b0610dc7aaf892c1d049c94232938a565
parents a9adf37e 284b5844
Loading
Loading
Loading
Loading
+38 −14
Original line number Diff line number Diff line
@@ -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 {
            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");
    }
}