Merge "Add config for Wi-Fi Hotspot Settings hidden" into tm-qpr-dev am: 87d2f6d3cb

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/20244146

Change-Id: I7b3275ffad2af79bb81c3761b691ab793a61168a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
TreeHugger Robot
2022-10-24 03:26:46 +00:00
committed by Automerger Merge Worker
7 changed files with 204 additions and 24 deletions

View File

@@ -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);

View File

@@ -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
}
}
}

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();
}
}