Merge "Add Instant hotspot preference" into udc-qpr-dev

This commit is contained in:
Treehugger Robot
2023-08-22 14:36:05 +00:00
committed by Android (Google) Code Review
9 changed files with 582 additions and 4 deletions

View File

@@ -23,6 +23,7 @@ import static android.view.View.VISIBLE;
import static com.android.settings.wifi.WifiUtils.setCanShowWifiHotspotCached;
import static com.android.settings.wifi.repository.WifiHotspotRepository.BAND_2GHZ_5GHZ_6GHZ;
import static com.android.settings.wifi.tether.WifiTetherSettings.KEY_INSTANT_HOTSPOT;
import static com.android.settings.wifi.tether.WifiTetherSettings.KEY_WIFI_HOTSPOT_SECURITY;
import static com.android.settings.wifi.tether.WifiTetherSettings.KEY_WIFI_HOTSPOT_SPEED;
@@ -90,6 +91,7 @@ public class WifiTetherSettingsTest {
private static final String[] WIFI_REGEXS = {"wifi_regexs"};
private static final String SSID = "ssid";
private static final String PASSWORD = "password";
private static final String SUMMARY = "summary";
@Rule
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
@@ -133,6 +135,10 @@ public class WifiTetherSettingsTest {
private WifiTetherAutoOffPreferenceController mWifiTetherAutoOffPreferenceController;
@Mock
private WifiTetherMaximizeCompatibilityPreferenceController mMaxCompatibilityPrefController;
@Mock
private Preference mInstantHotspot;
@Mock
private LiveData<String> mInstantHotspotSummary;
private WifiTetherSettings mSettings;
@@ -155,8 +161,10 @@ public class WifiTetherSettingsTest {
when(provider.getWifiTetherViewModel(mock(ViewModelStoreOwner.class)))
.thenReturn(mWifiTetherViewModel);
when(mWifiTetherViewModel.isSpeedFeatureAvailable()).thenReturn(false);
when(mWifiTetherViewModel.isInstantHotspotFeatureAvailable()).thenReturn(true);
when(mWifiTetherViewModel.getSecuritySummary()).thenReturn(mSecuritySummary);
when(mWifiTetherViewModel.getSpeedSummary()).thenReturn(mSpeedSummary);
when(mWifiTetherViewModel.getInstantHotspotSummary()).thenReturn(mInstantHotspotSummary);
mSettings = spy(new WifiTetherSettings(mWifiRestriction));
mSettings.mMainSwitchBar = mMainSwitchBar;
@@ -172,6 +180,8 @@ public class WifiTetherSettingsTest {
mSettings.mWifiTetherViewModel = mWifiTetherViewModel;
when(mSettings.findPreference(KEY_WIFI_HOTSPOT_SECURITY)).thenReturn(mWifiHotspotSecurity);
when(mSettings.findPreference(KEY_WIFI_HOTSPOT_SPEED)).thenReturn(mWifiHotspotSpeed);
when(mSettings.findPreference(KEY_INSTANT_HOTSPOT)).thenReturn(mInstantHotspot);
mSettings.mInstantHotspot = mInstantHotspot;
}
@Test
@@ -372,6 +382,47 @@ public class WifiTetherSettingsTest {
verify(mSettings).setLoading(true, false);
}
@Test
public void setupInstantHotspot_featureNotAvailable_doNothing() {
mSettings.setupInstantHotspot(false /* isFeatureAvailable */);
verify(mSettings, never()).findPreference(KEY_INSTANT_HOTSPOT);
verify(mWifiTetherViewModel, never()).getInstantHotspotSummary();
}
@Test
public void setupInstantHotspot_featureAvailable_doSetup() {
when(mWifiTetherViewModel.isInstantHotspotFeatureAvailable()).thenReturn(true);
mSettings.setupInstantHotspot(true /* isFeatureAvailable */);
verify(mSettings).findPreference(KEY_INSTANT_HOTSPOT);
verify(mInstantHotspotSummary).observe(any(), any());
verify(mInstantHotspot).setOnPreferenceClickListener(any());
}
@Test
public void onInstantHotspotChanged_nullRecord_setVisibleFalse() {
mSettings.onInstantHotspotChanged(null);
verify(mInstantHotspot).setVisible(false);
}
@Test
public void onInstantHotspotChanged_summaryNull_setVisibleFalse() {
mSettings.onInstantHotspotChanged(null);
verify(mInstantHotspot).setVisible(false);
}
@Test
public void onInstantHotspotChanged_summaryNotNull_setVisibleAndSummary() {
mSettings.onInstantHotspotChanged(SUMMARY);
verify(mInstantHotspot).setVisible(true);
verify(mInstantHotspot).setSummary(SUMMARY);
}
@Test
public void buildNewConfig_speedFeatureIsAvailableAndPasswordChanged_bandShouldNotBeLost() {
String newPassword = "new" + PASSWORD;