Merge changes from topic "sb-flags-new" into tm-qpr-dev am: c8645ff101
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20190152 Change-Id: I0ba3b3d4c5609880dfb9d6ec59c7c0f7d39e4f19 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -214,14 +214,30 @@ public class Flags {
|
|||||||
public static final ReleasedFlag STATUS_BAR_LETTERBOX_APPEARANCE =
|
public static final ReleasedFlag STATUS_BAR_LETTERBOX_APPEARANCE =
|
||||||
new ReleasedFlag(603, false);
|
new ReleasedFlag(603, false);
|
||||||
|
|
||||||
// TODO(b/254512623): Tracking Bug
|
/**
|
||||||
|
* @deprecated replaced by mobile and wifi specific flags.
|
||||||
|
*
|
||||||
|
* TODO(b/254512623): Tracking Bug
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public static final UnreleasedFlag NEW_STATUS_BAR_PIPELINE_BACKEND =
|
public static final UnreleasedFlag NEW_STATUS_BAR_PIPELINE_BACKEND =
|
||||||
new UnreleasedFlag(604, false);
|
new UnreleasedFlag(604, false);
|
||||||
|
|
||||||
// TODO(b/254512660): Tracking Bug
|
/**
|
||||||
|
* @deprecated replaced by mobile and wifi specific flags.
|
||||||
|
*
|
||||||
|
* TODO(b/254512660): Tracking Bug
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public static final UnreleasedFlag NEW_STATUS_BAR_PIPELINE_FRONTEND =
|
public static final UnreleasedFlag NEW_STATUS_BAR_PIPELINE_FRONTEND =
|
||||||
new UnreleasedFlag(605, false);
|
new UnreleasedFlag(605, false);
|
||||||
|
|
||||||
|
public static final UnreleasedFlag NEW_STATUS_BAR_MOBILE_ICONS =
|
||||||
|
new UnreleasedFlag(606, false);
|
||||||
|
|
||||||
|
public static final UnreleasedFlag NEW_STATUS_BAR_WIFI_ICON =
|
||||||
|
new UnreleasedFlag(607, false);
|
||||||
|
|
||||||
/***************************************/
|
/***************************************/
|
||||||
// 700 - dialer/calls
|
// 700 - dialer/calls
|
||||||
// TODO(b/254512734): Tracking Bug
|
// TODO(b/254512734): Tracking Bug
|
||||||
|
|||||||
@@ -372,7 +372,7 @@ public interface StatusBarIconController {
|
|||||||
mIconSize = mContext.getResources().getDimensionPixelSize(
|
mIconSize = mContext.getResources().getDimensionPixelSize(
|
||||||
com.android.internal.R.dimen.status_bar_icon_size);
|
com.android.internal.R.dimen.status_bar_icon_size);
|
||||||
|
|
||||||
if (statusBarPipelineFlags.isNewPipelineFrontendEnabled()) {
|
if (statusBarPipelineFlags.useNewMobileIcons()) {
|
||||||
// This starts the flow for the new pipeline, and will notify us of changes
|
// This starts the flow for the new pipeline, and will notify us of changes
|
||||||
mMobileIconsViewModel = mobileUiAdapter.createMobileIconsViewModel();
|
mMobileIconsViewModel = mobileUiAdapter.createMobileIconsViewModel();
|
||||||
MobileIconsBinder.bind(mGroup, mMobileIconsViewModel);
|
MobileIconsBinder.bind(mGroup, mMobileIconsViewModel);
|
||||||
@@ -451,7 +451,7 @@ public interface StatusBarIconController {
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected StatusIconDisplayable addWifiIcon(int index, String slot, WifiIconState state) {
|
protected StatusIconDisplayable addWifiIcon(int index, String slot, WifiIconState state) {
|
||||||
final BaseStatusBarFrameLayout view;
|
final BaseStatusBarFrameLayout view;
|
||||||
if (mStatusBarPipelineFlags.isNewPipelineFrontendEnabled()) {
|
if (mStatusBarPipelineFlags.useNewWifiIcon()) {
|
||||||
view = onCreateModernStatusBarWifiView(slot);
|
view = onCreateModernStatusBarWifiView(slot);
|
||||||
// When [ModernStatusBarWifiView] is created, it will automatically apply the
|
// When [ModernStatusBarWifiView] is created, it will automatically apply the
|
||||||
// correct view state so we don't need to call applyWifiState.
|
// correct view state so we don't need to call applyWifiState.
|
||||||
@@ -474,9 +474,9 @@ public interface StatusBarIconController {
|
|||||||
String slot,
|
String slot,
|
||||||
MobileIconState state
|
MobileIconState state
|
||||||
) {
|
) {
|
||||||
if (mStatusBarPipelineFlags.isNewPipelineFrontendEnabled()) {
|
if (mStatusBarPipelineFlags.useNewMobileIcons()) {
|
||||||
throw new IllegalStateException("Attempting to add a mobile icon while the new "
|
throw new IllegalStateException("Attempting to add a mobile icon while the new "
|
||||||
+ "pipeline is enabled is not supported");
|
+ "icons are enabled is not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the `subId` field as a key to query for the correct context
|
// Use the `subId` field as a key to query for the correct context
|
||||||
@@ -497,7 +497,7 @@ public interface StatusBarIconController {
|
|||||||
String slot,
|
String slot,
|
||||||
int subId
|
int subId
|
||||||
) {
|
) {
|
||||||
if (!mStatusBarPipelineFlags.isNewPipelineFrontendEnabled()) {
|
if (!mStatusBarPipelineFlags.useNewMobileIcons()) {
|
||||||
throw new IllegalStateException("Attempting to add a mobile icon using the new"
|
throw new IllegalStateException("Attempting to add a mobile icon using the new"
|
||||||
+ "pipeline, but the enabled flag is false.");
|
+ "pipeline, but the enabled flag is false.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -224,9 +224,9 @@ public class StatusBarIconControllerImpl implements Tunable,
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setMobileIcons(String slot, List<MobileIconState> iconStates) {
|
public void setMobileIcons(String slot, List<MobileIconState> iconStates) {
|
||||||
if (mStatusBarPipelineFlags.isNewPipelineFrontendEnabled()) {
|
if (mStatusBarPipelineFlags.useNewMobileIcons()) {
|
||||||
Log.d(TAG, "ignoring old pipeline callbacks, because the new "
|
Log.d(TAG, "ignoring old pipeline callbacks, because the new "
|
||||||
+ "pipeline frontend is enabled");
|
+ "icons are enabled");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Slot mobileSlot = mStatusBarIconList.getSlot(slot);
|
Slot mobileSlot = mStatusBarIconList.getSlot(slot);
|
||||||
@@ -249,9 +249,9 @@ public class StatusBarIconControllerImpl implements Tunable,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setNewMobileIconSubIds(List<Integer> subIds) {
|
public void setNewMobileIconSubIds(List<Integer> subIds) {
|
||||||
if (!mStatusBarPipelineFlags.isNewPipelineFrontendEnabled()) {
|
if (!mStatusBarPipelineFlags.useNewMobileIcons()) {
|
||||||
Log.d(TAG, "ignoring new pipeline callback, "
|
Log.d(TAG, "ignoring new pipeline callback, "
|
||||||
+ "since the frontend is disabled");
|
+ "since the new icons are disabled");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Slot mobileSlot = mStatusBarIconList.getSlot("mobile");
|
Slot mobileSlot = mStatusBarIconList.getSlot("mobile");
|
||||||
|
|||||||
@@ -24,29 +24,19 @@ import javax.inject.Inject
|
|||||||
/** All flagging methods related to the new status bar pipeline (see b/238425913). */
|
/** All flagging methods related to the new status bar pipeline (see b/238425913). */
|
||||||
@SysUISingleton
|
@SysUISingleton
|
||||||
class StatusBarPipelineFlags @Inject constructor(private val featureFlags: FeatureFlags) {
|
class StatusBarPipelineFlags @Inject constructor(private val featureFlags: FeatureFlags) {
|
||||||
/**
|
/** True if we should display the mobile icons using the new status bar data pipeline. */
|
||||||
* Returns true if we should run the new pipeline backend.
|
fun useNewMobileIcons(): Boolean = featureFlags.isEnabled(Flags.NEW_STATUS_BAR_MOBILE_ICONS)
|
||||||
*
|
|
||||||
* The new pipeline backend hooks up to all our external callbacks, logs those callback inputs,
|
/** True if we should display the wifi icon using the new status bar data pipeline. */
|
||||||
* and logs the output state.
|
fun useNewWifiIcon(): Boolean = featureFlags.isEnabled(Flags.NEW_STATUS_BAR_WIFI_ICON)
|
||||||
*/
|
|
||||||
fun isNewPipelineBackendEnabled(): Boolean =
|
// TODO(b/238425913): Add flags to only run the mobile backend or wifi backend so we get the
|
||||||
featureFlags.isEnabled(Flags.NEW_STATUS_BAR_PIPELINE_BACKEND)
|
// logging without getting the UI effects.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if we should run the new pipeline frontend *and* backend.
|
* Returns true if we should apply some coloring to the wifi icon that was rendered with the new
|
||||||
*
|
|
||||||
* The new pipeline frontend will use the outputted state from the new backend and will make the
|
|
||||||
* correct changes to the UI.
|
|
||||||
*/
|
|
||||||
fun isNewPipelineFrontendEnabled(): Boolean =
|
|
||||||
isNewPipelineBackendEnabled() &&
|
|
||||||
featureFlags.isEnabled(Flags.NEW_STATUS_BAR_PIPELINE_FRONTEND)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if we should apply some coloring to icons that were rendered with the new
|
|
||||||
* pipeline to help with debugging.
|
* pipeline to help with debugging.
|
||||||
*/
|
*/
|
||||||
// For now, just always apply the debug coloring if we've enabled frontend rendering.
|
// For now, just always apply the debug coloring if we've enabled the new icon.
|
||||||
fun useNewPipelineDebugColoring(): Boolean = isNewPipelineFrontendEnabled()
|
fun useWifiDebugColoring(): Boolean = useNewWifiIcon()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ import com.android.systemui.dagger.qualifiers.Main
|
|||||||
import com.android.systemui.statusbar.pipeline.shared.ConnectivityPipelineLogger
|
import com.android.systemui.statusbar.pipeline.shared.ConnectivityPipelineLogger
|
||||||
import com.android.systemui.statusbar.pipeline.shared.ConnectivityPipelineLogger.Companion.SB_LOGGING_TAG
|
import com.android.systemui.statusbar.pipeline.shared.ConnectivityPipelineLogger.Companion.SB_LOGGING_TAG
|
||||||
import com.android.systemui.statusbar.pipeline.shared.ConnectivityPipelineLogger.Companion.logInputChange
|
import com.android.systemui.statusbar.pipeline.shared.ConnectivityPipelineLogger.Companion.logInputChange
|
||||||
import com.android.systemui.statusbar.pipeline.shared.ConnectivityPipelineLogger.Companion.logOutputChange
|
|
||||||
import com.android.systemui.statusbar.pipeline.wifi.data.model.WifiNetworkModel
|
import com.android.systemui.statusbar.pipeline.wifi.data.model.WifiNetworkModel
|
||||||
import com.android.systemui.statusbar.pipeline.wifi.shared.model.WifiActivityModel
|
import com.android.systemui.statusbar.pipeline.wifi.shared.model.WifiActivityModel
|
||||||
import java.util.concurrent.Executor
|
import java.util.concurrent.Executor
|
||||||
@@ -64,6 +63,9 @@ interface WifiRepository {
|
|||||||
/** Observable for the current wifi enabled status. */
|
/** Observable for the current wifi enabled status. */
|
||||||
val isWifiEnabled: StateFlow<Boolean>
|
val isWifiEnabled: StateFlow<Boolean>
|
||||||
|
|
||||||
|
/** Observable for the current wifi default status. */
|
||||||
|
val isWifiDefault: StateFlow<Boolean>
|
||||||
|
|
||||||
/** Observable for the current wifi network. */
|
/** Observable for the current wifi network. */
|
||||||
val wifiNetwork: StateFlow<WifiNetworkModel>
|
val wifiNetwork: StateFlow<WifiNetworkModel>
|
||||||
|
|
||||||
@@ -103,7 +105,7 @@ class WifiRepositoryImpl @Inject constructor(
|
|||||||
merge(wifiNetworkChangeEvents, wifiStateChangeEvents)
|
merge(wifiNetworkChangeEvents, wifiStateChangeEvents)
|
||||||
.mapLatest { wifiManager.isWifiEnabled }
|
.mapLatest { wifiManager.isWifiEnabled }
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.logOutputChange(logger, "enabled")
|
.logInputChange(logger, "enabled")
|
||||||
.stateIn(
|
.stateIn(
|
||||||
scope = scope,
|
scope = scope,
|
||||||
started = SharingStarted.WhileSubscribed(),
|
started = SharingStarted.WhileSubscribed(),
|
||||||
@@ -111,6 +113,39 @@ class WifiRepositoryImpl @Inject constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override val isWifiDefault: StateFlow<Boolean> = conflatedCallbackFlow {
|
||||||
|
// Note: This callback doesn't do any logging because we already log every network change
|
||||||
|
// in the [wifiNetwork] callback.
|
||||||
|
val callback = object : ConnectivityManager.NetworkCallback(FLAG_INCLUDE_LOCATION_INFO) {
|
||||||
|
override fun onCapabilitiesChanged(
|
||||||
|
network: Network,
|
||||||
|
networkCapabilities: NetworkCapabilities
|
||||||
|
) {
|
||||||
|
// This method will always be called immediately after the network becomes the
|
||||||
|
// default, in addition to any time the capabilities change while the network is
|
||||||
|
// the default.
|
||||||
|
// If this network contains valid wifi info, then wifi is the default network.
|
||||||
|
val wifiInfo = networkCapabilitiesToWifiInfo(networkCapabilities)
|
||||||
|
trySend(wifiInfo != null)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLost(network: Network) {
|
||||||
|
// The system no longer has a default network, so wifi is definitely not default.
|
||||||
|
trySend(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
connectivityManager.registerDefaultNetworkCallback(callback)
|
||||||
|
awaitClose { connectivityManager.unregisterNetworkCallback(callback) }
|
||||||
|
}
|
||||||
|
.distinctUntilChanged()
|
||||||
|
.logInputChange(logger, "isWifiDefault")
|
||||||
|
.stateIn(
|
||||||
|
scope,
|
||||||
|
started = SharingStarted.WhileSubscribed(),
|
||||||
|
initialValue = false
|
||||||
|
)
|
||||||
|
|
||||||
override val wifiNetwork: StateFlow<WifiNetworkModel> = conflatedCallbackFlow {
|
override val wifiNetwork: StateFlow<WifiNetworkModel> = conflatedCallbackFlow {
|
||||||
var currentWifi: WifiNetworkModel = WIFI_NETWORK_DEFAULT
|
var currentWifi: WifiNetworkModel = WIFI_NETWORK_DEFAULT
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,9 @@ class WifiInteractor @Inject constructor(
|
|||||||
/** Our current enabled status. */
|
/** Our current enabled status. */
|
||||||
val isEnabled: Flow<Boolean> = wifiRepository.isWifiEnabled
|
val isEnabled: Flow<Boolean> = wifiRepository.isWifiEnabled
|
||||||
|
|
||||||
|
/** Our current default status. */
|
||||||
|
val isDefault: Flow<Boolean> = wifiRepository.isWifiDefault
|
||||||
|
|
||||||
/** Our current wifi network. See [WifiNetworkModel]. */
|
/** Our current wifi network. See [WifiNetworkModel]. */
|
||||||
val wifiNetwork: Flow<WifiNetworkModel> = wifiRepository.wifiNetwork
|
val wifiNetwork: Flow<WifiNetworkModel> = wifiRepository.wifiNetwork
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ abstract class LocationBasedWifiViewModel(
|
|||||||
/** The color that should be used to tint the icon. */
|
/** The color that should be used to tint the icon. */
|
||||||
val tint: Flow<Int> =
|
val tint: Flow<Int> =
|
||||||
flowOf(
|
flowOf(
|
||||||
if (statusBarPipelineFlags.useNewPipelineDebugColoring()) {
|
if (statusBarPipelineFlags.useWifiDebugColoring()) {
|
||||||
debugTint
|
debugTint
|
||||||
} else {
|
} else {
|
||||||
DEFAULT_TINT
|
DEFAULT_TINT
|
||||||
|
|||||||
@@ -124,9 +124,10 @@ constructor(
|
|||||||
private val wifiIcon: StateFlow<Icon.Resource?> =
|
private val wifiIcon: StateFlow<Icon.Resource?> =
|
||||||
combine(
|
combine(
|
||||||
interactor.isEnabled,
|
interactor.isEnabled,
|
||||||
|
interactor.isDefault,
|
||||||
interactor.isForceHidden,
|
interactor.isForceHidden,
|
||||||
interactor.wifiNetwork,
|
interactor.wifiNetwork,
|
||||||
) { isEnabled, isForceHidden, wifiNetwork ->
|
) { isEnabled, isDefault, isForceHidden, wifiNetwork ->
|
||||||
if (!isEnabled || isForceHidden || wifiNetwork is WifiNetworkModel.CarrierMerged) {
|
if (!isEnabled || isForceHidden || wifiNetwork is WifiNetworkModel.CarrierMerged) {
|
||||||
return@combine null
|
return@combine null
|
||||||
}
|
}
|
||||||
@@ -135,6 +136,7 @@ constructor(
|
|||||||
val icon = Icon.Resource(iconResId, wifiNetwork.contentDescription())
|
val icon = Icon.Resource(iconResId, wifiNetwork.contentDescription())
|
||||||
|
|
||||||
return@combine when {
|
return@combine when {
|
||||||
|
isDefault -> icon
|
||||||
wifiConstants.alwaysShowIconIfEnabled -> icon
|
wifiConstants.alwaysShowIconIfEnabled -> icon
|
||||||
!connectivityConstants.hasDataCapabilities -> icon
|
!connectivityConstants.hasDataCapabilities -> icon
|
||||||
wifiNetwork is WifiNetworkModel.Active && wifiNetwork.isValidated -> icon
|
wifiNetwork is WifiNetworkModel.Active && wifiNetwork.isValidated -> icon
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ class FakeWifiRepository : WifiRepository {
|
|||||||
private val _isWifiEnabled: MutableStateFlow<Boolean> = MutableStateFlow(false)
|
private val _isWifiEnabled: MutableStateFlow<Boolean> = MutableStateFlow(false)
|
||||||
override val isWifiEnabled: StateFlow<Boolean> = _isWifiEnabled
|
override val isWifiEnabled: StateFlow<Boolean> = _isWifiEnabled
|
||||||
|
|
||||||
|
private val _isWifiDefault: MutableStateFlow<Boolean> = MutableStateFlow(false)
|
||||||
|
override val isWifiDefault: StateFlow<Boolean> = _isWifiDefault
|
||||||
|
|
||||||
private val _wifiNetwork: MutableStateFlow<WifiNetworkModel> =
|
private val _wifiNetwork: MutableStateFlow<WifiNetworkModel> =
|
||||||
MutableStateFlow(WifiNetworkModel.Inactive)
|
MutableStateFlow(WifiNetworkModel.Inactive)
|
||||||
override val wifiNetwork: StateFlow<WifiNetworkModel> = _wifiNetwork
|
override val wifiNetwork: StateFlow<WifiNetworkModel> = _wifiNetwork
|
||||||
@@ -38,6 +41,10 @@ class FakeWifiRepository : WifiRepository {
|
|||||||
_isWifiEnabled.value = enabled
|
_isWifiEnabled.value = enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setIsWifiDefault(default: Boolean) {
|
||||||
|
_isWifiDefault.value = default
|
||||||
|
}
|
||||||
|
|
||||||
fun setWifiNetwork(wifiNetworkModel: WifiNetworkModel) {
|
fun setWifiNetwork(wifiNetworkModel: WifiNetworkModel) {
|
||||||
_wifiNetwork.value = wifiNetworkModel
|
_wifiNetwork.value = wifiNetworkModel
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -221,6 +221,83 @@ class WifiRepositoryImplTest : SysuiTestCase() {
|
|||||||
enabledJob.cancel()
|
enabledJob.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun isWifiDefault_initiallyGetsDefault() = runBlocking(IMMEDIATE) {
|
||||||
|
val job = underTest.isWifiDefault.launchIn(this)
|
||||||
|
|
||||||
|
assertThat(underTest.isWifiDefault.value).isFalse()
|
||||||
|
|
||||||
|
job.cancel()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun isWifiDefault_wifiNetwork_isTrue() = runBlocking(IMMEDIATE) {
|
||||||
|
val job = underTest.isWifiDefault.launchIn(this)
|
||||||
|
|
||||||
|
val wifiInfo = mock<WifiInfo>().apply {
|
||||||
|
whenever(this.ssid).thenReturn(SSID)
|
||||||
|
}
|
||||||
|
|
||||||
|
getDefaultNetworkCallback().onCapabilitiesChanged(
|
||||||
|
NETWORK,
|
||||||
|
createWifiNetworkCapabilities(wifiInfo)
|
||||||
|
)
|
||||||
|
|
||||||
|
assertThat(underTest.isWifiDefault.value).isTrue()
|
||||||
|
|
||||||
|
job.cancel()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun isWifiDefault_cellularVcnNetwork_isTrue() = runBlocking(IMMEDIATE) {
|
||||||
|
val job = underTest.isWifiDefault.launchIn(this)
|
||||||
|
|
||||||
|
val capabilities = mock<NetworkCapabilities>().apply {
|
||||||
|
whenever(this.hasTransport(TRANSPORT_CELLULAR)).thenReturn(true)
|
||||||
|
whenever(this.transportInfo).thenReturn(VcnTransportInfo(PRIMARY_WIFI_INFO))
|
||||||
|
}
|
||||||
|
|
||||||
|
getDefaultNetworkCallback().onCapabilitiesChanged(NETWORK, capabilities)
|
||||||
|
|
||||||
|
assertThat(underTest.isWifiDefault.value).isTrue()
|
||||||
|
|
||||||
|
job.cancel()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun isWifiDefault_cellularNotVcnNetwork_isFalse() = runBlocking(IMMEDIATE) {
|
||||||
|
val job = underTest.isWifiDefault.launchIn(this)
|
||||||
|
|
||||||
|
val capabilities = mock<NetworkCapabilities>().apply {
|
||||||
|
whenever(this.hasTransport(TRANSPORT_CELLULAR)).thenReturn(true)
|
||||||
|
whenever(this.transportInfo).thenReturn(mock())
|
||||||
|
}
|
||||||
|
|
||||||
|
getDefaultNetworkCallback().onCapabilitiesChanged(NETWORK, capabilities)
|
||||||
|
|
||||||
|
assertThat(underTest.isWifiDefault.value).isFalse()
|
||||||
|
|
||||||
|
job.cancel()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun isWifiDefault_wifiNetworkLost_isFalse() = runBlocking(IMMEDIATE) {
|
||||||
|
val job = underTest.isWifiDefault.launchIn(this)
|
||||||
|
|
||||||
|
// First, add a network
|
||||||
|
getDefaultNetworkCallback()
|
||||||
|
.onCapabilitiesChanged(NETWORK, createWifiNetworkCapabilities(PRIMARY_WIFI_INFO))
|
||||||
|
assertThat(underTest.isWifiDefault.value).isTrue()
|
||||||
|
|
||||||
|
// WHEN the network is lost
|
||||||
|
getDefaultNetworkCallback().onLost(NETWORK)
|
||||||
|
|
||||||
|
// THEN we update to false
|
||||||
|
assertThat(underTest.isWifiDefault.value).isFalse()
|
||||||
|
|
||||||
|
job.cancel()
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun wifiNetwork_initiallyGetsDefault() = runBlocking(IMMEDIATE) {
|
fun wifiNetwork_initiallyGetsDefault() = runBlocking(IMMEDIATE) {
|
||||||
var latest: WifiNetworkModel? = null
|
var latest: WifiNetworkModel? = null
|
||||||
@@ -745,6 +822,12 @@ class WifiRepositoryImplTest : SysuiTestCase() {
|
|||||||
return callbackCaptor.value!!
|
return callbackCaptor.value!!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getDefaultNetworkCallback(): ConnectivityManager.NetworkCallback {
|
||||||
|
val callbackCaptor = argumentCaptor<ConnectivityManager.NetworkCallback>()
|
||||||
|
verify(connectivityManager).registerDefaultNetworkCallback(callbackCaptor.capture())
|
||||||
|
return callbackCaptor.value!!
|
||||||
|
}
|
||||||
|
|
||||||
private fun createWifiNetworkCapabilities(
|
private fun createWifiNetworkCapabilities(
|
||||||
wifiInfo: WifiInfo,
|
wifiInfo: WifiInfo,
|
||||||
isValidated: Boolean = true,
|
isValidated: Boolean = true,
|
||||||
|
|||||||
@@ -177,6 +177,29 @@ class WifiInteractorTest : SysuiTestCase() {
|
|||||||
job.cancel()
|
job.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun isDefault_matchesRepoIsDefault() = runBlocking(IMMEDIATE) {
|
||||||
|
var latest: Boolean? = null
|
||||||
|
val job = underTest
|
||||||
|
.isDefault
|
||||||
|
.onEach { latest = it }
|
||||||
|
.launchIn(this)
|
||||||
|
|
||||||
|
wifiRepository.setIsWifiDefault(true)
|
||||||
|
yield()
|
||||||
|
assertThat(latest).isTrue()
|
||||||
|
|
||||||
|
wifiRepository.setIsWifiDefault(false)
|
||||||
|
yield()
|
||||||
|
assertThat(latest).isFalse()
|
||||||
|
|
||||||
|
wifiRepository.setIsWifiDefault(true)
|
||||||
|
yield()
|
||||||
|
assertThat(latest).isTrue()
|
||||||
|
|
||||||
|
job.cancel()
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun wifiNetwork_matchesRepoWifiNetwork() = runBlocking(IMMEDIATE) {
|
fun wifiNetwork_matchesRepoWifiNetwork() = runBlocking(IMMEDIATE) {
|
||||||
val wifiNetwork = WifiNetworkModel.Active(
|
val wifiNetwork = WifiNetworkModel.Active(
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ internal class WifiViewModelIconParameterizedTest(private val testCase: TestCase
|
|||||||
fun wifiIcon() =
|
fun wifiIcon() =
|
||||||
runBlocking(IMMEDIATE) {
|
runBlocking(IMMEDIATE) {
|
||||||
wifiRepository.setIsWifiEnabled(testCase.enabled)
|
wifiRepository.setIsWifiEnabled(testCase.enabled)
|
||||||
|
wifiRepository.setIsWifiDefault(testCase.isDefault)
|
||||||
connectivityRepository.setForceHiddenIcons(
|
connectivityRepository.setForceHiddenIcons(
|
||||||
if (testCase.forceHidden) {
|
if (testCase.forceHidden) {
|
||||||
setOf(ConnectivitySlot.WIFI)
|
setOf(ConnectivitySlot.WIFI)
|
||||||
@@ -152,6 +153,7 @@ internal class WifiViewModelIconParameterizedTest(private val testCase: TestCase
|
|||||||
val forceHidden: Boolean = false,
|
val forceHidden: Boolean = false,
|
||||||
val alwaysShowIconWhenEnabled: Boolean = false,
|
val alwaysShowIconWhenEnabled: Boolean = false,
|
||||||
val hasDataCapabilities: Boolean = true,
|
val hasDataCapabilities: Boolean = true,
|
||||||
|
val isDefault: Boolean = false,
|
||||||
val network: WifiNetworkModel,
|
val network: WifiNetworkModel,
|
||||||
|
|
||||||
/** The expected output. Null if we expect the output to be null. */
|
/** The expected output. Null if we expect the output to be null. */
|
||||||
@@ -162,6 +164,7 @@ internal class WifiViewModelIconParameterizedTest(private val testCase: TestCase
|
|||||||
"forceHidden=$forceHidden, " +
|
"forceHidden=$forceHidden, " +
|
||||||
"showWhenEnabled=$alwaysShowIconWhenEnabled, " +
|
"showWhenEnabled=$alwaysShowIconWhenEnabled, " +
|
||||||
"hasDataCaps=$hasDataCapabilities, " +
|
"hasDataCaps=$hasDataCapabilities, " +
|
||||||
|
"isDefault=$isDefault, " +
|
||||||
"network=$network) then " +
|
"network=$network) then " +
|
||||||
"EXPECTED($expected)"
|
"EXPECTED($expected)"
|
||||||
}
|
}
|
||||||
@@ -296,6 +299,46 @@ internal class WifiViewModelIconParameterizedTest(private val testCase: TestCase
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
// isDefault = true => all Inactive and Active networks shown
|
||||||
|
TestCase(
|
||||||
|
isDefault = true,
|
||||||
|
network = WifiNetworkModel.Inactive,
|
||||||
|
expected =
|
||||||
|
Expected(
|
||||||
|
iconResource = WIFI_NO_NETWORK,
|
||||||
|
contentDescription = { context ->
|
||||||
|
"${context.getString(WIFI_NO_CONNECTION)}," +
|
||||||
|
context.getString(NO_INTERNET)
|
||||||
|
},
|
||||||
|
description = "No network icon",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TestCase(
|
||||||
|
isDefault = true,
|
||||||
|
network = WifiNetworkModel.Active(NETWORK_ID, isValidated = false, level = 3),
|
||||||
|
expected =
|
||||||
|
Expected(
|
||||||
|
iconResource = WIFI_NO_INTERNET_ICONS[3],
|
||||||
|
contentDescription = { context ->
|
||||||
|
"${context.getString(WIFI_CONNECTION_STRENGTH[3])}," +
|
||||||
|
context.getString(NO_INTERNET)
|
||||||
|
},
|
||||||
|
description = "No internet level 3 icon",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TestCase(
|
||||||
|
isDefault = true,
|
||||||
|
network = WifiNetworkModel.Active(NETWORK_ID, isValidated = true, level = 1),
|
||||||
|
expected =
|
||||||
|
Expected(
|
||||||
|
iconResource = WIFI_FULL_ICONS[1],
|
||||||
|
contentDescription = { context ->
|
||||||
|
context.getString(WIFI_CONNECTION_STRENGTH[1])
|
||||||
|
},
|
||||||
|
description = "Full internet level 1 icon",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
// network = CarrierMerged => not shown
|
// network = CarrierMerged => not shown
|
||||||
TestCase(
|
TestCase(
|
||||||
network = WifiNetworkModel.CarrierMerged,
|
network = WifiNetworkModel.CarrierMerged,
|
||||||
|
|||||||
@@ -76,6 +76,8 @@ class WifiViewModelTest : SysuiTestCase() {
|
|||||||
scope.cancel()
|
scope.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// See [WifiViewModelIconParameterizedTest] for additional view model tests.
|
||||||
|
|
||||||
// Note on testing: [WifiViewModel] exposes 3 different instances of
|
// Note on testing: [WifiViewModel] exposes 3 different instances of
|
||||||
// [LocationBasedWifiViewModel]. In practice, these 3 different instances will get the exact
|
// [LocationBasedWifiViewModel]. In practice, these 3 different instances will get the exact
|
||||||
// same data for icon, activity, etc. flows. So, most of these tests will test just one of the
|
// same data for icon, activity, etc. flows. So, most of these tests will test just one of the
|
||||||
|
|||||||
Reference in New Issue
Block a user