Merge "[SB Refactor] Update wifi network to inactive if carrier merged is lost." into udc-dev

This commit is contained in:
Caitlin Shkuratov
2023-04-19 21:35:31 +00:00
committed by Android (Google) Code Review
2 changed files with 32 additions and 3 deletions

View File

@@ -160,8 +160,10 @@ constructor(
val wifi = currentWifi
if (
wifi is WifiNetworkModel.Active &&
wifi.networkId == network.getNetId()
(wifi is WifiNetworkModel.Active &&
wifi.networkId == network.getNetId()) ||
(wifi is WifiNetworkModel.CarrierMerged &&
wifi.networkId == network.getNetId())
) {
val newNetworkModel = WifiNetworkModel.Inactive
currentWifi = newNetworkModel

View File

@@ -994,7 +994,7 @@ class WifiRepositoryImplTest : SysuiTestCase() {
}
@Test
fun wifiNetwork_currentNetworkLost_flowHasNoNetwork() =
fun wifiNetwork_currentActiveNetworkLost_flowHasNoNetwork() =
testScope.runTest {
var latest: WifiNetworkModel? = null
val job = underTest.wifiNetwork.onEach { latest = it }.launchIn(this)
@@ -1012,6 +1012,33 @@ class WifiRepositoryImplTest : SysuiTestCase() {
job.cancel()
}
/** Possible regression test for b/278618530. */
@Test
fun wifiNetwork_currentCarrierMergedNetworkLost_flowHasNoNetwork() =
testScope.runTest {
var latest: WifiNetworkModel? = null
val job = underTest.wifiNetwork.onEach { latest = it }.launchIn(this)
val wifiInfo =
mock<WifiInfo>().apply {
whenever(this.isPrimary).thenReturn(true)
whenever(this.isCarrierMerged).thenReturn(true)
}
getNetworkCallback()
.onCapabilitiesChanged(NETWORK, createWifiNetworkCapabilities(wifiInfo))
assertThat(latest is WifiNetworkModel.CarrierMerged).isTrue()
assertThat((latest as WifiNetworkModel.CarrierMerged).networkId).isEqualTo(NETWORK_ID)
// WHEN we lose our current network
getNetworkCallback().onLost(NETWORK)
// THEN we update to no network
assertThat(latest is WifiNetworkModel.Inactive).isTrue()
job.cancel()
}
@Test
fun wifiNetwork_unknownNetworkLost_flowHasPreviousNetwork() =
testScope.runTest {