Loading res/xml/wifi_configure_settings.xml +2 −1 Original line number Diff line number Diff line Loading @@ -41,7 +41,8 @@ <SwitchPreference android:key="wifi_cellular_data_fallback" android:title="@string/wifi_cellular_data_fallback_title" android:summary="@string/wifi_cellular_data_fallback_summary" /> android:summary="@string/wifi_cellular_data_fallback_summary" settings:controller="com.android.settings.wifi.CellularFallbackPreferenceController" /> <Preference android:key="install_credentials" Loading src/com/android/settings/wifi/CellularFallbackPreferenceController.java +13 −41 Original line number Diff line number Diff line Loading @@ -18,62 +18,34 @@ package com.android.settings.wifi; import android.content.Context; import android.provider.Settings; import android.text.TextUtils; import androidx.preference.Preference; import androidx.preference.SwitchPreference; import com.android.settings.core.PreferenceControllerMixin; import com.android.settingslib.core.AbstractPreferenceController; import com.android.settings.core.TogglePreferenceController; /** * {@link AbstractPreferenceController} that controls whether we should fall back to celluar when * CellularFallbackPreferenceController controls whether we should fall back to celluar when * wifi is bad. */ public class CellularFallbackPreferenceController extends AbstractPreferenceController implements PreferenceControllerMixin { private static final String KEY_CELLULAR_FALLBACK = "wifi_cellular_data_fallback"; public class CellularFallbackPreferenceController extends TogglePreferenceController { public CellularFallbackPreferenceController(Context context) { super(context); public CellularFallbackPreferenceController(Context context, String key) { super(context, key); } @Override public boolean isAvailable() { return !avoidBadWifiConfig(); public int getAvailabilityStatus() { return !avoidBadWifiConfig() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; } @Override public String getPreferenceKey() { return KEY_CELLULAR_FALLBACK; public boolean isChecked() { return avoidBadWifiCurrentSettings(); } @Override public boolean handlePreferenceTreeClick(Preference preference) { if (!TextUtils.equals(preference.getKey(), KEY_CELLULAR_FALLBACK)) { return false; } if (!(preference instanceof SwitchPreference)) { return false; } public boolean setChecked(boolean isChecked) { // On: avoid bad wifi. Off: prompt. String settingName = Settings.Global.NETWORK_AVOID_BAD_WIFI; Settings.Global.putString(mContext.getContentResolver(), settingName, ((SwitchPreference) preference).isChecked() ? "1" : null); return true; } @Override public void updateState(Preference preference) { final boolean currentSetting = avoidBadWifiCurrentSettings(); // TODO: can this ever be null? The return value of avoidBadWifiConfig() can only // change if the resources change, but if that happens the activity will be recreated... if (preference != null) { SwitchPreference pref = (SwitchPreference) preference; pref.setChecked(currentSetting); } return Settings.Global.putString(mContext.getContentResolver(), Settings.Global.NETWORK_AVOID_BAD_WIFI, isChecked ? "1" : null); } private boolean avoidBadWifiConfig() { Loading src/com/android/settings/wifi/ConfigureWifiSettings.java +0 −1 Original line number Diff line number Diff line Loading @@ -85,7 +85,6 @@ public class ConfigureWifiSettings extends DashboardFragment { controllers.add(mUseOpenWifiPreferenceController); controllers.add(new WifiInfoPreferenceController(context, getSettingsLifecycle(), wifiManager)); controllers.add(new CellularFallbackPreferenceController(context)); controllers.add(new WifiP2pPreferenceController(context, getSettingsLifecycle(), wifiManager)); return controllers; Loading tests/robotests/src/com/android/settings/wifi/CellularFallbackPreferenceControllerTest.java +2 −1 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import org.mockito.MockitoAnnotations; @RunWith(SettingsRobolectricTestRunner.class) public class CellularFallbackPreferenceControllerTest { private static final String KEY_CELLULAR_FALLBACK = "wifi_cellular_data_fallback"; @Mock(answer = Answers.RETURNS_DEEP_STUBS) private Context mContext; Loading @@ -42,7 +43,7 @@ public class CellularFallbackPreferenceControllerTest { @Before public void setUp() { MockitoAnnotations.initMocks(this); mController = new CellularFallbackPreferenceController(mContext); mController = new CellularFallbackPreferenceController(mContext, KEY_CELLULAR_FALLBACK); } @Test Loading Loading
res/xml/wifi_configure_settings.xml +2 −1 Original line number Diff line number Diff line Loading @@ -41,7 +41,8 @@ <SwitchPreference android:key="wifi_cellular_data_fallback" android:title="@string/wifi_cellular_data_fallback_title" android:summary="@string/wifi_cellular_data_fallback_summary" /> android:summary="@string/wifi_cellular_data_fallback_summary" settings:controller="com.android.settings.wifi.CellularFallbackPreferenceController" /> <Preference android:key="install_credentials" Loading
src/com/android/settings/wifi/CellularFallbackPreferenceController.java +13 −41 Original line number Diff line number Diff line Loading @@ -18,62 +18,34 @@ package com.android.settings.wifi; import android.content.Context; import android.provider.Settings; import android.text.TextUtils; import androidx.preference.Preference; import androidx.preference.SwitchPreference; import com.android.settings.core.PreferenceControllerMixin; import com.android.settingslib.core.AbstractPreferenceController; import com.android.settings.core.TogglePreferenceController; /** * {@link AbstractPreferenceController} that controls whether we should fall back to celluar when * CellularFallbackPreferenceController controls whether we should fall back to celluar when * wifi is bad. */ public class CellularFallbackPreferenceController extends AbstractPreferenceController implements PreferenceControllerMixin { private static final String KEY_CELLULAR_FALLBACK = "wifi_cellular_data_fallback"; public class CellularFallbackPreferenceController extends TogglePreferenceController { public CellularFallbackPreferenceController(Context context) { super(context); public CellularFallbackPreferenceController(Context context, String key) { super(context, key); } @Override public boolean isAvailable() { return !avoidBadWifiConfig(); public int getAvailabilityStatus() { return !avoidBadWifiConfig() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; } @Override public String getPreferenceKey() { return KEY_CELLULAR_FALLBACK; public boolean isChecked() { return avoidBadWifiCurrentSettings(); } @Override public boolean handlePreferenceTreeClick(Preference preference) { if (!TextUtils.equals(preference.getKey(), KEY_CELLULAR_FALLBACK)) { return false; } if (!(preference instanceof SwitchPreference)) { return false; } public boolean setChecked(boolean isChecked) { // On: avoid bad wifi. Off: prompt. String settingName = Settings.Global.NETWORK_AVOID_BAD_WIFI; Settings.Global.putString(mContext.getContentResolver(), settingName, ((SwitchPreference) preference).isChecked() ? "1" : null); return true; } @Override public void updateState(Preference preference) { final boolean currentSetting = avoidBadWifiCurrentSettings(); // TODO: can this ever be null? The return value of avoidBadWifiConfig() can only // change if the resources change, but if that happens the activity will be recreated... if (preference != null) { SwitchPreference pref = (SwitchPreference) preference; pref.setChecked(currentSetting); } return Settings.Global.putString(mContext.getContentResolver(), Settings.Global.NETWORK_AVOID_BAD_WIFI, isChecked ? "1" : null); } private boolean avoidBadWifiConfig() { Loading
src/com/android/settings/wifi/ConfigureWifiSettings.java +0 −1 Original line number Diff line number Diff line Loading @@ -85,7 +85,6 @@ public class ConfigureWifiSettings extends DashboardFragment { controllers.add(mUseOpenWifiPreferenceController); controllers.add(new WifiInfoPreferenceController(context, getSettingsLifecycle(), wifiManager)); controllers.add(new CellularFallbackPreferenceController(context)); controllers.add(new WifiP2pPreferenceController(context, getSettingsLifecycle(), wifiManager)); return controllers; Loading
tests/robotests/src/com/android/settings/wifi/CellularFallbackPreferenceControllerTest.java +2 −1 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import org.mockito.MockitoAnnotations; @RunWith(SettingsRobolectricTestRunner.class) public class CellularFallbackPreferenceControllerTest { private static final String KEY_CELLULAR_FALLBACK = "wifi_cellular_data_fallback"; @Mock(answer = Answers.RETURNS_DEEP_STUBS) private Context mContext; Loading @@ -42,7 +43,7 @@ public class CellularFallbackPreferenceControllerTest { @Before public void setUp() { MockitoAnnotations.initMocks(this); mController = new CellularFallbackPreferenceController(mContext); mController = new CellularFallbackPreferenceController(mContext, KEY_CELLULAR_FALLBACK); } @Test Loading