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

Commit e7a8a48f authored by Martin Stjernholm's avatar Martin Stjernholm Committed by Android (Google) Code Review
Browse files

Merge changes Ia612ce7f,Id49c3811

* changes:
  Use ART Service for package install compilation if enabled.
  Call into ART Service for profile snapshotting when it is enabled.
parents 5e04e6e0 acb6addd
Loading
Loading
Loading
Loading
+22 −7
Original line number Original line Diff line number Diff line
@@ -158,6 +158,8 @@ import com.android.internal.util.ArrayUtils;
import com.android.internal.util.CollectionUtils;
import com.android.internal.util.CollectionUtils;
import com.android.internal.util.FrameworkStatsLog;
import com.android.internal.util.FrameworkStatsLog;
import com.android.server.EventLogTags;
import com.android.server.EventLogTags;
import com.android.server.LocalManagerRegistry;
import com.android.server.art.model.DexoptParams;
import com.android.server.pm.Installer.LegacyDexoptDisabledException;
import com.android.server.pm.Installer.LegacyDexoptDisabledException;
import com.android.server.pm.dex.ArtManagerService;
import com.android.server.pm.dex.ArtManagerService;
import com.android.server.pm.dex.DexManager;
import com.android.server.pm.dex.DexManager;
@@ -2385,6 +2387,7 @@ final class InstallPackageHelper {
                            || installRequest.getInstallReason() == INSTALL_REASON_DEVICE_SETUP;
                            || installRequest.getInstallReason() == INSTALL_REASON_DEVICE_SETUP;


            final int dexoptFlags = DexoptOptions.DEXOPT_BOOT_COMPLETE
            final int dexoptFlags = DexoptOptions.DEXOPT_BOOT_COMPLETE
                    | DexoptOptions.DEXOPT_CHECK_FOR_PROFILES_UPDATES
                    | DexoptOptions.DEXOPT_INSTALL_WITH_DEX_METADATA_FILE
                    | DexoptOptions.DEXOPT_INSTALL_WITH_DEX_METADATA_FILE
                    | (isBackupOrRestore ? DexoptOptions.DEXOPT_FOR_RESTORE : 0);
                    | (isBackupOrRestore ? DexoptOptions.DEXOPT_FOR_RESTORE : 0);
            DexoptOptions dexoptOptions =
            DexoptOptions dexoptOptions =
@@ -2445,14 +2448,26 @@ final class InstallPackageHelper {


                realPkgSetting.getPkgState().setUpdatedSystemApp(isUpdatedSystemApp);
                realPkgSetting.getPkgState().setUpdatedSystemApp(isUpdatedSystemApp);


                // TODO(b/251903639): Call into ART Service.
                if (useArtService()) {
                    PackageManagerLocal packageManagerLocal =
                            LocalManagerRegistry.getManager(PackageManagerLocal.class);
                    try (PackageManagerLocal.FilteredSnapshot snapshot =
                                    packageManagerLocal.withFilteredSnapshot()) {
                        DexoptParams params =
                                dexoptOptions.convertToDexoptParams(0 /* extraFlags */);
                        DexOptHelper.getArtManagerLocal().dexoptPackage(
                                snapshot, packageName, params);
                    }
                } else {
                    try {
                    try {
                        mPackageDexOptimizer.performDexOpt(pkg, realPkgSetting,
                        mPackageDexOptimizer.performDexOpt(pkg, realPkgSetting,
                            null /* instructionSets */, mPm.getOrCreateCompilerPackageStats(pkg),
                                null /* instructionSets */,
                                mPm.getOrCreateCompilerPackageStats(pkg),
                                mDexManager.getPackageUseInfoOrDefault(packageName), dexoptOptions);
                                mDexManager.getPackageUseInfoOrDefault(packageName), dexoptOptions);
                    } catch (LegacyDexoptDisabledException e) {
                    } catch (LegacyDexoptDisabledException e) {
                        throw new RuntimeException(e);
                        throw new RuntimeException(e);
                    }
                    }
                }
                Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
                Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
            }
            }


+83 −36
Original line number Original line Diff line number Diff line
@@ -50,11 +50,15 @@ import com.android.internal.os.RoSystemProperties;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.Preconditions;
import com.android.internal.util.Preconditions;
import com.android.server.LocalServices;
import com.android.server.LocalServices;
import com.android.server.art.ArtManagerLocal;
import com.android.server.pm.DexOptHelper;
import com.android.server.pm.Installer;
import com.android.server.pm.Installer;
import com.android.server.pm.Installer.InstallerException;
import com.android.server.pm.Installer.InstallerException;
import com.android.server.pm.Installer.LegacyDexoptDisabledException;
import com.android.server.pm.Installer.LegacyDexoptDisabledException;
import com.android.server.pm.PackageManagerLocal;
import com.android.server.pm.PackageManagerService;
import com.android.server.pm.PackageManagerService;
import com.android.server.pm.PackageManagerServiceCompilerMapping;
import com.android.server.pm.PackageManagerServiceCompilerMapping;
import com.android.server.pm.PackageManagerServiceUtils;
import com.android.server.pm.parsing.PackageInfoUtils;
import com.android.server.pm.parsing.PackageInfoUtils;
import com.android.server.pm.pkg.AndroidPackage;
import com.android.server.pm.pkg.AndroidPackage;
import com.android.server.pm.pkg.PackageState;
import com.android.server.pm.pkg.PackageState;
@@ -210,20 +214,15 @@ public class ArtManagerService extends android.content.pm.dex.IArtManager.Stub {
            Slog.d(TAG, "Requested snapshot for " + packageName + ":" + codePath);
            Slog.d(TAG, "Requested snapshot for " + packageName + ":" + codePath);
        }
        }


        // TODO(b/251903639): Call into ART Service.
        try {
        if (bootImageProfile) {
        if (bootImageProfile) {
            snapshotBootImageProfile(callback);
            snapshotBootImageProfile(callback);
        } else {
        } else {
            snapshotAppProfile(packageName, codePath, callback);
            snapshotAppProfile(packageName, codePath, callback);
        }
        }
        } catch (LegacyDexoptDisabledException e) {
            throw new RuntimeException(e);
        }
    }
    }


    private void snapshotAppProfile(String packageName, String codePath,
    private void snapshotAppProfile(
            ISnapshotRuntimeProfileCallback callback) throws LegacyDexoptDisabledException {
            String packageName, String codePath, ISnapshotRuntimeProfileCallback callback) {
        PackageInfo info = null;
        PackageInfo info = null;
        try {
        try {
            // Note that we use the default user 0 to retrieve the package info.
            // Note that we use the default user 0 to retrieve the package info.
@@ -260,6 +259,29 @@ public class ArtManagerService extends android.content.pm.dex.IArtManager.Stub {
        }
        }


        // All good, create the profile snapshot.
        // All good, create the profile snapshot.
        if (DexOptHelper.useArtService()) {
            ParcelFileDescriptor fd;

            try (PackageManagerLocal.FilteredSnapshot snapshot =
                            PackageManagerServiceUtils.getPackageManagerLocal()
                                    .withFilteredSnapshot()) {
                fd = DexOptHelper.getArtManagerLocal().snapshotAppProfile(
                        snapshot, packageName, splitName);
            } catch (IllegalArgumentException e) {
                // ArtManagerLocal.snapshotAppProfile couldn't find the package or split. Since
                // we've checked them above this can only happen due to race, i.e. the package got
                // removed. So let's report it as SNAPSHOT_FAILED_PACKAGE_NOT_FOUND even if it was
                // for the split.
                // TODO(mast): Reuse the same snapshot to avoid this race.
                postError(callback, packageName, ArtManager.SNAPSHOT_FAILED_PACKAGE_NOT_FOUND);
                return;
            } catch (IllegalStateException | ArtManagerLocal.SnapshotProfileException e) {
                postError(callback, packageName, ArtManager.SNAPSHOT_FAILED_INTERNAL_ERROR);
                return;
            }

            postSuccess(packageName, fd, callback);
        } else {
            int appId = UserHandle.getAppId(info.applicationInfo.uid);
            int appId = UserHandle.getAppId(info.applicationInfo.uid);
            if (appId < 0) {
            if (appId < 0) {
                postError(callback, packageName, ArtManager.SNAPSHOT_FAILED_INTERNAL_ERROR);
                postError(callback, packageName, ArtManager.SNAPSHOT_FAILED_INTERNAL_ERROR);
@@ -267,10 +289,15 @@ public class ArtManagerService extends android.content.pm.dex.IArtManager.Stub {
                return;
                return;
            }
            }


            try {
                createProfileSnapshot(packageName, ArtManager.getProfileName(splitName), codePath,
                createProfileSnapshot(packageName, ArtManager.getProfileName(splitName), codePath,
                        appId, callback);
                        appId, callback);
                // Destroy the snapshot, we no longer need it.
                // Destroy the snapshot, we no longer need it.
                destroyProfileSnapshot(packageName, ArtManager.getProfileName(splitName));
                destroyProfileSnapshot(packageName, ArtManager.getProfileName(splitName));
            } catch (LegacyDexoptDisabledException e) {
                throw new RuntimeException(e);
            }
        }
    }
    }


    private void createProfileSnapshot(String packageName, String profileName, String classpath,
    private void createProfileSnapshot(String packageName, String profileName, String classpath,
@@ -340,23 +367,43 @@ public class ArtManagerService extends android.content.pm.dex.IArtManager.Stub {
        }
        }
    }
    }


    private void snapshotBootImageProfile(ISnapshotRuntimeProfileCallback callback)
    private void snapshotBootImageProfile(ISnapshotRuntimeProfileCallback callback) {
            throws LegacyDexoptDisabledException {
        if (DexOptHelper.useArtService()) {
            ParcelFileDescriptor fd;

            try (PackageManagerLocal.FilteredSnapshot snapshot =
                            PackageManagerServiceUtils.getPackageManagerLocal()
                                    .withFilteredSnapshot()) {
                fd = DexOptHelper.getArtManagerLocal().snapshotBootImageProfile(snapshot);
            } catch (IllegalStateException | ArtManagerLocal.SnapshotProfileException e) {
                postError(callback, BOOT_IMAGE_ANDROID_PACKAGE,
                        ArtManager.SNAPSHOT_FAILED_INTERNAL_ERROR);
                return;
            }

            postSuccess(BOOT_IMAGE_ANDROID_PACKAGE, fd, callback);
        } else {
            // Combine the profiles for boot classpath and system server classpath.
            // Combine the profiles for boot classpath and system server classpath.
            // This avoids having yet another type of profiles and simplifies the processing.
            // This avoids having yet another type of profiles and simplifies the processing.
        String classpath = String.join(":", Os.getenv("BOOTCLASSPATH"),
            String classpath = String.join(
                Os.getenv("SYSTEMSERVERCLASSPATH"));
                    ":", Os.getenv("BOOTCLASSPATH"), Os.getenv("SYSTEMSERVERCLASSPATH"));


            final String standaloneSystemServerJars = Os.getenv("STANDALONE_SYSTEMSERVER_JARS");
            final String standaloneSystemServerJars = Os.getenv("STANDALONE_SYSTEMSERVER_JARS");
            if (standaloneSystemServerJars != null) {
            if (standaloneSystemServerJars != null) {
                classpath = String.join(":", classpath, standaloneSystemServerJars);
                classpath = String.join(":", classpath, standaloneSystemServerJars);
            }
            }


            try {
                // Create the snapshot.
                // Create the snapshot.
        createProfileSnapshot(BOOT_IMAGE_ANDROID_PACKAGE, BOOT_IMAGE_PROFILE_NAME, classpath,
                createProfileSnapshot(BOOT_IMAGE_ANDROID_PACKAGE, BOOT_IMAGE_PROFILE_NAME,
                        classpath,
                        /*appId*/ -1, callback);
                        /*appId*/ -1, callback);
                // Destroy the snapshot, we no longer need it.
                // Destroy the snapshot, we no longer need it.
                destroyProfileSnapshot(BOOT_IMAGE_ANDROID_PACKAGE, BOOT_IMAGE_PROFILE_NAME);
                destroyProfileSnapshot(BOOT_IMAGE_ANDROID_PACKAGE, BOOT_IMAGE_PROFILE_NAME);
            } catch (LegacyDexoptDisabledException e) {
                throw new RuntimeException(e);
            }
        }
    }
    }


    /**
    /**