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:
Weng Su
2022-10-18 04:08:13 +08:00
parent 062b18c736
commit f9b5e046a8
7 changed files with 204 additions and 24 deletions

View File

@@ -21,19 +21,53 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.res.Resources;
import android.net.TetheringManager;
import android.net.wifi.SoftApConfiguration;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.settings.R;
import com.android.wifitrackerlib.WifiEntry;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
@RunWith(AndroidJUnit4.class)
public class WifiUtilsTest {
static final String[] WIFI_REGEXS = {"wifi_regexs"};
@Rule
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
@Spy
Context mContext = ApplicationProvider.getApplicationContext();
@Mock
Resources mResources;
@Mock
WifiManager mWifiManager;
@Mock
TetheringManager mTetheringManager;
@Before
public void setUp() {
when(mContext.getResources()).thenReturn(mResources);
when(mResources.getBoolean(R.bool.config_show_wifi_hotspot_settings)).thenReturn(true);
when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
when(mContext.getSystemService(TetheringManager.class)).thenReturn(mTetheringManager);
when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(WIFI_REGEXS);
}
@Test
public void testSSID() {
assertThat(WifiUtils.isSSIDTooLong("123")).isFalse();
@@ -108,4 +142,53 @@ public class WifiUtilsTest {
WifiConfiguration config = WifiUtils.getWifiConfig(null /* wifiEntry */,
null /* scanResult */);
}
@Test
public void checkShowWifiHotspot_allReady_returnTrue() {
assertThat(WifiUtils.checkShowWifiHotspot(mContext)).isTrue();
}
@Test
public void checkShowWifiHotspot_contextIsNull_returnFalse() {
assertThat(WifiUtils.checkShowWifiHotspot(null)).isFalse();
}
@Test
public void checkShowWifiHotspot_configIsNotShow_returnFalse() {
when(mResources.getBoolean(R.bool.config_show_wifi_hotspot_settings)).thenReturn(false);
assertThat(WifiUtils.checkShowWifiHotspot(mContext)).isFalse();
}
@Test
public void checkShowWifiHotspot_wifiManagerIsNull_returnFalse() {
when(mContext.getSystemService(WifiManager.class)).thenReturn(null);
assertThat(WifiUtils.checkShowWifiHotspot(mContext)).isFalse();
}
@Test
public void checkShowWifiHotspot_tetheringManagerIsNull_returnFalse() {
when(mContext.getSystemService(TetheringManager.class)).thenReturn(null);
assertThat(WifiUtils.checkShowWifiHotspot(mContext)).isFalse();
}
@Test
public void checkShowWifiHotspot_wifiRegexsIsEmpty_returnFalse() {
when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(null);
assertThat(WifiUtils.checkShowWifiHotspot(mContext)).isFalse();
}
@Test
public void canShowWifiHotspot_cachedIsReady_returnCached() {
WifiUtils.setCanShowWifiHotspotCached(true);
assertThat(WifiUtils.canShowWifiHotspot(null)).isTrue();
WifiUtils.setCanShowWifiHotspotCached(false);
assertThat(WifiUtils.canShowWifiHotspot(null)).isFalse();
}
}