Add config for Wi-Fi Hotspot Settings hidden
- Add config_show_wifi_hotspot_settings for Settings customization
- Hide Wi-Fi Hotspot preference in Hotspot & tethering Settings
- Don't launch Wi-Fi Hotspot Settings (e.g long press on Hotspot in QS-tile)
Bug: 213426762
Test: manual test
atest -c com.android.settings.wifi.WifiUtilsTest
make RunSettingsRoboTests ROBOTEST_FILTER=WifiTetherPreferenceControllerTest
make RunSettingsRoboTests ROBOTEST_FILTER=WifiTetherSettingsTest
Merged-In: I11f88d0d15d6d5c2766b64b5847ac31ed0f34c25
Change-Id: I11f88d0d15d6d5c2766b64b5847ac31ed0f34c25
(cherry picked from commit 160b5078ed)
This commit is contained in:
@@ -16,13 +16,14 @@
|
||||
|
||||
package com.android.settings.wifi.tether;
|
||||
|
||||
import static com.android.settings.wifi.WifiUtils.setCanShowWifiHotspotCached;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.TetheringManager;
|
||||
import android.net.wifi.SoftApConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
@@ -62,8 +63,6 @@ public class WifiTetherPreferenceControllerTest {
|
||||
@Mock
|
||||
private Lifecycle mLifecycle;
|
||||
@Mock
|
||||
private TetheringManager mTetheringManager;
|
||||
@Mock
|
||||
private WifiManager mWifiManager;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@@ -74,38 +73,37 @@ public class WifiTetherPreferenceControllerTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
setCanShowWifiHotspotCached(true);
|
||||
FakeFeatureFactory.setupForTest();
|
||||
mPreference = new PrimarySwitchPreference(mContext);
|
||||
when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
|
||||
when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
|
||||
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
||||
mSoftApConfiguration = new SoftApConfiguration.Builder().setSsid(SSID).build();
|
||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(mSoftApConfiguration);
|
||||
|
||||
when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
|
||||
mController = new WifiTetherPreferenceController(mContext, mLifecycle, mWifiManager,
|
||||
mTetheringManager, false /* initSoftApManager */, true /* isWifiTetheringAllow */);
|
||||
false /* initSoftApManager */, true /* isWifiTetheringAllow */);
|
||||
mController.displayPreference(mScreen);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_noTetherRegex_shouldReturnFalse() {
|
||||
when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{});
|
||||
mController = new WifiTetherPreferenceController(mContext, mLifecycle, mWifiManager,
|
||||
mTetheringManager, false /* initSoftApManager */, true /* isWifiTetheringAllow */);
|
||||
public void isAvailable_canNotShowWifiHotspot_shouldReturnFalse() {
|
||||
setCanShowWifiHotspotCached(false);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_hasTetherRegex_shouldReturnTrue() {
|
||||
public void isAvailable_canShowWifiHostspot_shouldReturnTrue() {
|
||||
setCanShowWifiHotspotCached(true);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_wifiTetheringNotAllowed_shouldDisable() {
|
||||
mController = new WifiTetherPreferenceController(mContext, mLifecycle, mWifiManager,
|
||||
mTetheringManager, false /* initSoftApManager */, false /* isWifiTetheringAllow */);
|
||||
false /* initSoftApManager */, false /* isWifiTetheringAllow */);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
@@ -116,7 +114,7 @@ public class WifiTetherPreferenceControllerTest {
|
||||
@Test
|
||||
public void displayPreference_wifiTetheringAllowed_shouldEnable() {
|
||||
mController = new WifiTetherPreferenceController(mContext, mLifecycle, mWifiManager,
|
||||
mTetheringManager, false /* initSoftApManager */, true /* isWifiTetheringAllow */);
|
||||
false /* initSoftApManager */, true /* isWifiTetheringAllow */);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.wifi.tether;
|
||||
|
||||
import static com.android.settings.wifi.WifiUtils.setCanShowWifiHotspotCached;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -42,6 +44,7 @@ import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.RestrictedDashboardFragment;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.shadow.ShadowFragment;
|
||||
|
||||
@@ -55,6 +58,8 @@ import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.List;
|
||||
@@ -88,6 +93,7 @@ public class WifiTetherSettingsTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
setCanShowWifiHotspotCached(true);
|
||||
doReturn(mWifiManager).when(mContext).getSystemService(WifiManager.class);
|
||||
doReturn(mConnectivityManager)
|
||||
.when(mContext).getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
@@ -100,6 +106,17 @@ public class WifiTetherSettingsTest {
|
||||
mWifiTetherSettings = new WifiTetherSettings(mWifiRestriction);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowRestrictedDashboardFragment.class)
|
||||
public void onCreate_canNotShowWifiHotspot_shouldFinish() {
|
||||
setCanShowWifiHotspotCached(false);
|
||||
mWifiTetherSettings = spy(new WifiTetherSettings(mWifiRestriction));
|
||||
|
||||
mWifiTetherSettings.onCreate(null);
|
||||
|
||||
verify(mWifiTetherSettings).finish();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowFragment.class)
|
||||
public void onStart_uiIsRestricted_removeAllPreferences() {
|
||||
@@ -219,4 +236,13 @@ public class WifiTetherSettingsTest {
|
||||
|
||||
mWifiTetherSettings.onCreate(Bundle.EMPTY);
|
||||
}
|
||||
|
||||
@Implements(RestrictedDashboardFragment.class)
|
||||
public static final class ShadowRestrictedDashboardFragment {
|
||||
|
||||
@Implementation
|
||||
public void onCreate(Bundle icicle) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user