Commit 3ec6d4de authored by Andrew Grieve's avatar Andrew Grieve Committed by Chromium LUCI CQ

Android: Report fake crashes for DexFixer failures

UMA currently shows that:
  Os.stat() fails .14% of the time
  Runtime.exec() fails 0.02%

I suspect the heuristic for where the .odex files live might be wrong
for some small portion of devices, so would like to collect these
crashes.

Bug: 1152970
Change-Id: I98d1a14ae670bb1be04de6a4564001b65a67a1a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2624808Reviewed-by: default avatarClark DuVall <cduvall@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842563}
parent 7965f6d1
......@@ -18,6 +18,7 @@ import dalvik.system.DexFile;
import org.chromium.base.BuildConfig;
import org.chromium.base.BuildInfo;
import org.chromium.base.ContextUtils;
import org.chromium.base.JavaExceptionReporter;
import org.chromium.base.Log;
import org.chromium.base.compat.ApiHelperForM;
import org.chromium.base.compat.ApiHelperForO;
......@@ -29,6 +30,7 @@ import org.chromium.chrome.browser.DeferredStartupHandler;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.chrome.browser.version.ChromeVersionInfo;
import org.chromium.content_public.browser.UiThreadTaskTraits;
import java.io.File;
import java.io.IOException;
......@@ -41,6 +43,12 @@ public class DexFixer {
private static final String TAG = "DexFixer";
private static boolean sHasIsolatedSplits;
private static class DexFixerException extends Exception {
DexFixerException(String reason, Throwable causedBy) {
super(reason, causedBy);
}
}
@WorkerThread
public static void fixDexInBackground() {
if (shouldSkipDexFix()) {
......@@ -77,16 +85,23 @@ public class DexFixer {
int reason = needsDexCompile(appInfo);
if (reason > DexFixerReason.NOT_NEEDED) {
Log.w(TAG, "Triggering dex compile. Reason=%d", reason);
String cmd = "cmd package compile -r shared ";
if (reason == DexFixerReason.NOT_READABLE && BuildConfig.ISOLATED_SPLITS_ENABLED) {
// Isolated processes need only access the base split.
String apkBaseName = new File(appInfo.sourceDir).getName();
cmd += String.format("--split %s ", apkBaseName);
}
cmd += ContextUtils.getApplicationContext().getPackageName();
try {
String cmd = "cmd package compile -r shared ";
if (reason == DexFixerReason.NOT_READABLE && BuildConfig.ISOLATED_SPLITS_ENABLED) {
// Isolated processes need only access the base split.
String apkBaseName = new File(appInfo.sourceDir).getName();
cmd += String.format("--split %s ", apkBaseName);
}
cmd += ContextUtils.getApplicationContext().getPackageName();
runtime.exec(cmd);
} catch (IOException e) {
DexFixerException dfException =
new DexFixerException(String.format("Reason: %s Name: %s", reason,
new File(appInfo.sourceDir).getName()),
e);
// TODO(agrieve): Remove reportException() once some data is collected.
PostTask.postTask(UiThreadTaskTraits.BEST_EFFORT,
() -> JavaExceptionReporter.reportException(dfException));
reason = DexFixerReason.FAILED_TO_RUN;
}
}
......@@ -174,6 +189,11 @@ public class DexFixer {
return DexFixerReason.NOT_READABLE;
}
} catch (ErrnoException e) {
// TODO(agrieve): Remove reportException() once some data is collected.
DexFixerException dfException = new DexFixerException(
String.format("Path: %s exists: %s", oatPath, new File(oatPath).exists()), e);
PostTask.postTask(UiThreadTaskTraits.BEST_EFFORT,
() -> JavaExceptionReporter.reportException(dfException));
return DexFixerReason.STAT_FAILED;
}
return DexFixerReason.NOT_NEEDED;
......
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