Add toggle for Wi-Fi hotspot
- Add Wi-Fi hotspot toggle with vertical divider - Disable preference and toggle when Data Saver is enabled Bug: 245569117 Test: manual test make RunSettingsRoboTests ROBOTEST_FILTER=TetherSettingsTest make RunSettingsRoboTests ROBOTEST_FILTER=WifiTetherPreferenceControllerTest atest -c TetheringManagerModelTest Change-Id: Ic2baf7d3d0a7bf9527da38d24ecc511b7c91265a
This commit is contained in:
@@ -23,10 +23,10 @@
|
|||||||
android:key="tether_prefs_top_intro"
|
android:key="tether_prefs_top_intro"
|
||||||
settings:searchable="false"/>
|
settings:searchable="false"/>
|
||||||
|
|
||||||
<com.android.settings.widget.FixedLineSummaryPreference
|
<com.android.settingslib.PrimarySwitchPreference
|
||||||
android:key="wifi_tether"
|
android:key="wifi_tether"
|
||||||
android:title="@string/wifi_hotspot_checkbox_text"
|
android:title="@string/wifi_hotspot_checkbox_text"
|
||||||
android:summary="@string/summary_placeholder"
|
android:summary="@string/wifi_hotspot_off_subtext"
|
||||||
android:fragment="com.android.settings.wifi.tether.WifiTetherSettings"
|
android:fragment="com.android.settings.wifi.tether.WifiTetherSettings"
|
||||||
settings:allowDividerAbove="true"
|
settings:allowDividerAbove="true"
|
||||||
settings:maxLines="2"/>
|
settings:maxLines="2"/>
|
||||||
|
@@ -96,11 +96,12 @@ public class TetherSettings extends RestrictedSettingsFragment
|
|||||||
private static final String TAG = "TetheringSettings";
|
private static final String TAG = "TetheringSettings";
|
||||||
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
||||||
|
|
||||||
private RestrictedSwitchPreference mUsbTether;
|
@VisibleForTesting
|
||||||
|
RestrictedSwitchPreference mUsbTether;
|
||||||
private SwitchPreference mBluetoothTether;
|
@VisibleForTesting
|
||||||
|
SwitchPreference mBluetoothTether;
|
||||||
private SwitchPreference mEthernetTether;
|
@VisibleForTesting
|
||||||
|
SwitchPreference mEthernetTether;
|
||||||
|
|
||||||
private BroadcastReceiver mTetherChangeReceiver;
|
private BroadcastReceiver mTetherChangeReceiver;
|
||||||
private BroadcastReceiver mBluetoothStateReceiver;
|
private BroadcastReceiver mBluetoothStateReceiver;
|
||||||
@@ -115,7 +116,8 @@ public class TetherSettings extends RestrictedSettingsFragment
|
|||||||
private EthernetListener mEthernetListener;
|
private EthernetListener mEthernetListener;
|
||||||
private final HashSet<String> mAvailableInterfaces = new HashSet<>();
|
private final HashSet<String> mAvailableInterfaces = new HashSet<>();
|
||||||
|
|
||||||
private WifiTetherPreferenceController mWifiTetherPreferenceController;
|
@VisibleForTesting
|
||||||
|
WifiTetherPreferenceController mWifiTetherPreferenceController;
|
||||||
|
|
||||||
private boolean mUsbConnected;
|
private boolean mUsbConnected;
|
||||||
private boolean mMassStorageActive;
|
private boolean mMassStorageActive;
|
||||||
@@ -125,7 +127,8 @@ public class TetherSettings extends RestrictedSettingsFragment
|
|||||||
|
|
||||||
private DataSaverBackend mDataSaverBackend;
|
private DataSaverBackend mDataSaverBackend;
|
||||||
private boolean mDataSaverEnabled;
|
private boolean mDataSaverEnabled;
|
||||||
private Preference mDataSaverFooter;
|
@VisibleForTesting
|
||||||
|
Preference mDataSaverFooter;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
String[] mUsbRegexs;
|
String[] mUsbRegexs;
|
||||||
@@ -146,10 +149,10 @@ public class TetherSettings extends RestrictedSettingsFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
mWifiTetherPreferenceController =
|
|
||||||
new WifiTetherPreferenceController(context, getSettingsLifecycle());
|
|
||||||
TetheringManagerModel model = new ViewModelProvider(this).get(TetheringManagerModel.class);
|
TetheringManagerModel model = new ViewModelProvider(this).get(TetheringManagerModel.class);
|
||||||
mTm = model.mTetheringManager;
|
mWifiTetherPreferenceController =
|
||||||
|
new WifiTetherPreferenceController(context, getSettingsLifecycle(), model);
|
||||||
|
mTm = model.getTetheringManager();
|
||||||
model.getTetheredInterfaces().observe(this, this::onTetheredInterfacesChanged);
|
model.getTetheredInterfaces().observe(this, this::onTetheredInterfacesChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,6 +251,7 @@ public class TetherSettings extends RestrictedSettingsFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onDataSaverChanged(boolean isDataSaving) {
|
public void onDataSaverChanged(boolean isDataSaving) {
|
||||||
mDataSaverEnabled = isDataSaving;
|
mDataSaverEnabled = isDataSaving;
|
||||||
|
mWifiTetherPreferenceController.setDataSaverEnabled(mDataSaverEnabled);
|
||||||
mUsbTether.setEnabled(!mDataSaverEnabled);
|
mUsbTether.setEnabled(!mDataSaverEnabled);
|
||||||
mBluetoothTether.setEnabled(!mDataSaverEnabled);
|
mBluetoothTether.setEnabled(!mDataSaverEnabled);
|
||||||
mEthernetTether.setEnabled(!mDataSaverEnabled);
|
mEthernetTether.setEnabled(!mDataSaverEnabled);
|
||||||
|
@@ -34,6 +34,7 @@ public class TetheringManagerModel extends AndroidViewModel {
|
|||||||
protected TetheringManager mTetheringManager;
|
protected TetheringManager mTetheringManager;
|
||||||
protected EventCallback mEventCallback = new EventCallback();
|
protected EventCallback mEventCallback = new EventCallback();
|
||||||
protected MutableLiveData<List<String>> mTetheredInterfaces = new MutableLiveData<>();
|
protected MutableLiveData<List<String>> mTetheredInterfaces = new MutableLiveData<>();
|
||||||
|
protected StartTetheringCallback mStartTetheringCallback = new StartTetheringCallback();
|
||||||
|
|
||||||
public TetheringManagerModel(@NonNull Application application) {
|
public TetheringManagerModel(@NonNull Application application) {
|
||||||
super(application);
|
super(application);
|
||||||
@@ -62,6 +63,27 @@ public class TetheringManagerModel extends AndroidViewModel {
|
|||||||
return Transformations.distinctUntilChanged(mTetheredInterfaces);
|
return Transformations.distinctUntilChanged(mTetheredInterfaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts tethering and runs tether provisioning for the given type if needed. If provisioning
|
||||||
|
* fails, stopTethering will be called automatically.
|
||||||
|
*
|
||||||
|
* @param type The tethering type, on of the {@code TetheringManager#TETHERING_*} constants.
|
||||||
|
*/
|
||||||
|
public void startTethering(int type) {
|
||||||
|
mTetheringManager.startTethering(type, getApplication().getMainExecutor(),
|
||||||
|
mStartTetheringCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops tethering for the given type. Also cancels any provisioning rechecks for that type if
|
||||||
|
* applicable.
|
||||||
|
*
|
||||||
|
* @param type The tethering type, on of the {@code TetheringManager#TETHERING_*} constants.
|
||||||
|
*/
|
||||||
|
public void stopTethering(int type) {
|
||||||
|
mTetheringManager.stopTethering(type);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback for use with {@link TetheringManager#registerTetheringEventCallback} to find out
|
* Callback for use with {@link TetheringManager#registerTetheringEventCallback} to find out
|
||||||
* tethering upstream status.
|
* tethering upstream status.
|
||||||
@@ -72,4 +94,16 @@ public class TetheringManagerModel extends AndroidViewModel {
|
|||||||
mTetheredInterfaces.setValue(interfaces);
|
mTetheredInterfaces.setValue(interfaces);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class StartTetheringCallback implements TetheringManager.StartTetheringCallback {
|
||||||
|
@Override
|
||||||
|
public void onTetheringStarted() {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTetheringFailed(int error) {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
package com.android.settings.wifi.tether;
|
package com.android.settings.wifi.tether;
|
||||||
|
|
||||||
|
import static android.net.TetheringManager.TETHERING_WIFI;
|
||||||
|
import static android.net.wifi.WifiManager.SAP_START_FAILURE_GENERAL;
|
||||||
|
|
||||||
import static com.android.settings.wifi.WifiUtils.canShowWifiHotspot;
|
import static com.android.settings.wifi.WifiUtils.canShowWifiHotspot;
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
@@ -26,12 +29,15 @@ import android.net.wifi.WifiManager;
|
|||||||
import android.text.BidiFormatter;
|
import android.text.BidiFormatter;
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.preference.Preference;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
|
import com.android.settings.network.tether.TetheringManagerModel;
|
||||||
|
import com.android.settings.widget.GenericSwitchController;
|
||||||
|
import com.android.settings.widget.SwitchWidgetController;
|
||||||
|
import com.android.settingslib.PrimarySwitchPreference;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||||
@@ -43,7 +49,8 @@ import com.android.settingslib.wifi.WifiUtils;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class WifiTetherPreferenceController extends AbstractPreferenceController
|
public class WifiTetherPreferenceController extends AbstractPreferenceController
|
||||||
implements PreferenceControllerMixin, LifecycleObserver, OnStart, OnStop {
|
implements PreferenceControllerMixin, LifecycleObserver, OnStart, OnStop,
|
||||||
|
SwitchWidgetController.OnSwitchChangeListener {
|
||||||
|
|
||||||
private static final String WIFI_TETHER_SETTINGS = "wifi_tether";
|
private static final String WIFI_TETHER_SETTINGS = "wifi_tether";
|
||||||
|
|
||||||
@@ -51,16 +58,24 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
|
|||||||
private boolean mIsWifiTetheringAllow;
|
private boolean mIsWifiTetheringAllow;
|
||||||
private int mSoftApState;
|
private int mSoftApState;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
Preference mPreference;
|
PrimarySwitchPreference mPreference;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
WifiTetherSoftApManager mWifiTetherSoftApManager;
|
WifiTetherSoftApManager mWifiTetherSoftApManager;
|
||||||
|
@VisibleForTesting
|
||||||
|
TetheringManagerModel mTetheringManagerModel;
|
||||||
|
@VisibleForTesting
|
||||||
|
boolean mIsDataSaverEnabled;
|
||||||
|
@VisibleForTesting
|
||||||
|
SwitchWidgetController mSwitch;
|
||||||
|
|
||||||
public WifiTetherPreferenceController(Context context, Lifecycle lifecycle) {
|
public WifiTetherPreferenceController(Context context, Lifecycle lifecycle,
|
||||||
|
TetheringManagerModel tetheringManagerModel) {
|
||||||
// TODO(b/246537032):Use fragment context to WifiManager service will caused memory leak
|
// TODO(b/246537032):Use fragment context to WifiManager service will caused memory leak
|
||||||
this(context, lifecycle,
|
this(context, lifecycle,
|
||||||
context.getApplicationContext().getSystemService(WifiManager.class),
|
context.getApplicationContext().getSystemService(WifiManager.class),
|
||||||
true /* initSoftApManager */,
|
true /* initSoftApManager */,
|
||||||
WifiEnterpriseRestrictionUtils.isWifiTetheringAllowed(context));
|
WifiEnterpriseRestrictionUtils.isWifiTetheringAllowed(context),
|
||||||
|
tetheringManagerModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -69,11 +84,13 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
|
|||||||
Lifecycle lifecycle,
|
Lifecycle lifecycle,
|
||||||
WifiManager wifiManager,
|
WifiManager wifiManager,
|
||||||
boolean initSoftApManager,
|
boolean initSoftApManager,
|
||||||
boolean isWifiTetheringAllow) {
|
boolean isWifiTetheringAllow,
|
||||||
|
TetheringManagerModel tetheringManagerModel) {
|
||||||
super(context);
|
super(context);
|
||||||
mIsWifiTetheringAllow = isWifiTetheringAllow;
|
mIsWifiTetheringAllow = isWifiTetheringAllow;
|
||||||
if (!isWifiTetheringAllow) return;
|
if (!isWifiTetheringAllow) return;
|
||||||
|
|
||||||
|
mTetheringManagerModel = tetheringManagerModel;
|
||||||
mWifiManager = wifiManager;
|
mWifiManager = wifiManager;
|
||||||
|
|
||||||
if (lifecycle != null) {
|
if (lifecycle != null) {
|
||||||
@@ -97,8 +114,13 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
|
|||||||
// unavailable
|
// unavailable
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!mIsWifiTetheringAllow && mPreference.isEnabled()) {
|
if (mSwitch == null) {
|
||||||
mPreference.setEnabled(false);
|
mSwitch = new GenericSwitchController(mPreference);
|
||||||
|
mSwitch.setListener(this);
|
||||||
|
updateSwitch();
|
||||||
|
}
|
||||||
|
mPreference.setEnabled(canEnabled());
|
||||||
|
if (!mIsWifiTetheringAllow) {
|
||||||
mPreference.setSummary(R.string.not_allowed_by_ent);
|
mPreference.setSummary(R.string.not_allowed_by_ent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,6 +136,9 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
|
|||||||
if (mWifiTetherSoftApManager != null) {
|
if (mWifiTetherSoftApManager != null) {
|
||||||
mWifiTetherSoftApManager.registerSoftApCallback();
|
mWifiTetherSoftApManager.registerSoftApCallback();
|
||||||
}
|
}
|
||||||
|
if (mSwitch != null) {
|
||||||
|
mSwitch.startListening();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,6 +148,9 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
|
|||||||
if (mWifiTetherSoftApManager != null) {
|
if (mWifiTetherSoftApManager != null) {
|
||||||
mWifiTetherSoftApManager.unRegisterSoftApCallback();
|
mWifiTetherSoftApManager.unRegisterSoftApCallback();
|
||||||
}
|
}
|
||||||
|
if (mSwitch != null) {
|
||||||
|
mSwitch.stopListening();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,6 +186,7 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
|
|||||||
mPreference.setSummary(R.string.wifi_tether_starting);
|
mPreference.setSummary(R.string.wifi_tether_starting);
|
||||||
break;
|
break;
|
||||||
case WifiManager.WIFI_AP_STATE_ENABLED:
|
case WifiManager.WIFI_AP_STATE_ENABLED:
|
||||||
|
mSwitch.setChecked(true);
|
||||||
final SoftApConfiguration softApConfig = mWifiManager.getSoftApConfiguration();
|
final SoftApConfiguration softApConfig = mWifiManager.getSoftApConfiguration();
|
||||||
updateConfigSummary(softApConfig);
|
updateConfigSummary(softApConfig);
|
||||||
break;
|
break;
|
||||||
@@ -165,6 +194,7 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
|
|||||||
mPreference.setSummary(R.string.wifi_tether_stopping);
|
mPreference.setSummary(R.string.wifi_tether_stopping);
|
||||||
break;
|
break;
|
||||||
case WifiManager.WIFI_AP_STATE_DISABLED:
|
case WifiManager.WIFI_AP_STATE_DISABLED:
|
||||||
|
mSwitch.setChecked(false);
|
||||||
mPreference.setSummary(R.string.wifi_hotspot_off_subtext);
|
mPreference.setSummary(R.string.wifi_hotspot_off_subtext);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -184,4 +214,40 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
|
|||||||
mPreference.setSummary(mContext.getString(R.string.wifi_tether_enabled_subtext,
|
mPreference.setSummary(mContext.getString(R.string.wifi_tether_enabled_subtext,
|
||||||
BidiFormatter.getInstance().unicodeWrap(softApConfig.getSsid())));
|
BidiFormatter.getInstance().unicodeWrap(softApConfig.getSsid())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the Data Saver state for preference update.
|
||||||
|
*/
|
||||||
|
public void setDataSaverEnabled(boolean enabled) {
|
||||||
|
mIsDataSaverEnabled = enabled;
|
||||||
|
if (mPreference != null) {
|
||||||
|
mPreference.setEnabled(canEnabled());
|
||||||
|
}
|
||||||
|
if (mSwitch != null) {
|
||||||
|
mSwitch.setEnabled(canEnabled());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean canEnabled() {
|
||||||
|
return mIsWifiTetheringAllow && !mIsDataSaverEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
protected void updateSwitch() {
|
||||||
|
if (mWifiManager == null) return;
|
||||||
|
int wifiApState = mWifiManager.getWifiApState();
|
||||||
|
mSwitch.setEnabled(canEnabled());
|
||||||
|
mSwitch.setChecked(wifiApState == WifiManager.WIFI_AP_STATE_ENABLED);
|
||||||
|
handleWifiApStateChanged(wifiApState, SAP_START_FAILURE_GENERAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onSwitchToggled(boolean isChecked) {
|
||||||
|
if (isChecked) {
|
||||||
|
mTetheringManagerModel.startTethering(TETHERING_WIFI);
|
||||||
|
} else {
|
||||||
|
mTetheringManagerModel.stopTethering(TETHERING_WIFI);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -55,6 +55,7 @@ import androidx.preference.SwitchPreference;
|
|||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.FeatureFlags;
|
import com.android.settings.core.FeatureFlags;
|
||||||
|
import com.android.settings.wifi.tether.WifiTetherPreferenceController;
|
||||||
import com.android.settingslib.RestrictedSwitchPreference;
|
import com.android.settingslib.RestrictedSwitchPreference;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -80,6 +81,18 @@ public class TetherSettingsTest {
|
|||||||
private UserManager mUserManager;
|
private UserManager mUserManager;
|
||||||
@Mock
|
@Mock
|
||||||
private TetheringManager mTetheringManager;
|
private TetheringManager mTetheringManager;
|
||||||
|
@Mock
|
||||||
|
private WifiTetherPreferenceController mWifiTetherPreferenceController;
|
||||||
|
@Mock
|
||||||
|
private RestrictedSwitchPreference mUsbTether;
|
||||||
|
@Mock
|
||||||
|
private SwitchPreference mBluetoothTether;
|
||||||
|
@Mock
|
||||||
|
private SwitchPreference mEthernetTether;
|
||||||
|
@Mock
|
||||||
|
private Preference mDataSaverFooter;
|
||||||
|
|
||||||
|
TetherSettings mTetherSettings;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
@@ -100,6 +113,14 @@ public class TetherSettingsTest {
|
|||||||
|
|
||||||
when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
|
when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
|
||||||
when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[0]);
|
when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[0]);
|
||||||
|
|
||||||
|
mTetherSettings = spy(new TetherSettings());
|
||||||
|
mTetherSettings.mContext = mContext;
|
||||||
|
mTetherSettings.mWifiTetherPreferenceController = mWifiTetherPreferenceController;
|
||||||
|
mTetherSettings.mUsbTether = mUsbTether;
|
||||||
|
mTetherSettings.mBluetoothTether = mBluetoothTether;
|
||||||
|
mTetherSettings.mEthernetTether = mEthernetTether;
|
||||||
|
mTetherSettings.mDataSaverFooter = mDataSaverFooter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -184,16 +205,14 @@ public class TetherSettingsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetFooterPreferenceTitle_isStaApConcurrencySupported_showStaApString() {
|
public void testSetFooterPreferenceTitle_isStaApConcurrencySupported_showStaApString() {
|
||||||
final TetherSettings spyTetherSettings = spy(new TetherSettings());
|
|
||||||
spyTetherSettings.mContext = mContext;
|
|
||||||
final Preference mockPreference = mock(Preference.class);
|
final Preference mockPreference = mock(Preference.class);
|
||||||
when(spyTetherSettings.findPreference(TetherSettings.KEY_TETHER_PREFS_TOP_INTRO))
|
when(mTetherSettings.findPreference(TetherSettings.KEY_TETHER_PREFS_TOP_INTRO))
|
||||||
.thenReturn(mockPreference);
|
.thenReturn(mockPreference);
|
||||||
final WifiManager mockWifiManager = mock(WifiManager.class);
|
final WifiManager mockWifiManager = mock(WifiManager.class);
|
||||||
when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mockWifiManager);
|
when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mockWifiManager);
|
||||||
when(mockWifiManager.isStaApConcurrencySupported()).thenReturn(true);
|
when(mockWifiManager.isStaApConcurrencySupported()).thenReturn(true);
|
||||||
|
|
||||||
spyTetherSettings.setTopIntroPreferenceTitle();
|
mTetherSettings.setTopIntroPreferenceTitle();
|
||||||
|
|
||||||
verify(mockPreference, never()).setTitle(R.string.tethering_footer_info);
|
verify(mockPreference, never()).setTitle(R.string.tethering_footer_info);
|
||||||
verify(mockPreference).setTitle(R.string.tethering_footer_info_sta_ap_concurrency);
|
verify(mockPreference).setTitle(R.string.tethering_footer_info_sta_ap_concurrency);
|
||||||
@@ -201,25 +220,23 @@ public class TetherSettingsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBluetoothState_updateBluetoothState_bluetoothTetheringStateOn() {
|
public void testBluetoothState_updateBluetoothState_bluetoothTetheringStateOn() {
|
||||||
final TetherSettings spyTetherSettings = spy(new TetherSettings());
|
mTetherSettings.mTm = mTetheringManager;
|
||||||
spyTetherSettings.mContext = mContext;
|
|
||||||
spyTetherSettings.mTm = mTetheringManager;
|
|
||||||
final SwitchPreference mockSwitchPreference = mock(SwitchPreference.class);
|
final SwitchPreference mockSwitchPreference = mock(SwitchPreference.class);
|
||||||
when(spyTetherSettings.findPreference(TetherSettings.KEY_ENABLE_BLUETOOTH_TETHERING))
|
when(mTetherSettings.findPreference(TetherSettings.KEY_ENABLE_BLUETOOTH_TETHERING))
|
||||||
.thenReturn(mockSwitchPreference);
|
.thenReturn(mockSwitchPreference);
|
||||||
final FragmentActivity mockActivity = mock(FragmentActivity.class);
|
final FragmentActivity mockActivity = mock(FragmentActivity.class);
|
||||||
when(spyTetherSettings.getActivity()).thenReturn(mockActivity);
|
when(mTetherSettings.getActivity()).thenReturn(mockActivity);
|
||||||
final ArgumentCaptor<BroadcastReceiver> captor =
|
final ArgumentCaptor<BroadcastReceiver> captor =
|
||||||
ArgumentCaptor.forClass(BroadcastReceiver.class);
|
ArgumentCaptor.forClass(BroadcastReceiver.class);
|
||||||
when(mockActivity.registerReceiver(captor.capture(), any(IntentFilter.class)))
|
when(mockActivity.registerReceiver(captor.capture(), any(IntentFilter.class)))
|
||||||
.thenReturn(null);
|
.thenReturn(null);
|
||||||
// Bluetooth tethering state is on
|
// Bluetooth tethering state is on
|
||||||
when(spyTetherSettings.getBluetoothState()).thenReturn(BluetoothAdapter.STATE_ON);
|
when(mTetherSettings.getBluetoothState()).thenReturn(BluetoothAdapter.STATE_ON);
|
||||||
when(spyTetherSettings.isBluetoothTetheringOn()).thenReturn(true);
|
when(mTetherSettings.isBluetoothTetheringOn()).thenReturn(true);
|
||||||
|
|
||||||
spyTetherSettings.setupTetherPreference();
|
mTetherSettings.setupTetherPreference();
|
||||||
spyTetherSettings.registerReceiver();
|
mTetherSettings.registerReceiver();
|
||||||
updateOnlyBluetoothState(spyTetherSettings);
|
updateOnlyBluetoothState(mTetherSettings);
|
||||||
|
|
||||||
// Simulate Bluetooth tethering state changed
|
// Simulate Bluetooth tethering state changed
|
||||||
final BroadcastReceiver receiver = captor.getValue();
|
final BroadcastReceiver receiver = captor.getValue();
|
||||||
@@ -234,25 +251,23 @@ public class TetherSettingsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBluetoothState_updateBluetoothState_bluetoothTetheringStateOff() {
|
public void testBluetoothState_updateBluetoothState_bluetoothTetheringStateOff() {
|
||||||
final TetherSettings spyTetherSettings = spy(new TetherSettings());
|
mTetherSettings.mTm = mTetheringManager;
|
||||||
spyTetherSettings.mContext = mContext;
|
|
||||||
spyTetherSettings.mTm = mTetheringManager;
|
|
||||||
final SwitchPreference mockSwitchPreference = mock(SwitchPreference.class);
|
final SwitchPreference mockSwitchPreference = mock(SwitchPreference.class);
|
||||||
when(spyTetherSettings.findPreference(TetherSettings.KEY_ENABLE_BLUETOOTH_TETHERING))
|
when(mTetherSettings.findPreference(TetherSettings.KEY_ENABLE_BLUETOOTH_TETHERING))
|
||||||
.thenReturn(mockSwitchPreference);
|
.thenReturn(mockSwitchPreference);
|
||||||
final FragmentActivity mockActivity = mock(FragmentActivity.class);
|
final FragmentActivity mockActivity = mock(FragmentActivity.class);
|
||||||
when(spyTetherSettings.getActivity()).thenReturn(mockActivity);
|
when(mTetherSettings.getActivity()).thenReturn(mockActivity);
|
||||||
final ArgumentCaptor<BroadcastReceiver> captor =
|
final ArgumentCaptor<BroadcastReceiver> captor =
|
||||||
ArgumentCaptor.forClass(BroadcastReceiver.class);
|
ArgumentCaptor.forClass(BroadcastReceiver.class);
|
||||||
when(mockActivity.registerReceiver(captor.capture(), any(IntentFilter.class)))
|
when(mockActivity.registerReceiver(captor.capture(), any(IntentFilter.class)))
|
||||||
.thenReturn(null);
|
.thenReturn(null);
|
||||||
// Bluetooth tethering state is off
|
// Bluetooth tethering state is off
|
||||||
when(spyTetherSettings.getBluetoothState()).thenReturn(BluetoothAdapter.STATE_ON);
|
when(mTetherSettings.getBluetoothState()).thenReturn(BluetoothAdapter.STATE_ON);
|
||||||
when(spyTetherSettings.isBluetoothTetheringOn()).thenReturn(false);
|
when(mTetherSettings.isBluetoothTetheringOn()).thenReturn(false);
|
||||||
|
|
||||||
spyTetherSettings.setupTetherPreference();
|
mTetherSettings.setupTetherPreference();
|
||||||
spyTetherSettings.registerReceiver();
|
mTetherSettings.registerReceiver();
|
||||||
updateOnlyBluetoothState(spyTetherSettings);
|
updateOnlyBluetoothState(mTetherSettings);
|
||||||
|
|
||||||
// Simulate Bluetooth tethering state changed
|
// Simulate Bluetooth tethering state changed
|
||||||
final BroadcastReceiver receiver = captor.getValue();
|
final BroadcastReceiver receiver = captor.getValue();
|
||||||
@@ -268,16 +283,14 @@ public class TetherSettingsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void updateState_usbTetheringIsEnabled_checksUsbTethering() {
|
public void updateState_usbTetheringIsEnabled_checksUsbTethering() {
|
||||||
String [] tethered = {"rndis0"};
|
String [] tethered = {"rndis0"};
|
||||||
TetherSettings spyTetherSettings = spy(new TetherSettings());
|
|
||||||
RestrictedSwitchPreference tetheringPreference = mock(RestrictedSwitchPreference.class);
|
RestrictedSwitchPreference tetheringPreference = mock(RestrictedSwitchPreference.class);
|
||||||
when(spyTetherSettings.findPreference(TetherSettings.KEY_USB_TETHER_SETTINGS))
|
when(mTetherSettings.findPreference(TetherSettings.KEY_USB_TETHER_SETTINGS))
|
||||||
.thenReturn(tetheringPreference);
|
.thenReturn(tetheringPreference);
|
||||||
spyTetherSettings.mContext = mContext;
|
mTetherSettings.mTm = mTetheringManager;
|
||||||
spyTetherSettings.mTm = mTetheringManager;
|
mTetherSettings.setupTetherPreference();
|
||||||
spyTetherSettings.setupTetherPreference();
|
mTetherSettings.mUsbRegexs = tethered;
|
||||||
spyTetherSettings.mUsbRegexs = tethered;
|
|
||||||
|
|
||||||
spyTetherSettings.updateUsbState(tethered);
|
mTetherSettings.updateUsbState(tethered);
|
||||||
|
|
||||||
verify(tetheringPreference).setEnabled(true);
|
verify(tetheringPreference).setEnabled(true);
|
||||||
verify(tetheringPreference).setChecked(true);
|
verify(tetheringPreference).setChecked(true);
|
||||||
@@ -286,16 +299,14 @@ public class TetherSettingsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void updateState_usbTetheringIsDisabled_unchecksUsbTethering() {
|
public void updateState_usbTetheringIsDisabled_unchecksUsbTethering() {
|
||||||
String [] tethered = {"rndis0"};
|
String [] tethered = {"rndis0"};
|
||||||
TetherSettings spyTetherSettings = spy(new TetherSettings());
|
|
||||||
RestrictedSwitchPreference tetheringPreference = mock(RestrictedSwitchPreference.class);
|
RestrictedSwitchPreference tetheringPreference = mock(RestrictedSwitchPreference.class);
|
||||||
when(spyTetherSettings.findPreference(TetherSettings.KEY_USB_TETHER_SETTINGS))
|
when(mTetherSettings.findPreference(TetherSettings.KEY_USB_TETHER_SETTINGS))
|
||||||
.thenReturn(tetheringPreference);
|
.thenReturn(tetheringPreference);
|
||||||
spyTetherSettings.mContext = mContext;
|
mTetherSettings.mTm = mTetheringManager;
|
||||||
spyTetherSettings.mTm = mTetheringManager;
|
mTetherSettings.setupTetherPreference();
|
||||||
spyTetherSettings.setupTetherPreference();
|
mTetherSettings.mUsbRegexs = tethered;
|
||||||
spyTetherSettings.mUsbRegexs = tethered;
|
|
||||||
|
|
||||||
spyTetherSettings.updateUsbState(new String[0]);
|
mTetherSettings.updateUsbState(new String[0]);
|
||||||
|
|
||||||
verify(tetheringPreference).setEnabled(false);
|
verify(tetheringPreference).setEnabled(false);
|
||||||
verify(tetheringPreference).setChecked(false);
|
verify(tetheringPreference).setChecked(false);
|
||||||
@@ -362,6 +373,20 @@ public class TetherSettingsTest {
|
|||||||
verify(tetheringPreference, times(2)).setEnabled(true);
|
verify(tetheringPreference, times(2)).setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onDataSaverChanged_dataSaverEnabled_setToController() {
|
||||||
|
mTetherSettings.onDataSaverChanged(true);
|
||||||
|
|
||||||
|
verify(mWifiTetherPreferenceController).setDataSaverEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onDataSaverChanged_dataSaverDisabled_setToController() {
|
||||||
|
mTetherSettings.onDataSaverChanged(false);
|
||||||
|
|
||||||
|
verify(mWifiTetherPreferenceController).setDataSaverEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
private void updateOnlyBluetoothState(TetherSettings tetherSettings) {
|
private void updateOnlyBluetoothState(TetherSettings tetherSettings) {
|
||||||
doReturn(mTetheringManager).when(mContext)
|
doReturn(mTetheringManager).when(mContext)
|
||||||
.getSystemService(Context.TETHERING_SERVICE);
|
.getSystemService(Context.TETHERING_SERVICE);
|
||||||
@@ -391,21 +416,19 @@ public class TetherSettingsTest {
|
|||||||
|
|
||||||
private void setupUsbStateComponents(RestrictedSwitchPreference preference,
|
private void setupUsbStateComponents(RestrictedSwitchPreference preference,
|
||||||
ArgumentCaptor<BroadcastReceiver> captor, FragmentActivity activity) {
|
ArgumentCaptor<BroadcastReceiver> captor, FragmentActivity activity) {
|
||||||
TetherSettings spyTetherSettings = spy(new TetherSettings());
|
|
||||||
SwitchPreference mockSwitchPreference = mock(SwitchPreference.class);
|
SwitchPreference mockSwitchPreference = mock(SwitchPreference.class);
|
||||||
|
|
||||||
when(spyTetherSettings.findPreference(TetherSettings.KEY_USB_TETHER_SETTINGS))
|
when(mTetherSettings.findPreference(TetherSettings.KEY_USB_TETHER_SETTINGS))
|
||||||
.thenReturn(preference);
|
.thenReturn(preference);
|
||||||
when(spyTetherSettings.findPreference(TetherSettings.KEY_ENABLE_BLUETOOTH_TETHERING))
|
when(mTetherSettings.findPreference(TetherSettings.KEY_ENABLE_BLUETOOTH_TETHERING))
|
||||||
.thenReturn(mockSwitchPreference);
|
.thenReturn(mockSwitchPreference);
|
||||||
spyTetherSettings.mContext = mContext;
|
mTetherSettings.mTm = mTetheringManager;
|
||||||
spyTetherSettings.mTm = mTetheringManager;
|
when(mTetherSettings.getActivity()).thenReturn(activity);
|
||||||
when(spyTetherSettings.getActivity()).thenReturn(activity);
|
|
||||||
when(activity.registerReceiver(captor.capture(), any(IntentFilter.class)))
|
when(activity.registerReceiver(captor.capture(), any(IntentFilter.class)))
|
||||||
.thenReturn(null);
|
.thenReturn(null);
|
||||||
|
|
||||||
spyTetherSettings.setupTetherPreference();
|
mTetherSettings.setupTetherPreference();
|
||||||
spyTetherSettings.registerReceiver();
|
mTetherSettings.registerReceiver();
|
||||||
updateOnlyBluetoothState(spyTetherSettings);
|
updateOnlyBluetoothState(mTetherSettings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.settings.network.tether;
|
package com.android.settings.network.tether;
|
||||||
|
|
||||||
|
import static android.net.TetheringManager.TETHERING_WIFI;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
@@ -92,4 +94,18 @@ public class TetheringManagerModelTest {
|
|||||||
|
|
||||||
assertThat(mModel.mTetheredInterfaces.getValue()).isEqualTo(mInterfaces);
|
assertThat(mModel.mTetheredInterfaces.getValue()).isEqualTo(mInterfaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void startTethering_startTetheringToTetheringManager() {
|
||||||
|
mModel.startTethering(TETHERING_WIFI);
|
||||||
|
|
||||||
|
verify(mTetheringManager).startTethering(eq(TETHERING_WIFI), any(), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void stopTethering_stopTetheringToTetheringManager() {
|
||||||
|
mModel.stopTethering(TETHERING_WIFI);
|
||||||
|
|
||||||
|
verify(mTetheringManager).stopTethering(eq(TETHERING_WIFI));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,11 +16,15 @@
|
|||||||
|
|
||||||
package com.android.settings.wifi.tether;
|
package com.android.settings.wifi.tether;
|
||||||
|
|
||||||
|
import static android.net.TetheringManager.TETHERING_WIFI;
|
||||||
|
import static android.net.wifi.WifiManager.WIFI_AP_STATE_ENABLED;
|
||||||
|
|
||||||
import static com.android.settings.wifi.WifiUtils.setCanShowWifiHotspotCached;
|
import static com.android.settings.wifi.WifiUtils.setCanShowWifiHotspotCached;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -30,7 +34,9 @@ import android.net.wifi.WifiManager;
|
|||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
|
import com.android.settings.network.tether.TetheringManagerModel;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
import com.android.settings.widget.SwitchWidgetController;
|
||||||
import com.android.settingslib.PrimarySwitchPreference;
|
import com.android.settingslib.PrimarySwitchPreference;
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
@@ -66,6 +72,10 @@ public class WifiTetherPreferenceControllerTest {
|
|||||||
private WifiManager mWifiManager;
|
private WifiManager mWifiManager;
|
||||||
@Mock
|
@Mock
|
||||||
private PreferenceScreen mScreen;
|
private PreferenceScreen mScreen;
|
||||||
|
@Mock
|
||||||
|
TetheringManagerModel mTetheringManagerModel;
|
||||||
|
@Mock
|
||||||
|
private SwitchWidgetController mSwitch;
|
||||||
private SoftApConfiguration mSoftApConfiguration;
|
private SoftApConfiguration mSoftApConfiguration;
|
||||||
|
|
||||||
private WifiTetherPreferenceController mController;
|
private WifiTetherPreferenceController mController;
|
||||||
@@ -80,10 +90,13 @@ public class WifiTetherPreferenceControllerTest {
|
|||||||
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
||||||
mSoftApConfiguration = new SoftApConfiguration.Builder().setSsid(SSID).build();
|
mSoftApConfiguration = new SoftApConfiguration.Builder().setSsid(SSID).build();
|
||||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(mSoftApConfiguration);
|
when(mWifiManager.getSoftApConfiguration()).thenReturn(mSoftApConfiguration);
|
||||||
|
when(mWifiManager.getWifiApState()).thenReturn(WIFI_AP_STATE_ENABLED);
|
||||||
|
|
||||||
mController = new WifiTetherPreferenceController(mContext, mLifecycle, mWifiManager,
|
mController = new WifiTetherPreferenceController(mContext, mLifecycle, mWifiManager,
|
||||||
false /* initSoftApManager */, true /* isWifiTetheringAllow */);
|
false /* initSoftApManager */, true /* isWifiTetheringAllow */,
|
||||||
|
mTetheringManagerModel);
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
|
mController.mSwitch = mSwitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -103,7 +116,8 @@ public class WifiTetherPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void displayPreference_wifiTetheringNotAllowed_shouldDisable() {
|
public void displayPreference_wifiTetheringNotAllowed_shouldDisable() {
|
||||||
mController = new WifiTetherPreferenceController(mContext, mLifecycle, mWifiManager,
|
mController = new WifiTetherPreferenceController(mContext, mLifecycle, mWifiManager,
|
||||||
false /* initSoftApManager */, false /* isWifiTetheringAllow */);
|
false /* initSoftApManager */, false /* isWifiTetheringAllow */,
|
||||||
|
mTetheringManagerModel);
|
||||||
|
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
@@ -114,7 +128,8 @@ public class WifiTetherPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void displayPreference_wifiTetheringAllowed_shouldEnable() {
|
public void displayPreference_wifiTetheringAllowed_shouldEnable() {
|
||||||
mController = new WifiTetherPreferenceController(mContext, mLifecycle, mWifiManager,
|
mController = new WifiTetherPreferenceController(mContext, mLifecycle, mWifiManager,
|
||||||
false /* initSoftApManager */, true /* isWifiTetheringAllow */);
|
false /* initSoftApManager */, true /* isWifiTetheringAllow */,
|
||||||
|
mTetheringManagerModel);
|
||||||
|
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
@@ -130,7 +145,7 @@ public class WifiTetherPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHandleWifiApStateChanged_stateEnabled_showEnabledSummary() {
|
public void testHandleWifiApStateChanged_stateEnabled_showEnabledSummary() {
|
||||||
mController.handleWifiApStateChanged(WifiManager.WIFI_AP_STATE_ENABLED, 0 /* reason */);
|
mController.handleWifiApStateChanged(WIFI_AP_STATE_ENABLED, 0 /* reason */);
|
||||||
|
|
||||||
assertThat(mPreference.getSummary()).isEqualTo("Pixel is active");
|
assertThat(mPreference.getSummary()).isEqualTo("Pixel is active");
|
||||||
}
|
}
|
||||||
@@ -150,6 +165,53 @@ public class WifiTetherPreferenceControllerTest {
|
|||||||
"Not sharing internet or content with other devices");
|
"Not sharing internet or content with other devices");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void handleWifiApStateChanged_stateDisabled_setSwitchUnchecked() {
|
||||||
|
mController.handleWifiApStateChanged(WifiManager.WIFI_AP_STATE_DISABLED, 0 /* reason */);
|
||||||
|
|
||||||
|
verify(mSwitch).setChecked(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void handleWifiApStateChanged_stateEnabled_setSwitchChecked() {
|
||||||
|
mController.handleWifiApStateChanged(WIFI_AP_STATE_ENABLED, 0 /* reason */);
|
||||||
|
|
||||||
|
verify(mSwitch).setChecked(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setDataSaverEnabled_setEnabled_setPrefDisabled() {
|
||||||
|
mController.setDataSaverEnabled(true);
|
||||||
|
|
||||||
|
assertThat(mPreference.isEnabled()).isFalse();
|
||||||
|
verify(mSwitch).setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setDataSaverEnabled_setDisabled_setPrefEnabled() {
|
||||||
|
mController.setDataSaverEnabled(false);
|
||||||
|
|
||||||
|
assertThat(mPreference.isEnabled()).isTrue();
|
||||||
|
verify(mSwitch).setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onSwitchToggled_isChecked_startTethering() {
|
||||||
|
boolean ret = mController.onSwitchToggled(true);
|
||||||
|
|
||||||
|
verify(mTetheringManagerModel).startTethering(TETHERING_WIFI);
|
||||||
|
assertThat(ret).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onSwitchToggled_isUnchecked_stopTethering() {
|
||||||
|
boolean ret = mController.onSwitchToggled(false);
|
||||||
|
|
||||||
|
verify(mTetheringManagerModel).stopTethering(TETHERING_WIFI);
|
||||||
|
assertThat(ret).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Implements(WifiTetherSettings.class)
|
@Implements(WifiTetherSettings.class)
|
||||||
public static final class ShadowWifiTetherSettings {
|
public static final class ShadowWifiTetherSettings {
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user