Loading services/core/java/com/android/server/pm/DexOptHelper.java +67 −0 Original line number Diff line number Diff line Loading @@ -26,10 +26,13 @@ import static com.android.server.pm.PackageManagerService.REASON_CMDLINE; import static com.android.server.pm.PackageManagerService.REASON_FIRST_BOOT; import static com.android.server.pm.PackageManagerService.STUB_SUFFIX; import static com.android.server.pm.PackageManagerService.TAG; import static com.android.server.pm.PackageManagerServiceCompilerMapping.getCompilerFilterForReason; import static com.android.server.pm.PackageManagerServiceCompilerMapping.getDefaultCompilerFilter; import static com.android.server.pm.PackageManagerServiceUtils.REMOVE_IF_NULL_PKG; import android.Manifest; import android.annotation.NonNull; import android.annotation.RequiresPermission; import android.app.ActivityManager; import android.app.AppGlobals; import android.content.Intent; Loading @@ -42,6 +45,7 @@ import android.os.SystemClock; import android.os.SystemProperties; import android.os.Trace; import android.os.UserHandle; import android.provider.DeviceConfig; import android.util.ArraySet; import android.util.Log; import android.util.Slog; Loading @@ -55,6 +59,8 @@ import com.android.server.pm.parsing.pkg.AndroidPackage; import com.android.server.pm.parsing.pkg.AndroidPackageUtils; import com.android.server.pm.pkg.PackageStateInternal; import dalvik.system.DexFile; import java.io.File; import java.util.ArrayList; import java.util.Collection; Loading Loading @@ -250,10 +256,71 @@ final class DexOptHelper { numberOfPackagesFailed}; } /** * Checks if system UI package (typically "com.android.systemui") needs to be re-compiled, and * compiles it if needed. */ private void checkAndDexOptSystemUi() { Computer snapshot = mPm.snapshotComputer(); String sysUiPackageName = mPm.mContext.getString(com.android.internal.R.string.config_systemUi); AndroidPackage pkg = snapshot.getPackage(sysUiPackageName); if (pkg == null) { Log.w(TAG, "System UI package " + sysUiPackageName + " is not found for dexopting"); return; } // It could also be after mainline update, but we're not introducing a new reason just for // this special case. int reason = REASON_BOOT_AFTER_OTA; String defaultCompilerFilter = getCompilerFilterForReason(reason); String targetCompilerFilter = SystemProperties.get("dalvik.vm.systemuicompilerfilter", defaultCompilerFilter); String compilerFilter; if (DexFile.isProfileGuidedCompilerFilter(targetCompilerFilter)) { compilerFilter = defaultCompilerFilter; File profileFile = new File(getPrebuildProfilePath(pkg)); // Copy the profile to the reference profile path if it exists. Installd can only use a // profile at the reference profile path for dexopt. if (profileFile.exists()) { try { synchronized (mPm.mInstallLock) { if (mPm.mInstaller.copySystemProfile(profileFile.getAbsolutePath(), pkg.getUid(), pkg.getPackageName(), ArtManager.getProfileName(null))) { compilerFilter = targetCompilerFilter; } else { Log.e(TAG, "Failed to copy profile " + profileFile.getAbsolutePath()); } } } catch (Exception e) { Log.e(TAG, "Failed to copy profile " + profileFile.getAbsolutePath(), e); } } } else { compilerFilter = targetCompilerFilter; } performDexOptTraced(new DexoptOptions(pkg.getPackageName(), REASON_BOOT_AFTER_OTA, compilerFilter, null /* splitName */, 0 /* dexoptFlags */)); } @RequiresPermission(Manifest.permission.READ_DEVICE_CONFIG) public void performPackageDexOptUpgradeIfNeeded() { PackageManagerServiceUtils.enforceSystemOrRoot( "Only the system can request package update"); // The default is "true". if (!"false".equals(DeviceConfig.getProperty("runtime", "dexopt_system_ui_on_boot"))) { // System UI is important to user experience, so we check it on every boot. It may need // to be re-compiled after a mainline update or an OTA. // TODO(b/227310505): Only do this after a mainline update or an OTA. checkAndDexOptSystemUi(); } // We need to re-extract after an OTA. boolean causeUpgrade = mPm.isDeviceUpgrading(); Loading Loading
services/core/java/com/android/server/pm/DexOptHelper.java +67 −0 Original line number Diff line number Diff line Loading @@ -26,10 +26,13 @@ import static com.android.server.pm.PackageManagerService.REASON_CMDLINE; import static com.android.server.pm.PackageManagerService.REASON_FIRST_BOOT; import static com.android.server.pm.PackageManagerService.STUB_SUFFIX; import static com.android.server.pm.PackageManagerService.TAG; import static com.android.server.pm.PackageManagerServiceCompilerMapping.getCompilerFilterForReason; import static com.android.server.pm.PackageManagerServiceCompilerMapping.getDefaultCompilerFilter; import static com.android.server.pm.PackageManagerServiceUtils.REMOVE_IF_NULL_PKG; import android.Manifest; import android.annotation.NonNull; import android.annotation.RequiresPermission; import android.app.ActivityManager; import android.app.AppGlobals; import android.content.Intent; Loading @@ -42,6 +45,7 @@ import android.os.SystemClock; import android.os.SystemProperties; import android.os.Trace; import android.os.UserHandle; import android.provider.DeviceConfig; import android.util.ArraySet; import android.util.Log; import android.util.Slog; Loading @@ -55,6 +59,8 @@ import com.android.server.pm.parsing.pkg.AndroidPackage; import com.android.server.pm.parsing.pkg.AndroidPackageUtils; import com.android.server.pm.pkg.PackageStateInternal; import dalvik.system.DexFile; import java.io.File; import java.util.ArrayList; import java.util.Collection; Loading Loading @@ -250,10 +256,71 @@ final class DexOptHelper { numberOfPackagesFailed}; } /** * Checks if system UI package (typically "com.android.systemui") needs to be re-compiled, and * compiles it if needed. */ private void checkAndDexOptSystemUi() { Computer snapshot = mPm.snapshotComputer(); String sysUiPackageName = mPm.mContext.getString(com.android.internal.R.string.config_systemUi); AndroidPackage pkg = snapshot.getPackage(sysUiPackageName); if (pkg == null) { Log.w(TAG, "System UI package " + sysUiPackageName + " is not found for dexopting"); return; } // It could also be after mainline update, but we're not introducing a new reason just for // this special case. int reason = REASON_BOOT_AFTER_OTA; String defaultCompilerFilter = getCompilerFilterForReason(reason); String targetCompilerFilter = SystemProperties.get("dalvik.vm.systemuicompilerfilter", defaultCompilerFilter); String compilerFilter; if (DexFile.isProfileGuidedCompilerFilter(targetCompilerFilter)) { compilerFilter = defaultCompilerFilter; File profileFile = new File(getPrebuildProfilePath(pkg)); // Copy the profile to the reference profile path if it exists. Installd can only use a // profile at the reference profile path for dexopt. if (profileFile.exists()) { try { synchronized (mPm.mInstallLock) { if (mPm.mInstaller.copySystemProfile(profileFile.getAbsolutePath(), pkg.getUid(), pkg.getPackageName(), ArtManager.getProfileName(null))) { compilerFilter = targetCompilerFilter; } else { Log.e(TAG, "Failed to copy profile " + profileFile.getAbsolutePath()); } } } catch (Exception e) { Log.e(TAG, "Failed to copy profile " + profileFile.getAbsolutePath(), e); } } } else { compilerFilter = targetCompilerFilter; } performDexOptTraced(new DexoptOptions(pkg.getPackageName(), REASON_BOOT_AFTER_OTA, compilerFilter, null /* splitName */, 0 /* dexoptFlags */)); } @RequiresPermission(Manifest.permission.READ_DEVICE_CONFIG) public void performPackageDexOptUpgradeIfNeeded() { PackageManagerServiceUtils.enforceSystemOrRoot( "Only the system can request package update"); // The default is "true". if (!"false".equals(DeviceConfig.getProperty("runtime", "dexopt_system_ui_on_boot"))) { // System UI is important to user experience, so we check it on every boot. It may need // to be re-compiled after a mainline update or an OTA. // TODO(b/227310505): Only do this after a mainline update or an OTA. checkAndDexOptSystemUi(); } // We need to re-extract after an OTA. boolean causeUpgrade = mPm.isDeviceUpgrading(); Loading