Clean up AllInOneTetherSettings

This project is not on-going.

Clean up to help improve latency.

Bug: 311604902
Test: manual - on Network & internet page
Test: robo test
Change-Id: I6addb92e5587206661d1b64bdc56473a85ba9c9f
This commit is contained in:
Chaohui Wang
2023-11-30 12:03:51 +08:00
parent f04ee0dfab
commit 0664d3cc45
29 changed files with 8 additions and 2774 deletions

View File

@@ -1,187 +0,0 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.network;
import static com.android.settings.network.TetherEnabler.TETHERING_BLUETOOTH_ON;
import static com.android.settings.network.TetherEnabler.TETHERING_ETHERNET_ON;
import static com.android.settings.network.TetherEnabler.TETHERING_OFF;
import static com.android.settings.network.TetherEnabler.TETHERING_USB_ON;
import static com.android.settings.network.TetherEnabler.TETHERING_WIFI_ON;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothPan;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
import com.android.settingslib.PrimarySwitchPreference;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.ParameterizedRobolectricTestRunner;
import org.robolectric.util.ReflectionHelpers;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
@RunWith(ParameterizedRobolectricTestRunner.class)
public class AllInOneTetherPreferenceControllerTest {
@ParameterizedRobolectricTestRunner.Parameters(name = "TetherState: {0}")
public static List params() {
return Arrays.asList(new Object[][] {
{TETHERING_OFF, R.string.tether_settings_summary_off},
{TETHERING_WIFI_ON, R.string.tether_settings_summary_hotspot_only},
{TETHERING_USB_ON, R.string.tether_settings_summary_usb_tethering_only},
{TETHERING_BLUETOOTH_ON, R.string.tether_settings_summary_bluetooth_tethering_only},
{TETHERING_ETHERNET_ON, R.string.tether_settings_summary_ethernet_tethering_only},
{
TETHERING_WIFI_ON | TETHERING_USB_ON,
R.string.tether_settings_summary_hotspot_and_usb
},
{
TETHERING_WIFI_ON | TETHERING_BLUETOOTH_ON,
R.string.tether_settings_summary_hotspot_and_bluetooth
},
{
TETHERING_WIFI_ON | TETHERING_ETHERNET_ON,
R.string.tether_settings_summary_hotspot_and_ethernet
},
{
TETHERING_USB_ON | TETHERING_BLUETOOTH_ON,
R.string.tether_settings_summary_usb_and_bluetooth
},
{
TETHERING_USB_ON | TETHERING_ETHERNET_ON,
R.string.tether_settings_summary_usb_and_ethernet
},
{
TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON,
R.string.tether_settings_summary_bluetooth_and_ethernet
},
{
TETHERING_WIFI_ON | TETHERING_USB_ON | TETHERING_BLUETOOTH_ON,
R.string.tether_settings_summary_hotspot_and_usb_and_bluetooth
},
{
TETHERING_WIFI_ON | TETHERING_USB_ON | TETHERING_ETHERNET_ON,
R.string.tether_settings_summary_hotspot_and_usb_and_ethernet
},
{
TETHERING_WIFI_ON | TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON,
R.string.tether_settings_summary_hotspot_and_bluetooth_and_ethernet
},
{
TETHERING_USB_ON | TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON,
R.string.tether_settings_summary_usb_and_bluetooth_and_ethernet
},
{
TETHERING_WIFI_ON | TETHERING_USB_ON | TETHERING_BLUETOOTH_ON
| TETHERING_ETHERNET_ON,
R.string.tether_settings_summary_all
}
});
}
private Context mContext;
@Mock
private BluetoothAdapter mBluetoothAdapter;
@Mock
private PrimarySwitchPreference mPreference;
private static final String PREF_KEY = "tether";
private AllInOneTetherPreferenceController mController;
private final int mTetherState;
private final int mSummaryResId;
public AllInOneTetherPreferenceControllerTest(int tetherState, int summaryResId) {
mTetherState = tetherState;
mSummaryResId = summaryResId;
}
@Before
public void setUp() {
mContext = spy(ApplicationProvider.getApplicationContext());
MockitoAnnotations.initMocks(this);
doReturn(null).when(mContext)
.getSystemService(Context.DEVICE_POLICY_SERVICE);
mController = spy(new AllInOneTetherPreferenceController(mContext, /* key= */ "test"));
ReflectionHelpers.setField(mController, "mContext", mContext);
ReflectionHelpers.setField(mController, "mBluetoothAdapter", mBluetoothAdapter);
ReflectionHelpers.setField(mController, "mPreferenceKey", PREF_KEY);
PreferenceScreen screen = mock(PreferenceScreen.class);
when(screen.findPreference(PREF_KEY)).thenReturn(mPreference);
doReturn(mController.AVAILABLE).when(mController).getAvailabilityStatus();
mController.displayPreference(screen);
}
@Test
public void onCreate_shouldInitBluetoothPan() {
when(mBluetoothAdapter.getState()).thenReturn(BluetoothAdapter.STATE_ON);
mController.onCreate();
verify(mBluetoothAdapter).getState();
verify(mBluetoothAdapter).getProfileProxy(mContext, mController.mBtProfileServiceListener,
BluetoothProfile.PAN);
}
@Test
public void onCreate_shouldNotInitBluetoothPanWhenBluetoothOff() {
when(mBluetoothAdapter.getState()).thenReturn(BluetoothAdapter.STATE_OFF);
mController.onCreate();
verify(mBluetoothAdapter).getState();
verifyNoMoreInteractions(mBluetoothAdapter);
}
@Test
public void goThroughLifecycle_shouldDestroyBluetoothProfile() {
final BluetoothPan pan = mock(BluetoothPan.class);
final AtomicReference<BluetoothPan> panRef =
ReflectionHelpers.getField(mController, "mBluetoothPan");
panRef.set(pan);
mController.onDestroy();
verify(mBluetoothAdapter).closeProfileProxy(BluetoothProfile.PAN, pan);
}
@Test
public void getSummary_afterTetherStateChanged() {
mController.onTetherStateUpdated(mTetherState);
assertThat(mController.getSummary()).isEqualTo(mContext.getString(mSummaryResId));
verify(mController).updateState(mPreference);
verify(mPreference).setSummary(mContext.getString(mSummaryResId));
}
}

View File

@@ -1,132 +0,0 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.network;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.net.TetheringManager;
import androidx.preference.SwitchPreference;
import androidx.test.core.app.ApplicationProvider;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.util.ReflectionHelpers;
@RunWith(RobolectricTestRunner.class)
public class BluetoothTetherPreferenceControllerTest {
@Mock
private TetheringManager mTetheringManager;
@Mock
private TetherEnabler mTetherEnabler;
private SwitchPreference mSwitchPreference;
private BluetoothTetherPreferenceController mController;
private Context mContext;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(ApplicationProvider.getApplicationContext());
mSwitchPreference = spy(SwitchPreference.class);
when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[] {""});
mController = new BluetoothTetherPreferenceController(mContext, "BLUETOOTH");
mController.setTetherEnabler(mTetherEnabler);
ReflectionHelpers.setField(mController, "mPreference", mSwitchPreference);
}
@Test
public void lifecycle_shouldRegisterReceiverOnStart() {
mController.onStart();
verify(mContext).registerReceiver(
eq(mController.mBluetoothChangeReceiver),
any());
}
@Test
public void lifecycle_shouldAddListenerOnResume() {
mController.onResume();
verify(mTetherEnabler).addListener(mController);
}
@Test
public void lifecycle_shouldRemoveListenrOnPause() {
mController.onPause();
verify(mTetherEnabler).removeListener(mController);
}
@Test
public void lifecycle_shouldUnregisterReceiverOnStop() {
mController.onStart();
mController.onStop();
verify(mContext).unregisterReceiver(
eq(mController.mBluetoothChangeReceiver));
}
@Test
public void shouldShow_noBluetoothTetherable() {
when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[0]);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void shouldEnable_transientState() {
ReflectionHelpers.setField(mController, "mBluetoothState",
BluetoothAdapter.STATE_TURNING_OFF);
assertThat(mController.shouldEnable()).isFalse();
}
@Test
public void setChecked_shouldStartBluetoothTethering() {
mController.setChecked(true);
verify(mTetherEnabler).startTethering(TetheringManager.TETHERING_BLUETOOTH);
}
@Test
public void setUnchecked_shouldStopBluetoothTethering() {
mController.setChecked(false);
verify(mTetherEnabler).stopTethering(TetheringManager.TETHERING_BLUETOOTH);
}
@Test
public void switch_shouldCheckedWhenBluetoothTethering() {
mController.onTetherStateUpdated(TetherEnabler.TETHERING_BLUETOOTH_ON);
assertThat(mController.isChecked()).isTrue();
}
@Test
public void switch_shouldUnCheckedWhenBluetoothNotTethering() {
mController.onTetherStateUpdated(TetherEnabler.TETHERING_OFF);
assertThat(mController.isChecked()).isFalse();
}
}

View File

@@ -1,143 +0,0 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.network;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.net.EthernetManager;
import android.net.TetheringManager;
import androidx.preference.SwitchPreference;
import androidx.test.core.app.ApplicationProvider;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.util.ReflectionHelpers;
@RunWith(RobolectricTestRunner.class)
public class EthernetTetherPreferenceControllerTest {
@Rule
public MockitoRule mocks = MockitoJUnit.rule();
@Mock
private TetheringManager mTetheringManager;
@Mock
private EthernetManager mEthernetManager;
@Mock
private TetherEnabler mTetherEnabler;
private Context mContext;
private EthernetTetherPreferenceController mController;
private SwitchPreference mPreference;
private static final String ETHERNET_REGEX = "ethernet";
@Before
public void setUp() {
mContext = spy(ApplicationProvider.getApplicationContext());
mPreference = spy(SwitchPreference.class);
when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
when(mTetheringManager.getTetherableIfaces()).thenReturn(new String[]{ETHERNET_REGEX});
when(mContext.getSystemService(EthernetManager.class)).thenReturn(mEthernetManager);
mController = new EthernetTetherPreferenceController(mContext, "ethernet");
mController.setTetherEnabler(mTetherEnabler);
ReflectionHelpers.setField(mController, "mPreference", mPreference);
}
@Test
@Ignore
public void lifecycle_shouldRegisterReceiverOnStart() {
mController.onStart();
verify(mEthernetManager).addInterfaceStateListener(any(),
eq(mController.mEthernetListener));
}
@Test
public void lifecycle_shouldAddListenerOnResume() {
mController.onResume();
verify(mTetherEnabler).addListener(mController);
}
@Test
public void lifecycle_shouldRemoveListenerOnPause() {
mController.onPause();
verify(mTetherEnabler).removeListener(mController);
}
@Test
public void lifecycle_shouldUnregisterReceiverOnStop() {
mController.onStart();
EthernetManager.InterfaceStateListener listener = mController.mEthernetListener;
mController.onStop();
verify(mEthernetManager).removeInterfaceStateListener(eq(listener));
}
@Test
public void shouldEnable_noTetherable() {
when(mTetheringManager.getTetherableIfaces()).thenReturn(new String[0]);
assertThat(mController.shouldEnable()).isFalse();
}
@Test
public void shouldShow_noEthernetInterface() {
when(mContext.getSystemService(EthernetManager.class)).thenReturn(null);
final EthernetTetherPreferenceController controller =
new EthernetTetherPreferenceController(mContext, "ethernet");
assertThat(controller.shouldShow()).isFalse();
}
@Test
public void setChecked_shouldStartEthernetTethering() {
mController.setChecked(true);
verify(mTetherEnabler).startTethering(TetheringManager.TETHERING_ETHERNET);
}
@Test
public void setUnchecked_shouldStopEthernetTethering() {
mController.setChecked(false);
verify(mTetherEnabler).stopTethering(TetheringManager.TETHERING_ETHERNET);
}
@Test
public void switch_shouldCheckedWhenEthernetTethering() {
mController.onTetherStateUpdated(TetherEnabler.TETHERING_ETHERNET_ON);
assertThat(mController.isChecked()).isTrue();
}
@Test
public void switch_shouldUnCheckedWhenEthernetNotTethering() {
mController.onTetherStateUpdated(TetherEnabler.TETHERING_OFF);
assertThat(mController.isChecked()).isFalse();
}
}

View File

@@ -1,128 +0,0 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.network;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.net.TetheringManager;
import androidx.preference.SwitchPreference;
import androidx.test.core.app.ApplicationProvider;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.util.ReflectionHelpers;
@RunWith(RobolectricTestRunner.class)
public class UsbTetherPreferenceControllerTest {
@Mock
private TetheringManager mTetheringManager;
@Mock
private TetherEnabler mTetherEnabler;
private Context mContext;
private UsbTetherPreferenceController mController;
private SwitchPreference mSwitchPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(ApplicationProvider.getApplicationContext());
when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[]{""});
mController = new UsbTetherPreferenceController(mContext, "USB");
mController.setTetherEnabler(mTetherEnabler);
mSwitchPreference = spy(SwitchPreference.class);
ReflectionHelpers.setField(mController, "mPreference", mSwitchPreference);
}
@Test
public void lifecycle_shouldRegisterReceiverOnStart() {
mController.onStart();
verify(mContext).registerReceiver(eq(mController.mUsbChangeReceiver), any());
}
@Test
public void lifecycle_shouldAddListenerOnResume() {
mController.onResume();
verify(mTetherEnabler).addListener(mController);
}
@Test
public void lifecycle_shouldRemoveListenrOnPause() {
mController.onPause();
verify(mTetherEnabler).removeListener(mController);
}
@Test
public void lifecycle_shouldUnregisterReceiverOnStop() {
mController.onStart();
mController.onStop();
verify(mContext).unregisterReceiver(eq(mController.mUsbChangeReceiver));
}
@Test
public void shouldShow_noTetherableUsb() {
when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
assertThat(mController.shouldShow()).isFalse();
}
@Test
public void shouldEnable_noUsbConnected() {
ReflectionHelpers.setField(mController, "mUsbConnected", false);
assertThat(mController.shouldEnable()).isFalse();
}
@Test
public void setChecked_shouldStartUsbTethering() {
mController.setChecked(true);
verify(mTetherEnabler).startTethering(TetheringManager.TETHERING_USB);
}
@Test
public void setUnchecked_shouldStopUsbTethering() {
mController.setChecked(false);
verify(mTetherEnabler).stopTethering(TetheringManager.TETHERING_USB);
}
@Test
public void switch_shouldCheckedWhenUsbTethering() {
mController.onTetherStateUpdated(TetherEnabler.TETHERING_USB_ON);
assertThat(mController.isChecked()).isTrue();
}
@Test
public void switch_shouldUnCheckedWhenUsbNotTethering() {
mController.onTetherStateUpdated(TetherEnabler.TETHERING_OFF);
assertThat(mController.isChecked()).isFalse();
}
}

View File

@@ -1,142 +0,0 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.network;
import static com.android.settings.AllInOneTetherSettings.WIFI_TETHER_DISABLE_KEY;
import static com.android.settings.network.TetherEnabler.TETHERING_BLUETOOTH_ON;
import static com.android.settings.network.TetherEnabler.TETHERING_ETHERNET_ON;
import static com.android.settings.network.TetherEnabler.TETHERING_OFF;
import static com.android.settings.network.TetherEnabler.TETHERING_USB_ON;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.net.TetheringManager;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.ParameterizedRobolectricTestRunner;
import org.robolectric.util.ReflectionHelpers;
import java.util.Arrays;
import java.util.List;
@RunWith(ParameterizedRobolectricTestRunner.class)
public class WifiTetherDisablePreferenceControllerTest {
@ParameterizedRobolectricTestRunner.Parameters(name = "TetherState: {0}")
public static List params() {
return Arrays.asList(new Object[][] {
{TETHERING_OFF, R.string.summary_placeholder},
{TETHERING_USB_ON, R.string.disable_wifi_hotspot_when_usb_on},
{TETHERING_BLUETOOTH_ON, R.string.disable_wifi_hotspot_when_bluetooth_on},
{TETHERING_ETHERNET_ON, R.string.disable_wifi_hotspot_when_ethernet_on},
{
TETHERING_USB_ON | TETHERING_BLUETOOTH_ON,
R.string.disable_wifi_hotspot_when_usb_and_bluetooth_on
},
{
TETHERING_USB_ON | TETHERING_ETHERNET_ON,
R.string.disable_wifi_hotspot_when_usb_and_ethernet_on
},
{
TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON,
R.string.disable_wifi_hotspot_when_bluetooth_and_ethernet_on
},
{
TETHERING_USB_ON | TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON,
R.string.disable_wifi_hotspot_when_usb_and_bluetooth_and_ethernet_on
}
});
}
@Mock
private TetheringManager mTetheringManager;
@Mock
private PreferenceScreen mPreferenceScreen;
@Mock
private TetherEnabler mTetherEnabler;
private SwitchPreference mPreference;
private Context mContext;
private WifiTetherDisablePreferenceController mController;
private final int mTetherState;
private final int mSummaryResId;
public WifiTetherDisablePreferenceControllerTest(int tetherState, int summaryResId) {
mTetherState = tetherState;
mSummaryResId = summaryResId;
}
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(ApplicationProvider.getApplicationContext());
mPreference = spy(SwitchPreference.class);
when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{""});
mController = new WifiTetherDisablePreferenceController(mContext, WIFI_TETHER_DISABLE_KEY);
mController.setTetherEnabler(mTetherEnabler);
ReflectionHelpers.setField(mController, "mScreen", mPreferenceScreen);
ReflectionHelpers.setField(mController, "mPreference", mPreference);
when(mPreferenceScreen.findPreference(WIFI_TETHER_DISABLE_KEY)).thenReturn(mPreference);
}
@Test
public void shouldShow_noTetherableWifi() {
when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[0]);
assertThat(mController.shouldShow()).isFalse();
}
@Test
public void onTetherStateUpdated_visibilityChangeCorrectly() {
int state = TetherEnabler.TETHERING_BLUETOOTH_ON;
mController.onTetherStateUpdated(state);
assertThat(mController.shouldShow()).isTrue();
state |= TetherEnabler.TETHERING_USB_ON;
mController.onTetherStateUpdated(state);
assertThat(mController.shouldShow()).isTrue();
state = TetherEnabler.TETHERING_USB_ON;
mController.onTetherStateUpdated(state);
assertThat(mController.shouldShow()).isTrue();
state = TetherEnabler.TETHERING_OFF;
mController.onTetherStateUpdated(state);
assertThat(mController.shouldShow()).isFalse();
}
@Test
public void getSummary_onTetherStateUpdated() {
mController.onTetherStateUpdated(mTetherState);
assertThat(mController.getSummary()).isEqualTo(mContext.getString(mSummaryResId));
}
}

View File

@@ -48,7 +48,6 @@ import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.FeatureFlagUtils;
import androidx.fragment.app.FragmentActivity;
import androidx.preference.Preference;
@@ -56,7 +55,6 @@ import androidx.preference.SwitchPreference;
import com.android.settings.R;
import com.android.settings.RestrictedSettingsFragment;
import com.android.settings.core.FeatureFlags;
import com.android.settings.wifi.tether.WifiTetherPreferenceController;
import com.android.settingslib.RestrictedSwitchPreference;
@@ -145,7 +143,6 @@ public class TetherSettingsTest {
@Test
public void testTetherNonIndexableKeys_tetherAvailable_keysNotReturned() {
FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, false);
// To let TetherUtil.isTetherAvailable return true, select one of the combinations
setupIsTetherAvailable(true);
@@ -190,7 +187,6 @@ public class TetherSettingsTest {
@Test
public void testTetherNonIndexableKeys_usbAvailable_usbKeyNotReturned() {
FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, false);
// We can ignore the condition of Utils.isMonkeyRunning()
// In normal case, monkey and robotest should not execute at the same time
when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[]{"fakeRegex"});
@@ -213,7 +209,6 @@ public class TetherSettingsTest {
@Test
public void testTetherNonIndexableKeys_bluetoothAvailable_bluetoothKeyNotReturned() {
FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, false);
when(mTetheringManager.getTetherableBluetoothRegexs())
.thenReturn(new String[]{"fakeRegex"});