From 29528cf2155c4292f3e00e620d18e774adfd84de Mon Sep 17 00:00:00 2001 From: Martin Stjernholm Date: Tue, 21 Feb 2023 01:10:42 +0000 Subject: [PATCH] Dexopt the launcher(s) after a Mainline update. For consistency with commit 296bff69ead68553800eff41fa30d49654b32d78 in art/. Test: adb install com.google.android.art.apex adb reboot and check logcat that com.android.systemui and com.google.android.apps.nexuslauncher get passed down to PackageDexOptimizer.dexOptPath with "verify" and "speed-profile", respectively. Bug: 269140736 Bug: 251903639 Change-Id: I3b0294fcd93c7d61789e5caa1141cad8070d0838 --- .../com/android/server/pm/DexOptHelper.java | 38 +++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/services/core/java/com/android/server/pm/DexOptHelper.java b/services/core/java/com/android/server/pm/DexOptHelper.java index 1bd5b9962436a..0fd81ac0bc415 100644 --- a/services/core/java/com/android/server/pm/DexOptHelper.java +++ b/services/core/java/com/android/server/pm/DexOptHelper.java @@ -40,6 +40,7 @@ import static dalvik.system.DexFile.isProfileGuidedCompilerFilter; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.AppGlobals; +import android.app.role.RoleManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -272,7 +273,6 @@ public final class DexOptHelper { * compiles it if needed. */ private void checkAndDexOptSystemUi(int reason) throws LegacyDexoptDisabledException { - Installer.checkLegacyDexoptDisabled(); Computer snapshot = mPm.snapshotComputer(); String sysUiPackageName = mPm.mContext.getString(com.android.internal.R.string.config_systemUi); @@ -288,7 +288,7 @@ public final class DexOptHelper { String compilerFilter; if (isProfileGuidedCompilerFilter(targetCompilerFilter)) { - compilerFilter = defaultCompilerFilter; + compilerFilter = "verify"; File profileFile = new File(getPrebuildProfilePath(pkg)); // Copy the profile to the reference profile path if it exists. Installd can only use a @@ -312,7 +312,26 @@ public final class DexOptHelper { compilerFilter = targetCompilerFilter; } - // We don't expect updates in current profiles to be significant here, but + performDexoptPackage(sysUiPackageName, reason, compilerFilter); + } + + private void dexoptLauncher(int reason) throws LegacyDexoptDisabledException { + Computer snapshot = mPm.snapshotComputer(); + RoleManager roleManager = mPm.mContext.getSystemService(RoleManager.class); + for (var packageName : roleManager.getRoleHolders(RoleManager.ROLE_HOME)) { + AndroidPackage pkg = snapshot.getPackage(packageName); + if (pkg == null) { + Log.w(TAG, "Launcher package " + packageName + " is not found for dexopting"); + } else { + performDexoptPackage(packageName, reason, "speed-profile"); + } + } + } + + private void performDexoptPackage(@NonNull String packageName, int reason, + @NonNull String compilerFilter) throws LegacyDexoptDisabledException { + Installer.checkLegacyDexoptDisabled(); + // DEXOPT_CHECK_FOR_PROFILES_UPDATES is set to replicate behaviour that will be // unconditionally enabled for profile guided filters when ART Service is called instead of // the legacy PackageDexOptimizer implementation. @@ -320,8 +339,8 @@ public final class DexOptHelper { ? DexoptOptions.DEXOPT_CHECK_FOR_PROFILES_UPDATES : 0; - performDexOptTraced(new DexoptOptions(pkg.getPackageName(), REASON_BOOT_AFTER_OTA, - compilerFilter, null /* splitName */, dexoptFlags)); + performDexOptTraced(new DexoptOptions( + packageName, reason, compilerFilter, null /* splitName */, dexoptFlags)); } /** @@ -343,6 +362,10 @@ public final class DexOptHelper { return; } + Log.i(TAG, + "Starting boot dexopt for reason " + + DexoptOptions.convertToArtServiceDexoptReason(reason)); + final long startTime = System.nanoTime(); if (useArtService()) { @@ -351,9 +374,10 @@ public final class DexOptHelper { null /* progressCallbackExecutor */, null /* progressCallback */); } else { try { - // System UI is important to user experience, so we check it after a mainline update - // or an OTA. It may need to be re-compiled in these cases. + // System UI and the launcher are important to user experience, so we check them + // after a mainline update or OTA. They may need to be re-compiled in these cases. checkAndDexOptSystemUi(reason); + dexoptLauncher(reason); if (reason != REASON_BOOT_AFTER_OTA && reason != REASON_FIRST_BOOT) { return;