Commit 7cf54392 authored by Clark DuVall's avatar Clark DuVall Committed by Chromium LUCI CQ

Perform dex fixes when package is upgraded

This avoids users having a potentially slow startup after an update due
to invalid dex. See bugs for more details.

Bug: 1152970, 1159608
Change-Id: I897587b1b19ae6b9f4ba3dff23a598f9d3f58abe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2612088Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#840462}
parent 729b603c
......@@ -33,29 +33,29 @@ import org.chromium.chrome.browser.version.ChromeVersionInfo;
import java.io.File;
import java.io.IOException;
/**
* Performs work-arounds for Android bugs which result in invalid or unreadable dex.
*/
@RequiresApi(Build.VERSION_CODES.O)
class DexFixer {
public class DexFixer {
private static final String TAG = "DexFixer";
private static boolean sHasIsolatedSplits;
@WorkerThread
public static void fixDexInBackground() {
if (shouldSkipDexFix()) {
return;
}
fixDexIfNecessary(Runtime.getRuntime());
}
static void setHasIsolatedSplits(boolean value) {
sHasIsolatedSplits = value;
}
static void scheduleDexFix() {
ApplicationInfo appInfo = ContextUtils.getApplicationContext().getApplicationInfo();
// All bugs are fixed after Q.
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
return;
}
// Fixes are never required for system image installs, since we can trust those to be valid
// and world-readable.
if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
return;
}
// Skip the workaround on local builds to avoid affecting perf bots.
// https://bugs.chromium.org/p/chromium/issues/detail?id=1160070
if (ChromeVersionInfo.isLocalBuild() && ChromeVersionInfo.isOfficialBuild()) {
if (shouldSkipDexFix()) {
return;
}
......@@ -93,6 +93,25 @@ class DexFixer {
RecordHistogram.recordEnumeratedHistogram("Android.DexFixer", reason, DexFixerReason.COUNT);
}
private static boolean shouldSkipDexFix() {
ApplicationInfo appInfo = ContextUtils.getApplicationContext().getApplicationInfo();
// All bugs are fixed after Q.
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
return true;
}
// Fixes are never required for system image installs, since we can trust those to be valid
// and world-readable.
if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
return true;
}
// Skip the workaround on local builds to avoid affecting perf bots.
// https://bugs.chromium.org/p/chromium/issues/detail?id=1160070
if (ChromeVersionInfo.isLocalBuild() && ChromeVersionInfo.isOfficialBuild()) {
return true;
}
return false;
}
private static String odexPathFromApkPath(String apkPath) {
// Based on https://cs.android.com/search?q=OatFileAssistant::DexLocationToOdexNames
boolean is64Bit = ApiHelperForM.isProcess64Bit();
......
......@@ -7,10 +7,12 @@ package org.chromium.chrome.browser.upgrade;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import org.chromium.base.task.PostTask;
import org.chromium.base.task.TaskTraits;
import org.chromium.chrome.browser.autofill_assistant.AutofillAssistantModuleEntryProvider;
import org.chromium.chrome.browser.base.DexFixer;
import org.chromium.chrome.browser.notifications.channels.ChannelsUpdater;
import org.chromium.chrome.browser.vr.VrModuleProvider;
......@@ -32,16 +34,18 @@ public final class PackageReplacedBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, Intent intent) {
if (!Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) return;
updateChannelsIfNecessary();
VrModuleProvider.maybeRequestModuleIfDaydreamReady();
AutofillAssistantModuleEntryProvider.maybeInstallDeferred();
}
private void updateChannelsIfNecessary() {
if (!ChannelsUpdater.getInstance().shouldUpdateChannels()) return;
final PendingResult result = goAsync();
PostTask.postTask(TaskTraits.BEST_EFFORT_MAY_BLOCK, () -> {
ChannelsUpdater.getInstance().updateChannels();
if (ChannelsUpdater.getInstance().shouldUpdateChannels()) {
ChannelsUpdater.getInstance().updateChannels();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
DexFixer.fixDexInBackground();
}
result.finish();
});
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment