Commit 58ad4f28 authored by Hazem Ashmawy's avatar Hazem Ashmawy Committed by Commit Bot

[Aw] DevUI: Show error if the user haven't opted into crash collection

Show a persistent error message if the user hasn't opted into crash
collection:
- If "--enable-crash-reporter-for-testing" flag isn't enabled.
- AND GMS "Usage & Metrics" collection is not enabled.

The UI has to be relaunched in order to update the error status.

Bug: 1014825
Test: Check the error after with --enable-crash-reporter-for-testing flag on/off on upstream and downstream SystemWebView
Test: Check the error after switching GMS "usage & diagnostics" settings on/off on downstream webview
Change-Id: Idc1a74579cef267612bb5c5804f5b988c8c44c5d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1914394
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Reviewed-by: default avatarNate Fischer <ntfschr@chromium.org>
Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Auto-Submit: Hazem Ashmawy <hazems@chromium.org>
Cr-Commit-Position: refs/heads/master@{#717223}
parent 38bb1c0a
......@@ -52,8 +52,10 @@ android_library("devui_java") {
deps = [
":devui_resources",
":system_webview_manifest",
"//android_webview:common_commandline_java",
"//android_webview:common_crash_java",
"//android_webview:common_java",
"//android_webview:common_platform_services_java",
"//base:base_java",
"//components/minidump_uploader:minidump_uploader_java",
"//third_party/android_deps:androidx_annotation_annotation_java",
......
......@@ -5,8 +5,10 @@
package org.chromium.android_webview.devui;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
......@@ -23,10 +25,14 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.chromium.android_webview.common.CommandLineUtil;
import org.chromium.android_webview.common.PlatformServiceBridge;
import org.chromium.android_webview.common.crash.CrashInfo;
import org.chromium.android_webview.common.crash.CrashInfo.UploadState;
import org.chromium.android_webview.devui.util.NavigationMenuHelper;
import org.chromium.android_webview.devui.util.WebViewCrashInfoCollector;
import org.chromium.base.CommandLine;
import org.chromium.base.Log;
import java.util.Date;
import java.util.List;
......@@ -36,6 +42,8 @@ import java.util.Locale;
* An activity to show a list of recent WebView crashes.
*/
public class CrashesListActivity extends Activity {
private static final String TAG = "WebViewDevTools";
// Max number of crashes to show in the crashes list.
private static final int MAX_CRASHES_NUMBER = 20;
......@@ -97,6 +105,17 @@ public class CrashesListActivity extends Activity {
new WebViewPackageError(this, findViewById(R.id.crashes_list_activity_layout));
// show the dialog once when the activity is created.
mDifferentPackageError.showDialogIfDifferent();
final boolean enableMinidumpUploadingForTesting = CommandLine.getInstance().hasSwitch(
CommandLineUtil.CRASH_UPLOADS_ENABLED_FOR_TESTING_SWITCH);
if (!enableMinidumpUploadingForTesting) {
PlatformServiceBridge.getInstance().queryMetricsSetting(enabled -> {
// enabled is a Boolean object and can be null.
if (!Boolean.TRUE.equals(enabled)) {
showCrashConsentError(PlatformServiceBridge.getInstance().canUseGms());
}
});
}
}
@Override
......@@ -297,6 +316,36 @@ public class CrashesListActivity extends Activity {
String.format(Locale.US, "Crashes (%d)", mCrashInfoList.size()));
}
private void showCrashConsentError(boolean canUseGms) {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
dialogBuilder.setTitle("Error Showing Crashes");
if (canUseGms) {
dialogBuilder.setMessage(
"Crash collection is disabled. Please turn on 'Usage & diagnostics' "
+ "to enable WebView crash collection.");
// Open Google Settings activity, "Usage & diagnostics" activity is not exported and
// cannot be opened directly.
Intent settingsIntent = new Intent("com.android.settings.action.EXTRA_SETTINGS");
List<ResolveInfo> intentResolveInfo =
getPackageManager().queryIntentActivities(settingsIntent, 0);
// Show a button to open GMS settings activity only if it exists.
if (intentResolveInfo.size() > 0) {
dialogBuilder.setPositiveButton(
"Settings", (dialog, id) -> startActivity(settingsIntent));
} else {
Log.e(TAG, "Cannot find GMS settings activity");
}
} else {
dialogBuilder.setMessage("Crash collection is not supported at the moment.");
}
new PersistentErrorView(this, PersistentErrorView.Type.ERROR)
.prependToLinearLayout(findViewById(R.id.crashes_list_activity_layout))
.setText("Crash collection is disabled. Tap for more info.")
.setDialog(dialogBuilder.create())
.show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.crashes_options_menu, menu);
......
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