Commit 8cf48c92 authored by Nate Fischer's avatar Nate Fischer Committed by Commit Bot

AW: use user-friendly app label in error UI

This swaps out the app package name for the application "label" (the
user-friendly name for the app) and the version number (to disambiguate
between similarly-named apps). This is for consistency with the system's
webview chooser dialog (which the user is likely to go into next by
clicking the dialog button).

Fixed: 1040336
Test: manual - click icon when this is not the current provider
Change-Id: Iacb73cd2f0ca41844f2ff668230b3b95bb4ed472
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1991745Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#729813}
parent d3c8f507
......@@ -8,7 +8,9 @@ import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Build;
import android.provider.Settings;
......@@ -39,7 +41,7 @@ public class WebViewPackageError {
public WebViewPackageError(Activity context, LinearLayout linearLayout) {
mContext = context;
mErrorDialog = buildDifferentPackageErrorDialog(mContext.getPackageName());
mErrorDialog = buildDifferentPackageErrorDialog();
mErrorMessage = new PersistentErrorView(context, PersistentErrorView.Type.WARNING)
.prependToLinearLayout(linearLayout)
.setText("Warning: different WebView provider - Tap for more info.")
......@@ -78,12 +80,30 @@ public class WebViewPackageError {
return !mContext.getPackageName().equals(systemWebViewPackage.packageName);
}
private Dialog buildDifferentPackageErrorDialog(String currentWebViewPackage) {
/**
* Loads a label for the app specified by {@code mContext}. This is designed to be consistent
* with how the system's WebView chooser labels WebView packages (see {@code
* com.android.settings.webview.WebViewAppPicker.WebViewAppInfo#loadLabel()} in the AOSP source
* code).
*/
private CharSequence loadLabel() {
ApplicationInfo applicationInfo = mContext.getApplicationInfo();
PackageManager pm = mContext.getPackageManager();
CharSequence appLabel = applicationInfo.loadLabel(pm);
try {
String versionName = pm.getPackageInfo(mContext.getPackageName(), 0).versionName;
return String.format(Locale.US, "%s %s", appLabel, versionName);
} catch (PackageManager.NameNotFoundException e) {
return appLabel;
}
}
private Dialog buildDifferentPackageErrorDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setTitle("Wrong WebView DevTools")
.setMessage(String.format(Locale.US,
"This app (%s) is not the selected system's WebView provider.",
currentWebViewPackage));
loadLabel()));
builder.setPositiveButton("Open the current WebView provider", (dialog, id) -> {
PackageInfo systemWebViewPackage =
WebViewPackageHelper.getCurrentWebViewPackage(mContext);
......
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