InternetPreferenceController V2 (5/n)
Support ethernet. Bug: 339884322 Flag: com.android.settings.flags.internet_preference_controller_v2 Test: manual - on Internet Test: unit test Change-Id: I73fc9334379daa979f736fc9ff31c3d576a3381b
This commit is contained in:
@@ -33,6 +33,7 @@ import kotlinx.coroutines.flow.Flow
|
|||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.conflate
|
import kotlinx.coroutines.flow.conflate
|
||||||
import kotlinx.coroutines.flow.flatMapLatest
|
import kotlinx.coroutines.flow.flatMapLatest
|
||||||
|
import kotlinx.coroutines.flow.flowOf
|
||||||
import kotlinx.coroutines.flow.flowOn
|
import kotlinx.coroutines.flow.flowOn
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
@@ -71,6 +72,7 @@ class InternetPreferenceRepository(
|
|||||||
when (transportType) {
|
when (transportType) {
|
||||||
NetworkCapabilities.TRANSPORT_WIFI -> return wifiDisplayInfoFlow()
|
NetworkCapabilities.TRANSPORT_WIFI -> return wifiDisplayInfoFlow()
|
||||||
NetworkCapabilities.TRANSPORT_CELLULAR -> return cellularDisplayInfoFlow()
|
NetworkCapabilities.TRANSPORT_CELLULAR -> return cellularDisplayInfoFlow()
|
||||||
|
NetworkCapabilities.TRANSPORT_ETHERNET -> return ethernetDisplayInfoFlow()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,6 +95,14 @@ class InternetPreferenceRepository(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun ethernetDisplayInfoFlow() =
|
||||||
|
flowOf(
|
||||||
|
DisplayInfo(
|
||||||
|
summary = context.getString(R.string.to_switch_networks_disconnect_ethernet),
|
||||||
|
iconResId = R.drawable.ic_settings_ethernet,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
private fun defaultDisplayInfoFlow(): Flow<DisplayInfo> =
|
private fun defaultDisplayInfoFlow(): Flow<DisplayInfo> =
|
||||||
combine(
|
combine(
|
||||||
airplaneModeOnFlow,
|
airplaneModeOnFlow,
|
||||||
|
|||||||
@@ -105,6 +105,29 @@ class InternetPreferenceRepositoryTest {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun displayInfoFlow_ethernet() = runBlocking {
|
||||||
|
val wifiNetworkCapabilities =
|
||||||
|
NetworkCapabilities.Builder()
|
||||||
|
.addTransportType(NetworkCapabilities.TRANSPORT_ETHERNET)
|
||||||
|
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
||||||
|
.addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)
|
||||||
|
.build()
|
||||||
|
mockConnectivityRepository.stub {
|
||||||
|
on { networkCapabilitiesFlow() } doReturn flowOf(wifiNetworkCapabilities)
|
||||||
|
}
|
||||||
|
|
||||||
|
val displayInfo = repository.displayInfoFlow().firstWithTimeoutOrNull()
|
||||||
|
|
||||||
|
assertThat(displayInfo)
|
||||||
|
.isEqualTo(
|
||||||
|
InternetPreferenceRepository.DisplayInfo(
|
||||||
|
summary = context.getString(R.string.to_switch_networks_disconnect_ethernet),
|
||||||
|
iconResId = R.drawable.ic_settings_ethernet,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun displayInfoFlow_airplaneModeOnAndWifiOn() = runBlocking {
|
fun displayInfoFlow_airplaneModeOnAndWifiOn() = runBlocking {
|
||||||
mockConnectivityRepository.stub {
|
mockConnectivityRepository.stub {
|
||||||
|
|||||||
Reference in New Issue
Block a user