Merge "[Provider Model] Add Wi-Fi toggle" into sc-dev
This commit is contained in:
@@ -12671,10 +12671,8 @@
|
|||||||
<string name="provider_internet_settings">Internet</string>
|
<string name="provider_internet_settings">Internet</string>
|
||||||
<!-- Provider Model: SIMs controls settings screen, item title to go into the SIMs settings -->
|
<!-- Provider Model: SIMs controls settings screen, item title to go into the SIMs settings -->
|
||||||
<string name="provider_network_settings_title">SIMs</string>
|
<string name="provider_network_settings_title">SIMs</string>
|
||||||
<!-- Provider Model: Airplane mode networks controls settings screen -->
|
<!-- Provider Model: Summary for Wi-Fi switch [CHAR LIMIT=NONE] -->
|
||||||
<string name="airplane_safe_networks">Show airplane mode networks</string>
|
<string name="wifi_switch_summary">Find and connect to Wi\u2011Fi networks</string>
|
||||||
<!-- Provider Model: Summary for showing airplane mode networks-->
|
|
||||||
<string name="airplane_safe_networks_summary">Find and connect to networks in airplane mode.</string>
|
|
||||||
<!-- Provider Model: List of synonyms for the airplane-safe networks, used to match in settings search [CHAR LIMIT=NONE] -->
|
<!-- Provider Model: List of synonyms for the airplane-safe networks, used to match in settings search [CHAR LIMIT=NONE] -->
|
||||||
<string name="keywords_airplane_safe_networks">airplane, airplane-safe</string>
|
<string name="keywords_airplane_safe_networks">airplane, airplane-safe</string>
|
||||||
<!-- Provider Model: Calls and SMS controllers settings screen, item title to go into the Calls and SMS settings -->
|
<!-- Provider Model: Calls and SMS controllers settings screen, item title to go into the Calls and SMS settings -->
|
||||||
|
@@ -61,15 +61,6 @@
|
|||||||
settings:controller="com.android.settings.network.AirplaneModePreferenceController"
|
settings:controller="com.android.settings.network.AirplaneModePreferenceController"
|
||||||
settings:userRestriction="no_airplane_mode"/>
|
settings:userRestriction="no_airplane_mode"/>
|
||||||
|
|
||||||
<com.android.settingslib.RestrictedSwitchPreference
|
|
||||||
android:key="airplane_safe_networks"
|
|
||||||
android:title="@string/airplane_safe_networks"
|
|
||||||
android:icon="@drawable/ic_airplane_safe_networks_24dp"
|
|
||||||
android:summary="@string/airplane_safe_networks_summary"
|
|
||||||
android:order="-4"
|
|
||||||
settings:userRestriction="no_airplane_mode"
|
|
||||||
settings:keywords="@string/keywords_airplane_safe_networks" />
|
|
||||||
|
|
||||||
<com.android.settingslib.RestrictedPreference
|
<com.android.settingslib.RestrictedPreference
|
||||||
android:key="manage_mobile_plan"
|
android:key="manage_mobile_plan"
|
||||||
android:title="@string/manage_mobile_plan_title"
|
android:title="@string/manage_mobile_plan_title"
|
||||||
|
@@ -56,6 +56,13 @@
|
|||||||
android:key="access_points"
|
android:key="access_points"
|
||||||
android:layout="@layout/preference_category_no_label"/>
|
android:layout="@layout/preference_category_no_label"/>
|
||||||
|
|
||||||
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
|
android:key="wifi_switch"
|
||||||
|
android:title="@string/wifi"
|
||||||
|
android:summary="@string/wifi_switch_summary"
|
||||||
|
settings:allowDividerAbove="true"
|
||||||
|
settings:keywords="@string/keywords_wifi"/>
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="configure_wifi_settings"
|
android:key="configure_wifi_settings"
|
||||||
android:title="@string/network_and_internet_preferences_title"
|
android:title="@string/network_and_internet_preferences_title"
|
||||||
|
@@ -146,7 +146,6 @@ public class NetworkDashboardFragment extends DashboardFragment implements
|
|||||||
controllers.add(privateDnsPreferenceController);
|
controllers.add(privateDnsPreferenceController);
|
||||||
if (Utils.isProviderModelEnabled(context)) {
|
if (Utils.isProviderModelEnabled(context)) {
|
||||||
controllers.add(new NetworkProviderCallsSmsController(context, lifecycle));
|
controllers.add(new NetworkProviderCallsSmsController(context, lifecycle));
|
||||||
controllers.add(new AirplaneSafeNetworksPreferenceController(context, lifecycle));
|
|
||||||
}
|
}
|
||||||
return controllers;
|
return controllers;
|
||||||
}
|
}
|
||||||
|
@@ -196,6 +196,7 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
|
|||||||
private PreferenceCategory mWifiEntryPreferenceCategory;
|
private PreferenceCategory mWifiEntryPreferenceCategory;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
AddWifiNetworkPreference mAddWifiNetworkPreference;
|
AddWifiNetworkPreference mAddWifiNetworkPreference;
|
||||||
|
private WifiSwitchPreferenceController mWifiSwitchPreferenceController;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
Preference mConfigureWifiSettingsPreference;
|
Preference mConfigureWifiSettingsPreference;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -270,6 +271,7 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
|
|||||||
addNetworkMobileProviderController();
|
addNetworkMobileProviderController();
|
||||||
addViewAirplaneModeNetworksButtonController();
|
addViewAirplaneModeNetworksButtonController();
|
||||||
addConnectedEthernetNetworkController();
|
addConnectedEthernetNetworkController();
|
||||||
|
addWifiSwitchPreferenceController();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addNetworkMobileProviderController() {
|
private void addNetworkMobileProviderController() {
|
||||||
@@ -298,6 +300,14 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
|
|||||||
mConnectedEthernetNetworkController.displayPreference(getPreferenceScreen());
|
mConnectedEthernetNetworkController.displayPreference(getPreferenceScreen());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addWifiSwitchPreferenceController() {
|
||||||
|
if (mWifiSwitchPreferenceController == null) {
|
||||||
|
mWifiSwitchPreferenceController =
|
||||||
|
new WifiSwitchPreferenceController(getContext(), getSettingsLifecycle());
|
||||||
|
}
|
||||||
|
mWifiSwitchPreferenceController.displayPreference(getPreferenceScreen());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
@@ -23,41 +23,41 @@ import androidx.lifecycle.LifecycleObserver;
|
|||||||
import androidx.lifecycle.OnLifecycleEvent;
|
import androidx.lifecycle.OnLifecycleEvent;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.AirplaneModeEnabler;
|
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.widget.GenericSwitchController;
|
import com.android.settings.widget.GenericSwitchController;
|
||||||
import com.android.settings.wifi.WifiEnabler;
|
import com.android.settings.wifi.WifiEnabler;
|
||||||
import com.android.settingslib.RestrictedSwitchPreference;
|
import com.android.settingslib.RestrictedSwitchPreference;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
|
||||||
public class AirplaneSafeNetworksPreferenceController extends AbstractPreferenceController
|
/**
|
||||||
implements LifecycleObserver, AirplaneModeEnabler.OnAirplaneModeChangedListener {
|
* This controller helps to manage the state of wifi switch preference.
|
||||||
|
*/
|
||||||
|
public class WifiSwitchPreferenceController extends AbstractPreferenceController implements
|
||||||
|
LifecycleObserver {
|
||||||
|
|
||||||
private static final String PREFERENCE_KEY = "airplane_safe_networks";
|
public static final String KEY = "wifi_switch";
|
||||||
|
|
||||||
private RestrictedSwitchPreference mPreference;
|
private RestrictedSwitchPreference mPreference;
|
||||||
|
|
||||||
private AirplaneModeEnabler mAirplaneModeEnabler;
|
|
||||||
private WifiEnabler mWifiEnabler;
|
private WifiEnabler mWifiEnabler;
|
||||||
|
|
||||||
public AirplaneSafeNetworksPreferenceController(Context context, Lifecycle lifecycle) {
|
public WifiSwitchPreferenceController(Context context, Lifecycle lifecycle) {
|
||||||
super(context);
|
super(context);
|
||||||
if (lifecycle == null) {
|
if (lifecycle == null) {
|
||||||
throw new IllegalArgumentException("Lifecycle must be set");
|
throw new IllegalArgumentException("Lifecycle must be set");
|
||||||
}
|
}
|
||||||
|
|
||||||
mAirplaneModeEnabler = new AirplaneModeEnabler(mContext, this);
|
|
||||||
lifecycle.addObserver(this);
|
lifecycle.addObserver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPreferenceKey() {
|
public String getPreferenceKey() {
|
||||||
return PREFERENCE_KEY;
|
return KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
return mAirplaneModeEnabler.isAirplaneModeOn();
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -66,23 +66,24 @@ public class AirplaneSafeNetworksPreferenceController extends AbstractPreference
|
|||||||
mPreference = screen.findPreference(getPreferenceKey());
|
mPreference = screen.findPreference(getPreferenceKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Lifecycle.Event.ON_START */
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
mAirplaneModeEnabler.start();
|
|
||||||
if (mPreference != null) {
|
if (mPreference != null) {
|
||||||
mWifiEnabler = new WifiEnabler(mContext, new GenericSwitchController(mPreference),
|
mWifiEnabler = new WifiEnabler(mContext, new GenericSwitchController(mPreference),
|
||||||
FeatureFactory.getFactory(mContext).getMetricsFeatureProvider());
|
FeatureFactory.getFactory(mContext).getMetricsFeatureProvider());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Lifecycle.Event.ON_STOP */
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
|
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
mAirplaneModeEnabler.stop();
|
|
||||||
if (mWifiEnabler != null) {
|
if (mWifiEnabler != null) {
|
||||||
mWifiEnabler.teardownSwitchController();
|
mWifiEnabler.teardownSwitchController();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Lifecycle.Event.ON_RESUME */
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
if (mWifiEnabler != null) {
|
if (mWifiEnabler != null) {
|
||||||
@@ -90,17 +91,11 @@ public class AirplaneSafeNetworksPreferenceController extends AbstractPreference
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Lifecycle.Event.ON_PAUSE */
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
if (mWifiEnabler != null) {
|
if (mWifiEnabler != null) {
|
||||||
mWifiEnabler.pause();
|
mWifiEnabler.pause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAirplaneModeChanged(boolean isAirplaneModeOn) {
|
|
||||||
if (mPreference != null) {
|
|
||||||
mPreference.setVisible(isAirplaneModeOn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
@@ -22,11 +22,9 @@ import static org.mockito.Mockito.doReturn;
|
|||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
|
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.provider.Settings;
|
|
||||||
|
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
@@ -43,17 +41,11 @@ import org.mockito.Mock;
|
|||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class AirplaneSafeNetworksPreferenceControllerTest {
|
public class WifiSwitchPreferenceControllerTest {
|
||||||
|
|
||||||
private static final String KEY_AIRPLANE_SAFE_NETWORKS = "airplane_safe_networks";
|
|
||||||
|
|
||||||
private static final int ON = 1;
|
|
||||||
private static final int OFF = 0;
|
|
||||||
|
|
||||||
private ContentResolver mResolver;
|
|
||||||
private PreferenceScreen mScreen;
|
private PreferenceScreen mScreen;
|
||||||
private RestrictedSwitchPreference mPreference;
|
private RestrictedSwitchPreference mPreference;
|
||||||
private AirplaneSafeNetworksPreferenceController mController;
|
private WifiSwitchPreferenceController mController;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private WifiManager mWifiManager;
|
private WifiManager mWifiManager;
|
||||||
@@ -62,37 +54,21 @@ public class AirplaneSafeNetworksPreferenceControllerTest {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
final Context context = spy(ApplicationProvider.getApplicationContext());
|
final Context context = spy(ApplicationProvider.getApplicationContext());
|
||||||
mResolver = context.getContentResolver();
|
|
||||||
doReturn(mWifiManager).when(context).getSystemService(Context.WIFI_SERVICE);
|
doReturn(mWifiManager).when(context).getSystemService(Context.WIFI_SERVICE);
|
||||||
|
|
||||||
mController = new AirplaneSafeNetworksPreferenceController(context, mock(Lifecycle.class));
|
mController = new WifiSwitchPreferenceController(context, mock(Lifecycle.class));
|
||||||
if (Looper.myLooper() == null) {
|
if (Looper.myLooper() == null) {
|
||||||
Looper.prepare();
|
Looper.prepare();
|
||||||
}
|
}
|
||||||
final PreferenceManager preferenceManager = new PreferenceManager(context);
|
final PreferenceManager preferenceManager = new PreferenceManager(context);
|
||||||
mScreen = preferenceManager.createPreferenceScreen(context);
|
mScreen = preferenceManager.createPreferenceScreen(context);
|
||||||
mPreference = new RestrictedSwitchPreference(context);
|
mPreference = new RestrictedSwitchPreference(context);
|
||||||
mPreference.setKey(KEY_AIRPLANE_SAFE_NETWORKS);
|
mPreference.setKey(WifiSwitchPreferenceController.KEY);
|
||||||
mScreen.addPreference(mPreference);
|
mScreen.addPreference(mPreference);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_airplaneModeOff_returnFalse() {
|
public void isAvailable_returnTrue() {
|
||||||
Settings.Global.putInt(mResolver, Settings.Global.AIRPLANE_MODE_ON, OFF);
|
|
||||||
|
|
||||||
mController.displayPreference(mScreen);
|
|
||||||
mController.onStart();
|
|
||||||
|
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isAvailable_airplaneModeOn_returnTrue() {
|
|
||||||
Settings.Global.putInt(mResolver, Settings.Global.AIRPLANE_MODE_ON, ON);
|
|
||||||
|
|
||||||
mController.displayPreference(mScreen);
|
|
||||||
mController.onStart();
|
|
||||||
|
|
||||||
assertThat(mController.isAvailable()).isTrue();
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue
Block a user