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

View File

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