Allow "None" to be selected as a Network rating provider.

Updated the picker to always provide "None" as an option. The
preference is only disabled if there a no valid scorers installed.
Existing tests updated and new tests added.

Bug: 37722313
Test: make RunSettingsRoboTests -j40
Test: manual on device clicking.
Change-Id: Ie6fd9f29e0ea3c64845dd98ce1d117013f50c86b
This commit is contained in:
Jeremy Joslin
2017-04-28 16:40:51 -07:00
parent 23550fdcd3
commit 9dd363847c
4 changed files with 84 additions and 20 deletions

View File

@@ -74,14 +74,19 @@ public class NetworkScorerPicker extends InstrumentedPreferenceFragment implemen
screen.removeAll();
final List<NetworkScorerAppData> scorers = mNetworkScoreManager.getAllValidScorers();
if (scorers.isEmpty()) {
final RadioButtonPreference nonePref = new RadioButtonPreference(getPrefContext());
nonePref.setTitle(R.string.network_scorer_picker_none_preference);
nonePref.setChecked(true);
screen.addPreference(nonePref);
return;
}
final String defaultAppKey = getActiveScorerPackage();
final RadioButtonPreference nonePref = new RadioButtonPreference(getPrefContext());
nonePref.setTitle(R.string.network_scorer_picker_none_preference);
if (scorers.isEmpty()) {
nonePref.setChecked(true);
} else {
nonePref.setKey(null);
nonePref.setChecked(TextUtils.isEmpty(defaultAppKey));
nonePref.setOnClickListener(this);
}
screen.addPreference(nonePref);
final int numScorers = scorers.size();
for (int i = 0; i < numScorers; i++) {
final RadioButtonPreference pref = new RadioButtonPreference(getPrefContext());

View File

@@ -17,14 +17,16 @@ package com.android.settings.network;
import android.content.Context;
import android.net.NetworkScorerAppData;
import android.provider.Settings;
import android.support.v7.preference.Preference;
import com.android.settings.R;
import com.android.settings.core.PreferenceController;
import java.util.List;
/**
* {@link PreferenceController} that shows the active network scorer and toggles the preference
* based on {@link Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED}.
* based on whether or not there are valid scorers installed.
*/
public class NetworkScorerPickerPreferenceController extends PreferenceController {
@@ -45,8 +47,9 @@ public class NetworkScorerPickerPreferenceController extends PreferenceControlle
@Override
public void updateState(Preference preference) {
boolean enabled = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED, 0) == 1;
final List<NetworkScorerAppData> allValidScorers =
mNetworkScoreManager.getAllValidScorers();
boolean enabled = !allValidScorers.isEmpty();
preference.setEnabled(enabled);
if (!enabled) {
preference.setSummary(null);