Fallback to "Extended Compatibility" if Speed feature is not ready

- Fallback to the "Extended Compatibility" design when the following conditions occur
  - 5 GHz band is not supported on the device
  - 5 GHz SAP available channels cannot be obtained from WifiManager
  - 6 GHz SAP available channels cannot be obtained from WifiManager

Bug: 272450463
Test: manual test
atest -c WifiTetherSettingsTest
atest -c WifiTetherViewModelTest \
         WifiHotspotRepositoryTest \
         WifiTetherSecurityPreferenceControllerTest.java \
         WifiTetherMaximizeCompatibilityPreferenceControllerTest

Change-Id: If7c8c41ebe86f5e7d8e4737ab7a82d38c9d633de
This commit is contained in:
Weng Su
2023-04-17 12:20:42 +08:00
parent 019e8ceb72
commit d965ff3049
10 changed files with 278 additions and 33 deletions

View File

@@ -36,6 +36,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -592,6 +593,65 @@ public class WifiHotspotRepositoryTest {
assertThat(mWifiHotspotRepository.get6gAvailable()).isNotNull();
}
@Test
public void isSpeedFeatureAvailable_configNotShow_returnFalse() {
mWifiHotspotRepository.mIsConfigShowSpeed = false;
assertThat(mWifiHotspotRepository.isSpeedFeatureAvailable()).isFalse();
}
@Test
public void isSpeedFeatureAvailable_5gBandNotSupported_returnFalse() {
mWifiHotspotRepository.mIsConfigShowSpeed = true;
mWifiHotspotRepository.mIs5gBandSupported = false;
assertThat(mWifiHotspotRepository.isSpeedFeatureAvailable()).isFalse();
}
@Test
public void isSpeedFeatureAvailable_throwExceptionWhenGet5gSapChannel_returnFalse() {
mWifiHotspotRepository.mIsConfigShowSpeed = true;
mWifiHotspotRepository.mIs5gBandSupported = true;
doThrow(IllegalArgumentException.class).when(mWifiManager)
.getUsableChannels(WifiScanner.WIFI_BAND_5_GHZ_WITH_DFS, OP_MODE_SAP);
assertThat(mWifiHotspotRepository.isSpeedFeatureAvailable()).isFalse();
doThrow(UnsupportedOperationException.class).when(mWifiManager)
.getUsableChannels(WifiScanner.WIFI_BAND_5_GHZ_WITH_DFS, OP_MODE_SAP);
assertThat(mWifiHotspotRepository.isSpeedFeatureAvailable()).isFalse();
}
@Test
public void isSpeedFeatureAvailable_throwExceptionWhenGet6gSapChannel_returnFalse() {
mWifiHotspotRepository.mIsConfigShowSpeed = true;
mWifiHotspotRepository.mIs5gBandSupported = true;
doReturn(Arrays.asList(new WifiAvailableChannel(FREQ_5GHZ, OP_MODE_SAP))).when(mWifiManager)
.getUsableChannels(WifiScanner.WIFI_BAND_5_GHZ_WITH_DFS, OP_MODE_SAP);
doThrow(IllegalArgumentException.class).when(mWifiManager)
.getUsableChannels(WifiScanner.WIFI_BAND_6_GHZ, OP_MODE_SAP);
assertThat(mWifiHotspotRepository.isSpeedFeatureAvailable()).isFalse();
doThrow(UnsupportedOperationException.class).when(mWifiManager)
.getUsableChannels(WifiScanner.WIFI_BAND_6_GHZ, OP_MODE_SAP);
assertThat(mWifiHotspotRepository.isSpeedFeatureAvailable()).isFalse();
}
@Test
public void isSpeedFeatureAvailable_conditionsAreReady_returnTrue() {
mWifiHotspotRepository.mIsConfigShowSpeed = true;
mWifiHotspotRepository.mIs5gBandSupported = true;
doReturn(Arrays.asList(new WifiAvailableChannel(FREQ_5GHZ, OP_MODE_SAP))).when(mWifiManager)
.getUsableChannels(WifiScanner.WIFI_BAND_5_GHZ_WITH_DFS, OP_MODE_SAP);
doReturn(Arrays.asList(new WifiAvailableChannel(FREQ_6GHZ, OP_MODE_SAP))).when(mWifiManager)
.getUsableChannels(WifiScanner.WIFI_BAND_6_GHZ, OP_MODE_SAP);
assertThat(mWifiHotspotRepository.isSpeedFeatureAvailable()).isTrue();
}
private void mockConfigSecurityType(int securityType) {
mockConfig(securityType, SPEED_2GHZ);
}

View File

@@ -237,4 +237,11 @@ public class WifiTetherMaximizeCompatibilityPreferenceControllerTest {
assertThat(builder.build().getBand()).isEqualTo(SoftApConfiguration.BAND_2GHZ);
}
@Test
public void isAvailable_shouldHidePreference_returnFalse() {
mController.mShouldHidePreference = true;
assertThat(mController.isAvailable()).isFalse();
}
}

View File

@@ -203,4 +203,11 @@ public class WifiTetherSecurityPreferenceControllerTest {
.isEqualTo(SoftApConfiguration.SECURITY_TYPE_WPA2_PSK);
assertThat(mPreference.getSummary().toString()).isEqualTo("WPA2-Personal");
}
@Test
public void isAvailable_shouldHidePreference_returnFalse() {
mController.mShouldHidePreference = true;
assertThat(mController.isAvailable()).isFalse();
}
}

View File

@@ -72,7 +72,10 @@ public class WifiTetherViewModelTest {
}
@Test
public void onCleared_setAutoRefreshFalse() {
public void onCleared_removeObservers() {
mViewModel.getSecuritySummary();
mViewModel.getSpeedSummary();
mViewModel.onCleared();
verify(mSecurityType).removeObserver(mViewModel.mSecurityTypeObserver);
@@ -116,4 +119,11 @@ public class WifiTetherViewModelTest {
assertThat(mViewModel.mSpeedSummary).isNotNull();
verify(mSpeedType).observeForever(mViewModel.mSpeedTypeObserver);
}
@Test
public void isSpeedFeatureAvailable_verifyRepositoryIsCalled() {
mViewModel.isSpeedFeatureAvailable();
verify(mWifiHotspotRepository).isSpeedFeatureAvailable();
}
}