Refine WifiHotspotRepository variable names

- Since the speed of hotspot design was changed to refer to allowed channels rather than usable channels, remove the "Usable" naming to avoid confusion

Fix: 360312024
Flag: EXEMPT refactor
Test: Manual testing
atest -c WifiHotspotRepositoryTest

Change-Id: Ie54a351e0f788e1b6aeec079ccf6671f7f78fb1c
This commit is contained in:
Weng Su
2024-08-16 18:36:38 +08:00
parent eb1fc8415b
commit 1a975d6f72
2 changed files with 63 additions and 63 deletions

View File

@@ -397,7 +397,7 @@ public class WifiHotspotRepository {
* @return {@code true} if Wi-Fi Hotspot 5 GHz Band is available * @return {@code true} if Wi-Fi Hotspot 5 GHz Band is available
*/ */
public boolean is5gAvailable() { public boolean is5gAvailable() {
if (!mBand5g.isUsableChannelsReady && is5GHzBandSupported()) { if (!mBand5g.isChannelsReady && is5GHzBandSupported()) {
isChannelAvailable(mBand5g); isChannelAvailable(mBand5g);
} }
return mBand5g.isAvailable(); return mBand5g.isAvailable();
@@ -439,7 +439,7 @@ public class WifiHotspotRepository {
* @return {@code true} if Wi-Fi Hotspot 6 GHz Band is available * @return {@code true} if Wi-Fi Hotspot 6 GHz Band is available
*/ */
public boolean is6gAvailable() { public boolean is6gAvailable() {
if (!mBand6g.isUsableChannelsReady && is6GHzBandSupported()) { if (!mBand6g.isChannelsReady && is6GHzBandSupported()) {
isChannelAvailable(mBand6g); isChannelAvailable(mBand6g);
} }
return mBand6g.isAvailable(); return mBand6g.isAvailable();
@@ -475,19 +475,19 @@ public class WifiHotspotRepository {
List<WifiAvailableChannel> channels = List<WifiAvailableChannel> channels =
mWifiManager.getAllowedChannels(sapBand.band, OP_MODE_SAP); mWifiManager.getAllowedChannels(sapBand.band, OP_MODE_SAP);
log("isChannelAvailable(), band:" + sapBand.band + ", channels:" + channels); log("isChannelAvailable(), band:" + sapBand.band + ", channels:" + channels);
sapBand.hasUsableChannels = (channels != null && channels.size() > 0); sapBand.hasChannels = (channels != null && channels.size() > 0);
sapBand.isUsableChannelsUnsupported = false; sapBand.isChannelsUnsupported = false;
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
Log.e(TAG, "Querying usable SAP channels failed, band:" + sapBand.band); Log.e(TAG, "Querying SAP channels failed, band:" + sapBand.band);
sapBand.hasUsableChannels = false; sapBand.hasChannels = false;
sapBand.isUsableChannelsUnsupported = true; sapBand.isChannelsUnsupported = true;
} catch (UnsupportedOperationException e) { } catch (UnsupportedOperationException e) {
// This is expected on some hardware. // This is expected on some hardware.
Log.e(TAG, "Querying usable SAP channels is unsupported, band:" + sapBand.band); Log.e(TAG, "Querying SAP channels is unsupported, band:" + sapBand.band);
sapBand.hasUsableChannels = false; sapBand.hasChannels = false;
sapBand.isUsableChannelsUnsupported = true; sapBand.isChannelsUnsupported = true;
} }
sapBand.isUsableChannelsReady = true; sapBand.isChannelsReady = true;
log("isChannelAvailable(), " + sapBand); log("isChannelAvailable(), " + sapBand);
return sapBand.isAvailable(); return sapBand.isAvailable();
} }
@@ -531,8 +531,8 @@ public class WifiHotspotRepository {
} }
protected void purgeRefreshData() { protected void purgeRefreshData() {
mBand5g.isUsableChannelsReady = false; mBand5g.isChannelsReady = false;
mBand6g.isUsableChannelsReady = false; mBand6g.isChannelsReady = false;
} }
protected void startAutoRefresh() { protected void startAutoRefresh() {
@@ -615,15 +615,15 @@ public class WifiHotspotRepository {
@VisibleForTesting @VisibleForTesting
void updateCapabilityChanged() { void updateCapabilityChanged() {
if (mBand5g.isUsableChannelsUnsupported) { if (mBand5g.isChannelsUnsupported) {
update5gAvailable(); update5gAvailable();
log("updateCapabilityChanged(), " + mBand5g); log("updateCapabilityChanged(), " + mBand5g);
} }
if (mBand6g.isUsableChannelsUnsupported) { if (mBand6g.isChannelsUnsupported) {
update6gAvailable(); update6gAvailable();
log("updateCapabilityChanged(), " + mBand6g); log("updateCapabilityChanged(), " + mBand6g);
} }
if (mBand5g.isUsableChannelsUnsupported || mBand6g.isUsableChannelsUnsupported) { if (mBand5g.isChannelsUnsupported || mBand6g.isChannelsUnsupported) {
updateSpeedType(); updateSpeedType();
} }
} }
@@ -676,9 +676,9 @@ public class WifiHotspotRepository {
@VisibleForTesting @VisibleForTesting
static class SapBand { static class SapBand {
public int band; public int band;
public boolean isUsableChannelsReady; public boolean isChannelsReady;
public boolean hasUsableChannels; public boolean hasChannels;
public boolean isUsableChannelsUnsupported; public boolean isChannelsUnsupported;
public boolean hasCapability; public boolean hasCapability;
SapBand(int band) { SapBand(int band) {
@@ -689,7 +689,7 @@ public class WifiHotspotRepository {
* Return whether SoftAp band is available or not. * Return whether SoftAp band is available or not.
*/ */
public boolean isAvailable() { public boolean isAvailable() {
return isUsableChannelsUnsupported ? hasCapability : hasUsableChannels; return isChannelsUnsupported ? hasCapability : hasChannels;
} }
@Override @Override
@@ -697,10 +697,10 @@ public class WifiHotspotRepository {
public String toString() { public String toString() {
return "SapBand{" return "SapBand{"
+ "band:" + band + "band:" + band
+ ",isUsableChannelsReady:" + isUsableChannelsReady + ",isChannelsReady:" + isChannelsReady
+ ",hasUsableChannels:" + hasUsableChannels + ",hasChannels:" + hasChannels
+ ",isUsableChannelsUnsupported:" + isUsableChannelsUnsupported + ",isChannelsUnsupported:" + isChannelsUnsupported
+ ",hasChannelsCapability:" + hasCapability + ",hasCapability:" + hasCapability
+ '}'; + '}';
} }
} }

View File

@@ -118,12 +118,12 @@ public class WifiHotspotRepositoryTest {
mRepository.mSecurityType = mSecurityType; mRepository.mSecurityType = mSecurityType;
mRepository.mSpeedType = mSpeedType; mRepository.mSpeedType = mSpeedType;
mRepository.mIsDualBand = true; mRepository.mIsDualBand = true;
mRepository.mBand5g.isUsableChannelsReady = true; mRepository.mBand5g.isChannelsReady = true;
mRepository.mBand5g.isUsableChannelsUnsupported = false; mRepository.mBand5g.isChannelsUnsupported = false;
mRepository.mBand5g.hasUsableChannels = true; mRepository.mBand5g.hasChannels = true;
mRepository.mBand6g.isUsableChannelsReady = true; mRepository.mBand6g.isChannelsReady = true;
mRepository.mBand6g.isUsableChannelsUnsupported = false; mRepository.mBand6g.isChannelsUnsupported = false;
mRepository.mBand6g.hasUsableChannels = true; mRepository.mBand6g.hasChannels = true;
} }
@Test @Test
@@ -382,7 +382,7 @@ public class WifiHotspotRepositoryTest {
@Test @Test
public void updateSpeedType_singleBand5gPreferredBut5gUnavailable_get2gSpeedType() { public void updateSpeedType_singleBand5gPreferredBut5gUnavailable_get2gSpeedType() {
mRepository.mIsDualBand = false; mRepository.mIsDualBand = false;
mRepository.mBand5g.hasUsableChannels = false; mRepository.mBand5g.hasChannels = false;
SoftApConfiguration config = new SoftApConfiguration.Builder() SoftApConfiguration config = new SoftApConfiguration.Builder()
.setBand(WIFI_5GHZ_BAND_PREFERRED).build(); .setBand(WIFI_5GHZ_BAND_PREFERRED).build();
when(mWifiManager.getSoftApConfiguration()).thenReturn(config); when(mWifiManager.getSoftApConfiguration()).thenReturn(config);
@@ -407,7 +407,7 @@ public class WifiHotspotRepositoryTest {
@Test @Test
public void updateSpeedType_singleBand6gPreferredBut6gUnavailable_get5gSpeedType() { public void updateSpeedType_singleBand6gPreferredBut6gUnavailable_get5gSpeedType() {
mRepository.mIsDualBand = false; mRepository.mIsDualBand = false;
mRepository.mBand6g.hasUsableChannels = false; mRepository.mBand6g.hasChannels = false;
SoftApConfiguration config = new SoftApConfiguration.Builder() SoftApConfiguration config = new SoftApConfiguration.Builder()
.setBand(WIFI_6GHZ_BAND_PREFERRED).build(); .setBand(WIFI_6GHZ_BAND_PREFERRED).build();
when(mWifiManager.getSoftApConfiguration()).thenReturn(config); when(mWifiManager.getSoftApConfiguration()).thenReturn(config);
@@ -420,8 +420,8 @@ public class WifiHotspotRepositoryTest {
@Test @Test
public void updateSpeedType_singleBand6gPreferredBut5gAnd6gUnavailable_get2gSpeedType() { public void updateSpeedType_singleBand6gPreferredBut5gAnd6gUnavailable_get2gSpeedType() {
mRepository.mIsDualBand = false; mRepository.mIsDualBand = false;
mRepository.mBand5g.hasUsableChannels = false; mRepository.mBand5g.hasChannels = false;
mRepository.mBand6g.hasUsableChannels = false; mRepository.mBand6g.hasChannels = false;
SoftApConfiguration config = new SoftApConfiguration.Builder() SoftApConfiguration config = new SoftApConfiguration.Builder()
.setBand(WIFI_6GHZ_BAND_PREFERRED).build(); .setBand(WIFI_6GHZ_BAND_PREFERRED).build();
when(mWifiManager.getSoftApConfiguration()).thenReturn(config); when(mWifiManager.getSoftApConfiguration()).thenReturn(config);
@@ -446,7 +446,7 @@ public class WifiHotspotRepositoryTest {
@Test @Test
public void updateSpeedType_dualBand2gAnd5gBut5gUnavailable_get2gSpeedType() { public void updateSpeedType_dualBand2gAnd5gBut5gUnavailable_get2gSpeedType() {
mRepository.mIsDualBand = true; mRepository.mIsDualBand = true;
mRepository.mBand5g.hasUsableChannels = false; mRepository.mBand5g.hasChannels = false;
SoftApConfiguration config = new SoftApConfiguration.Builder() SoftApConfiguration config = new SoftApConfiguration.Builder()
.setBand(WIFI_5GHZ_BAND_PREFERRED).build(); .setBand(WIFI_5GHZ_BAND_PREFERRED).build();
when(mWifiManager.getSoftApConfiguration()).thenReturn(config); when(mWifiManager.getSoftApConfiguration()).thenReturn(config);
@@ -562,19 +562,19 @@ public class WifiHotspotRepositoryTest {
} }
@Test @Test
public void is5gAvailable_hasUsableChannels_returnTrue() { public void is5gAvailable_hasChannels_returnTrue() {
mRepository.mIs5gBandSupported = true; mRepository.mIs5gBandSupported = true;
// Reset m5gBand to trigger an update // Reset m5gBand to trigger an update
mRepository.mBand5g.isUsableChannelsReady = false; mRepository.mBand5g.isChannelsReady = false;
assertThat(mRepository.is5gAvailable()).isTrue(); assertThat(mRepository.is5gAvailable()).isTrue();
} }
@Test @Test
public void is5gAvailable_noUsableChannels_returnFalse() { public void is5gAvailable_noChannels_returnFalse() {
mRepository.mIs5gBandSupported = true; mRepository.mIs5gBandSupported = true;
// Reset m5gBand to trigger an update // Reset m5gBand to trigger an update
mRepository.mBand5g.isUsableChannelsReady = false; mRepository.mBand5g.isChannelsReady = false;
when(mWifiManager.getAllowedChannels(WifiScanner.WIFI_BAND_5_GHZ_WITH_DFS, OP_MODE_SAP)) when(mWifiManager.getAllowedChannels(WifiScanner.WIFI_BAND_5_GHZ_WITH_DFS, OP_MODE_SAP))
.thenReturn(null); .thenReturn(null);
@@ -585,7 +585,7 @@ public class WifiHotspotRepositoryTest {
@UiThreadTest @UiThreadTest
public void get5gAvailable_shouldNotReturnNull() { public void get5gAvailable_shouldNotReturnNull() {
// Reset m5gBand to trigger an update // Reset m5gBand to trigger an update
mRepository.mBand5g.isUsableChannelsReady = false; mRepository.mBand5g.isChannelsReady = false;
assertThat(mRepository.get5gAvailable()).isNotNull(); assertThat(mRepository.get5gAvailable()).isNotNull();
} }
@@ -606,19 +606,19 @@ public class WifiHotspotRepositoryTest {
} }
@Test @Test
public void is6gAvailable_hasUsableChannels_returnTrue() { public void is6gAvailable_hasChannels_returnTrue() {
mRepository.mIs6gBandSupported = true; mRepository.mIs6gBandSupported = true;
// Reset m6gBand to trigger an update // Reset m6gBand to trigger an update
mRepository.mBand6g.isUsableChannelsReady = false; mRepository.mBand6g.isChannelsReady = false;
assertThat(mRepository.is6gAvailable()).isTrue(); assertThat(mRepository.is6gAvailable()).isTrue();
} }
@Test @Test
public void is6gAvailable_noUsableChannels_returnFalse() { public void is6gAvailable_noChannels_returnFalse() {
mRepository.mIs6gBandSupported = true; mRepository.mIs6gBandSupported = true;
// Reset m6gBand to trigger an update // Reset m6gBand to trigger an update
mRepository.mBand6g.isUsableChannelsReady = false; mRepository.mBand6g.isChannelsReady = false;
when(mWifiManager.getAllowedChannels(WifiScanner.WIFI_BAND_6_GHZ, OP_MODE_SAP)) when(mWifiManager.getAllowedChannels(WifiScanner.WIFI_BAND_6_GHZ, OP_MODE_SAP))
.thenReturn(null); .thenReturn(null);
@@ -658,33 +658,33 @@ public class WifiHotspotRepositoryTest {
} }
@Test @Test
public void isChannelAvailable_throwIllegalArgumentException_hasUsableChannelsFalse() { public void isChannelAvailable_throwIllegalArgumentException_hasChannelsFalse() {
doThrow(IllegalArgumentException.class).when(mWifiManager) doThrow(IllegalArgumentException.class).when(mWifiManager)
.getAllowedChannels(WifiScanner.WIFI_BAND_6_GHZ, OP_MODE_SAP); .getAllowedChannels(WifiScanner.WIFI_BAND_6_GHZ, OP_MODE_SAP);
mRepository.isChannelAvailable(mRepository.mBand6g); mRepository.isChannelAvailable(mRepository.mBand6g);
assertThat(mRepository.mBand6g.hasUsableChannels).isFalse(); assertThat(mRepository.mBand6g.hasChannels).isFalse();
assertThat(mRepository.mBand6g.isUsableChannelsUnsupported).isTrue(); assertThat(mRepository.mBand6g.isChannelsUnsupported).isTrue();
} }
@Test @Test
public void isChannelAvailable_throwUnsupportedOperationException_hasUsableChannelsFalse() { public void isChannelAvailable_throwUnsupportedOperationException_hasChannelsFalse() {
doThrow(UnsupportedOperationException.class).when(mWifiManager) doThrow(UnsupportedOperationException.class).when(mWifiManager)
.getAllowedChannels(WifiScanner.WIFI_BAND_6_GHZ, OP_MODE_SAP); .getAllowedChannels(WifiScanner.WIFI_BAND_6_GHZ, OP_MODE_SAP);
mRepository.isChannelAvailable(mRepository.mBand6g); mRepository.isChannelAvailable(mRepository.mBand6g);
assertThat(mRepository.mBand6g.hasUsableChannels).isFalse(); assertThat(mRepository.mBand6g.hasChannels).isFalse();
assertThat(mRepository.mBand6g.isUsableChannelsUnsupported).isTrue(); assertThat(mRepository.mBand6g.isChannelsUnsupported).isTrue();
} }
@Test @Test
public void isChannelAvailable_noExceptionAndHasUsableChannels_hasUsableChannelsTrue() { public void isChannelAvailable_noExceptionAndHasChannels_hasChannelsTrue() {
mRepository.isChannelAvailable(mRepository.mBand6g); mRepository.isChannelAvailable(mRepository.mBand6g);
assertThat(mRepository.mBand6g.hasUsableChannels).isTrue(); assertThat(mRepository.mBand6g.hasChannels).isTrue();
assertThat(mRepository.mBand6g.isUsableChannelsUnsupported).isFalse(); assertThat(mRepository.mBand6g.isChannelsUnsupported).isFalse();
} }
@Test @Test
@@ -744,9 +744,9 @@ public class WifiHotspotRepositoryTest {
} }
@Test @Test
public void updateCapabilityChanged_band5gUsableChannelsUnsupported_update5gAvailable() { public void updateCapabilityChanged_band5gChannelsUnsupported_update5gAvailable() {
mRepository = spy(new WifiHotspotRepository(mContext, mWifiManager, mTetheringManager)); mRepository = spy(new WifiHotspotRepository(mContext, mWifiManager, mTetheringManager));
mRepository.mBand5g.isUsableChannelsUnsupported = true; mRepository.mBand5g.isChannelsUnsupported = true;
mRepository.updateCapabilityChanged(); mRepository.updateCapabilityChanged();
@@ -755,9 +755,9 @@ public class WifiHotspotRepositoryTest {
} }
@Test @Test
public void updateCapabilityChanged_band6gUsableChannelsUnsupported_update5gAvailable() { public void updateCapabilityChanged_band6gChannelsUnsupported_update5gAvailable() {
mRepository = spy(new WifiHotspotRepository(mContext, mWifiManager, mTetheringManager)); mRepository = spy(new WifiHotspotRepository(mContext, mWifiManager, mTetheringManager));
mRepository.mBand6g.isUsableChannelsUnsupported = true; mRepository.mBand6g.isChannelsUnsupported = true;
mRepository.updateCapabilityChanged(); mRepository.updateCapabilityChanged();
@@ -766,18 +766,18 @@ public class WifiHotspotRepositoryTest {
} }
@Test @Test
public void isAvailable_isUsableChannelsUnsupportedFalse_returnHasUsableChannels() { public void isAvailable_isChannelsUnsupportedFalse_returnHasChannels() {
mRepository.mBand6g.isUsableChannelsUnsupported = false; mRepository.mBand6g.isChannelsUnsupported = false;
mRepository.mBand6g.hasUsableChannels = false; mRepository.mBand6g.hasChannels = false;
mRepository.mBand6g.hasCapability = true; mRepository.mBand6g.hasCapability = true;
assertThat(mRepository.mBand6g.isAvailable()).isFalse(); assertThat(mRepository.mBand6g.isAvailable()).isFalse();
} }
@Test @Test
public void isAvailable_isUsableChannelsUnsupportedTrue_returnHasCapability() { public void isAvailable_isChannelsUnsupportedTrue_returnHasCapability() {
mRepository.mBand6g.isUsableChannelsUnsupported = true; mRepository.mBand6g.isChannelsUnsupported = true;
mRepository.mBand6g.hasUsableChannels = false; mRepository.mBand6g.hasChannels = false;
mRepository.mBand6g.hasCapability = true; mRepository.mBand6g.hasCapability = true;
assertThat(mRepository.mBand6g.isAvailable()).isTrue(); assertThat(mRepository.mBand6g.isAvailable()).isTrue();