Have WebView Implementation Dev Setting use DefaultAppPickerFragment.
Make the WebView Implementation Dev Setting look like the fullscreen settings deriving from DefaultAppPickerFragment. Point the Activity opened through Settings.ACTION_WEBVIEW_SETTINGS to the class WebViewAppPicker which is our new implementation of the WebView Implementation setting. Ensure the new setting closes if it is reached from a user that isn't an admin of the device. Bug: 34806477 Bug: 34966439 Test: Ensure WebView implementation Dev Setting looks ok (disabled packages should have a text showing why they cannot be chosen). Test: Start Intent with action Settings.ACTION_WEBVIEW_SETTINGS and ensure the started Activity looks similar to the WebView Implementation Dev Setting. Test: Ensure picking a package that is no longer active, updates the setting (so that package isn't visible anymore). Change-Id: I08007c515193739ad61dfd735bb5130fc07bd6e6
This commit is contained in:
@@ -91,6 +91,11 @@ public abstract class DefaultAppPickerFragment extends InstrumentedPreferenceFra
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
super.onCreatePreferences(savedInstanceState, rootKey);
|
||||
addPreferencesFromResource(R.xml.app_picker_prefs);
|
||||
updateCandidates();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void updateCandidates() {
|
||||
mCandidates.clear();
|
||||
final List<DefaultAppInfo> candidateList = getCandidates();
|
||||
if (candidateList != null) {
|
||||
@@ -123,6 +128,10 @@ public abstract class DefaultAppPickerFragment extends InstrumentedPreferenceFra
|
||||
if (TextUtils.equals(systemDefaultAppKey, appKey)) {
|
||||
pref.setSummary(R.string.system_app);
|
||||
}
|
||||
if (!TextUtils.isEmpty(app.getValue().disabledDescription)) {
|
||||
pref.setEnabled(false);
|
||||
pref.setSummary(app.getValue().disabledDescription);
|
||||
}
|
||||
pref.setOnClickListener(this);
|
||||
screen.addPreference(pref);
|
||||
}
|
||||
@@ -145,18 +154,23 @@ public abstract class DefaultAppPickerFragment extends InstrumentedPreferenceFra
|
||||
private void onRadioButtonConfirmed(String selectedKey) {
|
||||
final boolean success = setDefaultAppKey(selectedKey);
|
||||
if (success) {
|
||||
final PreferenceScreen screen = getPreferenceScreen();
|
||||
if (screen != null) {
|
||||
final int count = screen.getPreferenceCount();
|
||||
for (int i = 0; i < count; i++) {
|
||||
final Preference pref = screen.getPreference(i);
|
||||
if (pref instanceof RadioButtonPreference) {
|
||||
final RadioButtonPreference radioPref = (RadioButtonPreference) pref;
|
||||
final boolean newCheckedState =
|
||||
TextUtils.equals(pref.getKey(), selectedKey);
|
||||
if (radioPref.isChecked() != newCheckedState) {
|
||||
radioPref.setChecked(TextUtils.equals(pref.getKey(), selectedKey));
|
||||
}
|
||||
updateCheckedState(selectedKey);
|
||||
}
|
||||
onSelectionPerformed(success);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void updateCheckedState(String selectedKey) {
|
||||
final PreferenceScreen screen = getPreferenceScreen();
|
||||
if (screen != null) {
|
||||
final int count = screen.getPreferenceCount();
|
||||
for (int i = 0; i < count; i++) {
|
||||
final Preference pref = screen.getPreference(i);
|
||||
if (pref instanceof RadioButtonPreference) {
|
||||
final RadioButtonPreference radioPref = (RadioButtonPreference) pref;
|
||||
final boolean newCheckedState = TextUtils.equals(pref.getKey(), selectedKey);
|
||||
if (radioPref.isChecked() != newCheckedState) {
|
||||
radioPref.setChecked(TextUtils.equals(pref.getKey(), selectedKey));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -177,6 +191,9 @@ public abstract class DefaultAppPickerFragment extends InstrumentedPreferenceFra
|
||||
|
||||
protected abstract boolean setDefaultAppKey(String key);
|
||||
|
||||
// Called after the user tries to select an item.
|
||||
protected void onSelectionPerformed(boolean success) {}
|
||||
|
||||
protected String getConfirmationMessage(DefaultAppInfo appInfo) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user