Merge "Fix disabled WebView packages being shown as enabled in Dev Setting."
This commit is contained in:
committed by
Android (Google) Code Review
commit
9a8bae0838
@@ -35,8 +35,6 @@ public class DefaultAppInfo {
|
||||
public final ComponentName componentName;
|
||||
public final PackageItemInfo packageItemInfo;
|
||||
public final String summary;
|
||||
// Description for why this item is disabled, if null, the item is enabled.
|
||||
public final String disabledDescription;
|
||||
public final boolean enabled;
|
||||
|
||||
public DefaultAppInfo(int uid, ComponentName cn) {
|
||||
@@ -52,21 +50,19 @@ public class DefaultAppInfo {
|
||||
userId = uid;
|
||||
componentName = cn;
|
||||
this.summary = summary;
|
||||
this.disabledDescription = null;
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public DefaultAppInfo(PackageItemInfo info, String description) {
|
||||
public DefaultAppInfo(PackageItemInfo info, String summary, boolean enabled) {
|
||||
userId = UserHandle.myUserId();
|
||||
packageItemInfo = info;
|
||||
componentName = null;
|
||||
summary = null;
|
||||
this.disabledDescription = description;
|
||||
enabled = true;
|
||||
this.summary = summary;
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public DefaultAppInfo(PackageItemInfo info) {
|
||||
this(info, null);
|
||||
this(info, null /* summary */, true /* enabled */);
|
||||
}
|
||||
|
||||
public CharSequence loadLabel(PackageManager pm) {
|
||||
|
@@ -116,26 +116,9 @@ public abstract class DefaultAppPickerFragment extends InstrumentedPreferenceFra
|
||||
screen.addPreference(nonePref);
|
||||
}
|
||||
for (Map.Entry<String, DefaultAppInfo> app : mCandidates.entrySet()) {
|
||||
final RadioButtonPreference pref = new RadioButtonPreference(getPrefContext());
|
||||
final String appKey = app.getKey();
|
||||
final DefaultAppInfo info = app.getValue();
|
||||
pref.setTitle(info.loadLabel(mPm.getPackageManager()));
|
||||
pref.setIcon(info.loadIcon(mPm.getPackageManager()));
|
||||
pref.setKey(appKey);
|
||||
if (TextUtils.equals(defaultAppKey, appKey)) {
|
||||
pref.setChecked(true);
|
||||
}
|
||||
if (TextUtils.equals(systemDefaultAppKey, appKey)) {
|
||||
pref.setSummary(R.string.system_app);
|
||||
} else if (!TextUtils.isEmpty(info.summary)) {
|
||||
pref.setSummary(info.summary);
|
||||
}
|
||||
if (!TextUtils.isEmpty(app.getValue().disabledDescription)) {
|
||||
pref.setEnabled(false);
|
||||
pref.setSummary(app.getValue().disabledDescription);
|
||||
}
|
||||
pref.setEnabled(info.enabled);
|
||||
pref.setOnClickListener(this);
|
||||
RadioButtonPreference pref = new RadioButtonPreference(getPrefContext());
|
||||
configurePreferenceFromAppInfo(
|
||||
pref, app.getKey(), app.getValue(), defaultAppKey, systemDefaultAppKey);
|
||||
screen.addPreference(pref);
|
||||
}
|
||||
mayCheckOnlyRadioButton();
|
||||
@@ -259,4 +242,22 @@ public abstract class DefaultAppPickerFragment extends InstrumentedPreferenceFra
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public RadioButtonPreference configurePreferenceFromAppInfo(RadioButtonPreference pref,
|
||||
String appKey, DefaultAppInfo info, String defaultAppKey, String systemDefaultAppKey) {
|
||||
pref.setTitle(info.loadLabel(mPm.getPackageManager()));
|
||||
pref.setIcon(info.loadIcon(mPm.getPackageManager()));
|
||||
pref.setKey(appKey);
|
||||
if (TextUtils.equals(defaultAppKey, appKey)) {
|
||||
pref.setChecked(true);
|
||||
}
|
||||
if (TextUtils.equals(systemDefaultAppKey, appKey)) {
|
||||
pref.setSummary(R.string.system_app);
|
||||
} else if (!TextUtils.isEmpty(info.summary)) {
|
||||
pref.setSummary(info.summary);
|
||||
}
|
||||
pref.setEnabled(info.enabled);
|
||||
pref.setOnClickListener(this);
|
||||
return pref;
|
||||
}
|
||||
}
|
||||
|
@@ -24,6 +24,7 @@ import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
@@ -58,7 +59,7 @@ public class WebViewAppPicker extends DefaultAppPickerFragment {
|
||||
List<ApplicationInfo> pkgs =
|
||||
getWebViewUpdateServiceWrapper().getValidWebViewApplicationInfos(getContext());
|
||||
for (ApplicationInfo ai : pkgs) {
|
||||
packageInfoList.add(new DefaultAppInfo(ai,
|
||||
packageInfoList.add(createDefaultAppInfo(ai,
|
||||
getDisabledReason(getWebViewUpdateServiceWrapper(),
|
||||
getContext(), ai.packageName)));
|
||||
}
|
||||
@@ -92,7 +93,6 @@ public class WebViewAppPicker extends DefaultAppPickerFragment {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private WebViewUpdateServiceWrapper createDefaultWebViewUpdateServiceWrapper() {
|
||||
return new WebViewUpdateServiceWrapper();
|
||||
}
|
||||
@@ -107,6 +107,13 @@ public class WebViewAppPicker extends DefaultAppPickerFragment {
|
||||
return MetricsEvent.WEBVIEW_IMPLEMENTATION;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
DefaultAppInfo createDefaultAppInfo(
|
||||
ApplicationInfo applicationInfo, String disabledReason) {
|
||||
return new DefaultAppInfo(applicationInfo, disabledReason,
|
||||
TextUtils.isEmpty(disabledReason) /* enabled */);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the reason why a package cannot be used as WebView implementation.
|
||||
* This is either because of it being disabled, uninstalled, or hidden for any user.
|
||||
|
Reference in New Issue
Block a user