Loading packages/SettingsLib/src/com/android/settingslib/Utils.java +34 −30 Original line number Diff line number Diff line Loading @@ -549,7 +549,12 @@ public class Utils { /** * Return the combined service state. * To make behavior consistent with SystemUI and Settings/AboutPhone/SIM status UI * To make behavior consistent with SystemUI and Settings/AboutPhone/SIM status UI. * * This method returns a single service state int if either the voice reg state is * {@link ServiceState#STATE_IN_SERVICE} or if data network is registered via a * WWAN transport type. We consider the combined service state of an IWLAN network * to be OOS. * * @param serviceState Service state. {@link ServiceState} */ Loading @@ -558,23 +563,37 @@ public class Utils { return ServiceState.STATE_OUT_OF_SERVICE; } // Consider the device to be in service if either voice or data // service is available. Some SIM cards are marketed as data-only // and do not support voice service, and on these SIM cards, we // want to show signal bars for data service as well as the "no // service" or "emergency calls only" text that indicates that voice // is not available. Note that we ignore the IWLAN service state // because that state indicates the use of VoWIFI and not cell service final int state = serviceState.getState(); final int dataState = serviceState.getDataRegistrationState(); final int voiceRegState = serviceState.getVoiceRegState(); if (state == ServiceState.STATE_OUT_OF_SERVICE || state == ServiceState.STATE_EMERGENCY_ONLY) { if (dataState == ServiceState.STATE_IN_SERVICE && isNotInIwlan(serviceState)) { // Consider a mobile connection to be "in service" if either voice is IN_SERVICE // or the data registration reports IN_SERVICE on a transport type of WWAN. This // effectively excludes the IWLAN condition. IWLAN connections imply service via // Wi-Fi rather than cellular, and so we do not consider these transports when // determining if cellular is "in service". if (voiceRegState == ServiceState.STATE_OUT_OF_SERVICE || voiceRegState == ServiceState.STATE_EMERGENCY_ONLY) { if (isDataRegInWwanAndInService(serviceState)) { return ServiceState.STATE_IN_SERVICE; } } return state; return voiceRegState; } // ServiceState#mDataRegState can be set to IN_SERVICE if the network is registered // on either a WLAN or WWAN network. Since we want to exclude the WLAN network, we can // query the WWAN network directly and check for its registration state private static boolean isDataRegInWwanAndInService(ServiceState serviceState) { final NetworkRegistrationInfo networkRegWwan = serviceState.getNetworkRegistrationInfo( NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN); if (networkRegWwan == null) { return false; } return networkRegWwan.isInService(); } /** Get the corresponding adaptive icon drawable. */ Loading @@ -598,21 +617,6 @@ public class Utils { UserHandle.getUserHandleForUid(appInfo.uid)); } private static boolean isNotInIwlan(ServiceState serviceState) { final NetworkRegistrationInfo networkRegWlan = serviceState.getNetworkRegistrationInfo( NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WLAN); if (networkRegWlan == null) { return true; } final boolean isInIwlan = (networkRegWlan.getRegistrationState() == NetworkRegistrationInfo.REGISTRATION_STATE_HOME) || (networkRegWlan.getRegistrationState() == NetworkRegistrationInfo.REGISTRATION_STATE_ROAMING); return !isInIwlan; } /** * Returns a bitmap with rounded corner. * Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/UtilsTest.java +28 −24 Original line number Diff line number Diff line Loading @@ -200,47 +200,55 @@ public class UtilsTest { @Test public void isInService_voiceInService_returnTrue() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE); when(mServiceState.getVoiceRegState()).thenReturn(ServiceState.STATE_IN_SERVICE); assertThat(Utils.isInService(mServiceState)).isTrue(); } @Test public void isInService_voiceOutOfServiceDataInService_returnTrue() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getVoiceRegState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getDataRegistrationState()).thenReturn(ServiceState.STATE_IN_SERVICE); when(mServiceState.getNetworkRegistrationInfo(NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WLAN)).thenReturn(mNetworkRegistrationInfo); when(mNetworkRegistrationInfo.getRegistrationState()).thenReturn( NetworkRegistrationInfo.REGISTRATION_STATE_UNKNOWN); AccessNetworkConstants.TRANSPORT_TYPE_WWAN)).thenReturn(mNetworkRegistrationInfo); when(mNetworkRegistrationInfo.isInService()).thenReturn(true); assertThat(Utils.isInService(mServiceState)).isTrue(); } @Test public void isInService_voiceOutOfServiceDataInServiceOnIwLan_returnFalse() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getVoiceRegState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getNetworkRegistrationInfo(NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WLAN)).thenReturn(mNetworkRegistrationInfo); when(mNetworkRegistrationInfo.getRegistrationState()).thenReturn( NetworkRegistrationInfo.REGISTRATION_STATE_HOME); when(mServiceState.getDataRegistrationState()).thenReturn(ServiceState.STATE_IN_SERVICE); when(mNetworkRegistrationInfo.isInService()).thenReturn(true); assertThat(Utils.isInService(mServiceState)).isFalse(); } @Test public void isInService_voiceOutOfServiceDataNull_returnFalse() { when(mServiceState.getVoiceRegState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getNetworkRegistrationInfo(NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN)).thenReturn(null); assertThat(Utils.isInService(mServiceState)).isFalse(); } @Test public void isInService_voiceOutOfServiceDataOutOfService_returnFalse() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getDataRegistrationState()).thenReturn( ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getVoiceRegState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getNetworkRegistrationInfo(NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN)).thenReturn(mNetworkRegistrationInfo); when(mNetworkRegistrationInfo.isInService()).thenReturn(false); assertThat(Utils.isInService(mServiceState)).isFalse(); } @Test public void isInService_ServiceStatePowerOff_returnFalse() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_POWER_OFF); when(mServiceState.getVoiceRegState()).thenReturn(ServiceState.STATE_POWER_OFF); assertThat(Utils.isInService(mServiceState)).isFalse(); } Loading @@ -253,7 +261,7 @@ public class UtilsTest { @Test public void getCombinedServiceState_ServiceStatePowerOff_returnPowerOff() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_POWER_OFF); when(mServiceState.getVoiceRegState()).thenReturn(ServiceState.STATE_POWER_OFF); assertThat(Utils.getCombinedServiceState(mServiceState)).isEqualTo( ServiceState.STATE_POWER_OFF); Loading @@ -261,7 +269,7 @@ public class UtilsTest { @Test public void getCombinedServiceState_voiceInService_returnInService() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE); when(mServiceState.getVoiceRegState()).thenReturn(ServiceState.STATE_IN_SERVICE); assertThat(Utils.getCombinedServiceState(mServiceState)).isEqualTo( ServiceState.STATE_IN_SERVICE); Loading @@ -269,12 +277,10 @@ public class UtilsTest { @Test public void getCombinedServiceState_voiceOutOfServiceDataInService_returnInService() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getDataRegistrationState()).thenReturn(ServiceState.STATE_IN_SERVICE); when(mServiceState.getVoiceRegState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getNetworkRegistrationInfo(NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WLAN)).thenReturn(mNetworkRegistrationInfo); when(mNetworkRegistrationInfo.getRegistrationState()).thenReturn( NetworkRegistrationInfo.REGISTRATION_STATE_UNKNOWN); AccessNetworkConstants.TRANSPORT_TYPE_WWAN)).thenReturn(mNetworkRegistrationInfo); when(mNetworkRegistrationInfo.isInService()).thenReturn(true); assertThat(Utils.getCombinedServiceState(mServiceState)).isEqualTo( ServiceState.STATE_IN_SERVICE); Loading @@ -282,12 +288,10 @@ public class UtilsTest { @Test public void getCombinedServiceState_voiceOutOfServiceDataInServiceOnIwLan_returnOutOfService() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getDataRegistrationState()).thenReturn(ServiceState.STATE_IN_SERVICE); when(mServiceState.getVoiceRegState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getNetworkRegistrationInfo(NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WLAN)).thenReturn(mNetworkRegistrationInfo); when(mNetworkRegistrationInfo.getRegistrationState()).thenReturn( NetworkRegistrationInfo.REGISTRATION_STATE_HOME); when(mNetworkRegistrationInfo.isInService()).thenReturn(true); assertThat(Utils.getCombinedServiceState(mServiceState)).isEqualTo( ServiceState.STATE_OUT_OF_SERVICE); Loading @@ -295,7 +299,7 @@ public class UtilsTest { @Test public void getCombinedServiceState_voiceOutOfServiceDataOutOfService_returnOutOfService() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getVoiceRegState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getDataRegistrationState()).thenReturn( ServiceState.STATE_OUT_OF_SERVICE); Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/connectivity/NetworkControllerBaseTest.java +23 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ package com.android.systemui.statusbar.connectivity; import static android.telephony.AccessNetworkConstants.TRANSPORT_TYPE_WWAN; import static android.telephony.NetworkRegistrationInfo.DOMAIN_PS; import static android.telephony.NetworkRegistrationInfo.REGISTRATION_STATE_DENIED; import static android.telephony.NetworkRegistrationInfo.REGISTRATION_STATE_HOME; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNotNull; Loading Loading @@ -439,11 +441,29 @@ public class NetworkControllerBaseTest extends SysuiTestCase { public void setVoiceRegState(int voiceRegState) { when(mServiceState.getState()).thenReturn(voiceRegState); when(mServiceState.getVoiceRegState()).thenReturn(voiceRegState); updateServiceState(); } public void setDataRegState(int dataRegState) { when(mServiceState.getDataRegistrationState()).thenReturn(dataRegState); public void setDataRegInService(boolean inService) { // mFakeRegInfo#isInService() // Utils#isInService uses NetworkRegistrationInfo#isInService(). Since we can't // mock the answer here, just set the bit based on what the caller wants NetworkRegistrationInfo.Builder builder = new NetworkRegistrationInfo.Builder() .setTransportType(TRANSPORT_TYPE_WWAN) .setDomain(DOMAIN_PS) .setAccessNetworkTechnology(TelephonyManager.NETWORK_TYPE_LTE); if (inService) { builder.setRegistrationState(REGISTRATION_STATE_HOME); } else { builder.setRegistrationState(REGISTRATION_STATE_DENIED); } NetworkRegistrationInfo fakeRegInfo = builder.build(); when(mServiceState.getNetworkRegistrationInfo(DOMAIN_PS, TRANSPORT_TYPE_WWAN)) .thenReturn(fakeRegInfo); updateServiceState(); } Loading Loading @@ -658,3 +678,4 @@ public class NetworkControllerBaseTest extends SysuiTestCase { assertEquals("Data network name", expected, mNetworkController.getMobileDataNetworkName()); } } packages/SystemUI/tests/src/com/android/systemui/statusbar/connectivity/NetworkControllerDataTest.java +2 −1 Original line number Diff line number Diff line Loading @@ -340,7 +340,7 @@ public class NetworkControllerDataTest extends NetworkControllerBaseTest { public void testIsDataInService_notInService_false() { setupDefaultSignal(); setVoiceRegState(ServiceState.STATE_OUT_OF_SERVICE); setDataRegState(ServiceState.STATE_OUT_OF_SERVICE); setDataRegInService(false); assertFalse(mNetworkController.isMobileDataNetworkInService()); } Loading Loading @@ -408,3 +408,4 @@ public class NetworkControllerDataTest extends NetworkControllerBaseTest { false); } } packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryTest.kt +32 −16 Original line number Diff line number Diff line Loading @@ -19,8 +19,13 @@ package com.android.systemui.statusbar.pipeline.mobile.data.repository.prod import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.telephony.AccessNetworkConstants.TRANSPORT_TYPE_WLAN import android.telephony.AccessNetworkConstants.TRANSPORT_TYPE_WWAN import android.telephony.CarrierConfigManager.KEY_INFLATE_SIGNAL_STRENGTH_BOOL import android.telephony.NetworkRegistrationInfo import android.telephony.NetworkRegistrationInfo.DOMAIN_PS import android.telephony.NetworkRegistrationInfo.REGISTRATION_STATE_DENIED import android.telephony.NetworkRegistrationInfo.REGISTRATION_STATE_HOME import android.telephony.ServiceState import android.telephony.ServiceState.STATE_IN_SERVICE import android.telephony.ServiceState.STATE_OUT_OF_SERVICE Loading Loading @@ -80,7 +85,6 @@ import com.android.systemui.statusbar.pipeline.shared.data.model.DataActivityMod import com.android.systemui.statusbar.pipeline.shared.data.model.toMobileDataActivityModel import com.android.systemui.util.mockito.any import com.android.systemui.util.mockito.argumentCaptor import com.android.systemui.util.mockito.mock import com.android.systemui.util.mockito.whenever import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.ExperimentalCoroutinesApi Loading Loading @@ -801,11 +805,18 @@ class MobileConnectionRepositoryTest : SysuiTestCase() { var latest: Boolean? = null val job = underTest.isInService.onEach { latest = it }.launchIn(this) val nriInService = NetworkRegistrationInfo.Builder() .setDomain(DOMAIN_PS) .setTransportType(TRANSPORT_TYPE_WWAN) .setRegistrationState(REGISTRATION_STATE_HOME) .build() getTelephonyCallbackForType<ServiceStateListener>() .onServiceStateChanged( ServiceState().also { it.voiceRegState = STATE_IN_SERVICE it.dataRegState = STATE_IN_SERVICE it.addNetworkRegistrationInfo(nriInService) } ) Loading @@ -814,17 +825,23 @@ class MobileConnectionRepositoryTest : SysuiTestCase() { getTelephonyCallbackForType<ServiceStateListener>() .onServiceStateChanged( ServiceState().also { it.dataRegState = STATE_IN_SERVICE it.voiceRegState = STATE_OUT_OF_SERVICE it.addNetworkRegistrationInfo(nriInService) } ) assertThat(latest).isTrue() val nriNotInService = NetworkRegistrationInfo.Builder() .setDomain(DOMAIN_PS) .setTransportType(TRANSPORT_TYPE_WWAN) .setRegistrationState(REGISTRATION_STATE_DENIED) .build() getTelephonyCallbackForType<ServiceStateListener>() .onServiceStateChanged( ServiceState().also { it.voiceRegState = STATE_OUT_OF_SERVICE it.dataRegState = STATE_OUT_OF_SERVICE it.addNetworkRegistrationInfo(nriNotInService) } ) assertThat(latest).isFalse() Loading @@ -838,18 +855,17 @@ class MobileConnectionRepositoryTest : SysuiTestCase() { var latest: Boolean? = null val job = underTest.isInService.onEach { latest = it }.launchIn(this) // Mock the service state here so we can make it specifically IWLAN val serviceState: ServiceState = mock() whenever(serviceState.state).thenReturn(STATE_OUT_OF_SERVICE) whenever(serviceState.dataRegistrationState).thenReturn(STATE_IN_SERVICE) // See [com.android.settingslib.Utils.isInService] for more info. This is one way to // make the network look like IWLAN val networkRegWlan: NetworkRegistrationInfo = mock() whenever(serviceState.getNetworkRegistrationInfo(any(), any())) .thenReturn(networkRegWlan) whenever(networkRegWlan.registrationState) .thenReturn(NetworkRegistrationInfo.REGISTRATION_STATE_HOME) val iwlanData = NetworkRegistrationInfo.Builder() .setDomain(DOMAIN_PS) .setTransportType(TRANSPORT_TYPE_WLAN) .setRegistrationState(REGISTRATION_STATE_HOME) .build() val serviceState = ServiceState().also { it.voiceRegState = STATE_OUT_OF_SERVICE it.addNetworkRegistrationInfo(iwlanData) } getTelephonyCallbackForType<ServiceStateListener>().onServiceStateChanged(serviceState) assertThat(latest).isFalse() Loading Loading
packages/SettingsLib/src/com/android/settingslib/Utils.java +34 −30 Original line number Diff line number Diff line Loading @@ -549,7 +549,12 @@ public class Utils { /** * Return the combined service state. * To make behavior consistent with SystemUI and Settings/AboutPhone/SIM status UI * To make behavior consistent with SystemUI and Settings/AboutPhone/SIM status UI. * * This method returns a single service state int if either the voice reg state is * {@link ServiceState#STATE_IN_SERVICE} or if data network is registered via a * WWAN transport type. We consider the combined service state of an IWLAN network * to be OOS. * * @param serviceState Service state. {@link ServiceState} */ Loading @@ -558,23 +563,37 @@ public class Utils { return ServiceState.STATE_OUT_OF_SERVICE; } // Consider the device to be in service if either voice or data // service is available. Some SIM cards are marketed as data-only // and do not support voice service, and on these SIM cards, we // want to show signal bars for data service as well as the "no // service" or "emergency calls only" text that indicates that voice // is not available. Note that we ignore the IWLAN service state // because that state indicates the use of VoWIFI and not cell service final int state = serviceState.getState(); final int dataState = serviceState.getDataRegistrationState(); final int voiceRegState = serviceState.getVoiceRegState(); if (state == ServiceState.STATE_OUT_OF_SERVICE || state == ServiceState.STATE_EMERGENCY_ONLY) { if (dataState == ServiceState.STATE_IN_SERVICE && isNotInIwlan(serviceState)) { // Consider a mobile connection to be "in service" if either voice is IN_SERVICE // or the data registration reports IN_SERVICE on a transport type of WWAN. This // effectively excludes the IWLAN condition. IWLAN connections imply service via // Wi-Fi rather than cellular, and so we do not consider these transports when // determining if cellular is "in service". if (voiceRegState == ServiceState.STATE_OUT_OF_SERVICE || voiceRegState == ServiceState.STATE_EMERGENCY_ONLY) { if (isDataRegInWwanAndInService(serviceState)) { return ServiceState.STATE_IN_SERVICE; } } return state; return voiceRegState; } // ServiceState#mDataRegState can be set to IN_SERVICE if the network is registered // on either a WLAN or WWAN network. Since we want to exclude the WLAN network, we can // query the WWAN network directly and check for its registration state private static boolean isDataRegInWwanAndInService(ServiceState serviceState) { final NetworkRegistrationInfo networkRegWwan = serviceState.getNetworkRegistrationInfo( NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN); if (networkRegWwan == null) { return false; } return networkRegWwan.isInService(); } /** Get the corresponding adaptive icon drawable. */ Loading @@ -598,21 +617,6 @@ public class Utils { UserHandle.getUserHandleForUid(appInfo.uid)); } private static boolean isNotInIwlan(ServiceState serviceState) { final NetworkRegistrationInfo networkRegWlan = serviceState.getNetworkRegistrationInfo( NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WLAN); if (networkRegWlan == null) { return true; } final boolean isInIwlan = (networkRegWlan.getRegistrationState() == NetworkRegistrationInfo.REGISTRATION_STATE_HOME) || (networkRegWlan.getRegistrationState() == NetworkRegistrationInfo.REGISTRATION_STATE_ROAMING); return !isInIwlan; } /** * Returns a bitmap with rounded corner. * Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/UtilsTest.java +28 −24 Original line number Diff line number Diff line Loading @@ -200,47 +200,55 @@ public class UtilsTest { @Test public void isInService_voiceInService_returnTrue() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE); when(mServiceState.getVoiceRegState()).thenReturn(ServiceState.STATE_IN_SERVICE); assertThat(Utils.isInService(mServiceState)).isTrue(); } @Test public void isInService_voiceOutOfServiceDataInService_returnTrue() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getVoiceRegState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getDataRegistrationState()).thenReturn(ServiceState.STATE_IN_SERVICE); when(mServiceState.getNetworkRegistrationInfo(NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WLAN)).thenReturn(mNetworkRegistrationInfo); when(mNetworkRegistrationInfo.getRegistrationState()).thenReturn( NetworkRegistrationInfo.REGISTRATION_STATE_UNKNOWN); AccessNetworkConstants.TRANSPORT_TYPE_WWAN)).thenReturn(mNetworkRegistrationInfo); when(mNetworkRegistrationInfo.isInService()).thenReturn(true); assertThat(Utils.isInService(mServiceState)).isTrue(); } @Test public void isInService_voiceOutOfServiceDataInServiceOnIwLan_returnFalse() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getVoiceRegState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getNetworkRegistrationInfo(NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WLAN)).thenReturn(mNetworkRegistrationInfo); when(mNetworkRegistrationInfo.getRegistrationState()).thenReturn( NetworkRegistrationInfo.REGISTRATION_STATE_HOME); when(mServiceState.getDataRegistrationState()).thenReturn(ServiceState.STATE_IN_SERVICE); when(mNetworkRegistrationInfo.isInService()).thenReturn(true); assertThat(Utils.isInService(mServiceState)).isFalse(); } @Test public void isInService_voiceOutOfServiceDataNull_returnFalse() { when(mServiceState.getVoiceRegState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getNetworkRegistrationInfo(NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN)).thenReturn(null); assertThat(Utils.isInService(mServiceState)).isFalse(); } @Test public void isInService_voiceOutOfServiceDataOutOfService_returnFalse() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getDataRegistrationState()).thenReturn( ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getVoiceRegState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getNetworkRegistrationInfo(NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN)).thenReturn(mNetworkRegistrationInfo); when(mNetworkRegistrationInfo.isInService()).thenReturn(false); assertThat(Utils.isInService(mServiceState)).isFalse(); } @Test public void isInService_ServiceStatePowerOff_returnFalse() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_POWER_OFF); when(mServiceState.getVoiceRegState()).thenReturn(ServiceState.STATE_POWER_OFF); assertThat(Utils.isInService(mServiceState)).isFalse(); } Loading @@ -253,7 +261,7 @@ public class UtilsTest { @Test public void getCombinedServiceState_ServiceStatePowerOff_returnPowerOff() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_POWER_OFF); when(mServiceState.getVoiceRegState()).thenReturn(ServiceState.STATE_POWER_OFF); assertThat(Utils.getCombinedServiceState(mServiceState)).isEqualTo( ServiceState.STATE_POWER_OFF); Loading @@ -261,7 +269,7 @@ public class UtilsTest { @Test public void getCombinedServiceState_voiceInService_returnInService() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE); when(mServiceState.getVoiceRegState()).thenReturn(ServiceState.STATE_IN_SERVICE); assertThat(Utils.getCombinedServiceState(mServiceState)).isEqualTo( ServiceState.STATE_IN_SERVICE); Loading @@ -269,12 +277,10 @@ public class UtilsTest { @Test public void getCombinedServiceState_voiceOutOfServiceDataInService_returnInService() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getDataRegistrationState()).thenReturn(ServiceState.STATE_IN_SERVICE); when(mServiceState.getVoiceRegState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getNetworkRegistrationInfo(NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WLAN)).thenReturn(mNetworkRegistrationInfo); when(mNetworkRegistrationInfo.getRegistrationState()).thenReturn( NetworkRegistrationInfo.REGISTRATION_STATE_UNKNOWN); AccessNetworkConstants.TRANSPORT_TYPE_WWAN)).thenReturn(mNetworkRegistrationInfo); when(mNetworkRegistrationInfo.isInService()).thenReturn(true); assertThat(Utils.getCombinedServiceState(mServiceState)).isEqualTo( ServiceState.STATE_IN_SERVICE); Loading @@ -282,12 +288,10 @@ public class UtilsTest { @Test public void getCombinedServiceState_voiceOutOfServiceDataInServiceOnIwLan_returnOutOfService() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getDataRegistrationState()).thenReturn(ServiceState.STATE_IN_SERVICE); when(mServiceState.getVoiceRegState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getNetworkRegistrationInfo(NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WLAN)).thenReturn(mNetworkRegistrationInfo); when(mNetworkRegistrationInfo.getRegistrationState()).thenReturn( NetworkRegistrationInfo.REGISTRATION_STATE_HOME); when(mNetworkRegistrationInfo.isInService()).thenReturn(true); assertThat(Utils.getCombinedServiceState(mServiceState)).isEqualTo( ServiceState.STATE_OUT_OF_SERVICE); Loading @@ -295,7 +299,7 @@ public class UtilsTest { @Test public void getCombinedServiceState_voiceOutOfServiceDataOutOfService_returnOutOfService() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getVoiceRegState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getDataRegistrationState()).thenReturn( ServiceState.STATE_OUT_OF_SERVICE); Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/connectivity/NetworkControllerBaseTest.java +23 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ package com.android.systemui.statusbar.connectivity; import static android.telephony.AccessNetworkConstants.TRANSPORT_TYPE_WWAN; import static android.telephony.NetworkRegistrationInfo.DOMAIN_PS; import static android.telephony.NetworkRegistrationInfo.REGISTRATION_STATE_DENIED; import static android.telephony.NetworkRegistrationInfo.REGISTRATION_STATE_HOME; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNotNull; Loading Loading @@ -439,11 +441,29 @@ public class NetworkControllerBaseTest extends SysuiTestCase { public void setVoiceRegState(int voiceRegState) { when(mServiceState.getState()).thenReturn(voiceRegState); when(mServiceState.getVoiceRegState()).thenReturn(voiceRegState); updateServiceState(); } public void setDataRegState(int dataRegState) { when(mServiceState.getDataRegistrationState()).thenReturn(dataRegState); public void setDataRegInService(boolean inService) { // mFakeRegInfo#isInService() // Utils#isInService uses NetworkRegistrationInfo#isInService(). Since we can't // mock the answer here, just set the bit based on what the caller wants NetworkRegistrationInfo.Builder builder = new NetworkRegistrationInfo.Builder() .setTransportType(TRANSPORT_TYPE_WWAN) .setDomain(DOMAIN_PS) .setAccessNetworkTechnology(TelephonyManager.NETWORK_TYPE_LTE); if (inService) { builder.setRegistrationState(REGISTRATION_STATE_HOME); } else { builder.setRegistrationState(REGISTRATION_STATE_DENIED); } NetworkRegistrationInfo fakeRegInfo = builder.build(); when(mServiceState.getNetworkRegistrationInfo(DOMAIN_PS, TRANSPORT_TYPE_WWAN)) .thenReturn(fakeRegInfo); updateServiceState(); } Loading Loading @@ -658,3 +678,4 @@ public class NetworkControllerBaseTest extends SysuiTestCase { assertEquals("Data network name", expected, mNetworkController.getMobileDataNetworkName()); } }
packages/SystemUI/tests/src/com/android/systemui/statusbar/connectivity/NetworkControllerDataTest.java +2 −1 Original line number Diff line number Diff line Loading @@ -340,7 +340,7 @@ public class NetworkControllerDataTest extends NetworkControllerBaseTest { public void testIsDataInService_notInService_false() { setupDefaultSignal(); setVoiceRegState(ServiceState.STATE_OUT_OF_SERVICE); setDataRegState(ServiceState.STATE_OUT_OF_SERVICE); setDataRegInService(false); assertFalse(mNetworkController.isMobileDataNetworkInService()); } Loading Loading @@ -408,3 +408,4 @@ public class NetworkControllerDataTest extends NetworkControllerBaseTest { false); } }
packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionRepositoryTest.kt +32 −16 Original line number Diff line number Diff line Loading @@ -19,8 +19,13 @@ package com.android.systemui.statusbar.pipeline.mobile.data.repository.prod import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.telephony.AccessNetworkConstants.TRANSPORT_TYPE_WLAN import android.telephony.AccessNetworkConstants.TRANSPORT_TYPE_WWAN import android.telephony.CarrierConfigManager.KEY_INFLATE_SIGNAL_STRENGTH_BOOL import android.telephony.NetworkRegistrationInfo import android.telephony.NetworkRegistrationInfo.DOMAIN_PS import android.telephony.NetworkRegistrationInfo.REGISTRATION_STATE_DENIED import android.telephony.NetworkRegistrationInfo.REGISTRATION_STATE_HOME import android.telephony.ServiceState import android.telephony.ServiceState.STATE_IN_SERVICE import android.telephony.ServiceState.STATE_OUT_OF_SERVICE Loading Loading @@ -80,7 +85,6 @@ import com.android.systemui.statusbar.pipeline.shared.data.model.DataActivityMod import com.android.systemui.statusbar.pipeline.shared.data.model.toMobileDataActivityModel import com.android.systemui.util.mockito.any import com.android.systemui.util.mockito.argumentCaptor import com.android.systemui.util.mockito.mock import com.android.systemui.util.mockito.whenever import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.ExperimentalCoroutinesApi Loading Loading @@ -801,11 +805,18 @@ class MobileConnectionRepositoryTest : SysuiTestCase() { var latest: Boolean? = null val job = underTest.isInService.onEach { latest = it }.launchIn(this) val nriInService = NetworkRegistrationInfo.Builder() .setDomain(DOMAIN_PS) .setTransportType(TRANSPORT_TYPE_WWAN) .setRegistrationState(REGISTRATION_STATE_HOME) .build() getTelephonyCallbackForType<ServiceStateListener>() .onServiceStateChanged( ServiceState().also { it.voiceRegState = STATE_IN_SERVICE it.dataRegState = STATE_IN_SERVICE it.addNetworkRegistrationInfo(nriInService) } ) Loading @@ -814,17 +825,23 @@ class MobileConnectionRepositoryTest : SysuiTestCase() { getTelephonyCallbackForType<ServiceStateListener>() .onServiceStateChanged( ServiceState().also { it.dataRegState = STATE_IN_SERVICE it.voiceRegState = STATE_OUT_OF_SERVICE it.addNetworkRegistrationInfo(nriInService) } ) assertThat(latest).isTrue() val nriNotInService = NetworkRegistrationInfo.Builder() .setDomain(DOMAIN_PS) .setTransportType(TRANSPORT_TYPE_WWAN) .setRegistrationState(REGISTRATION_STATE_DENIED) .build() getTelephonyCallbackForType<ServiceStateListener>() .onServiceStateChanged( ServiceState().also { it.voiceRegState = STATE_OUT_OF_SERVICE it.dataRegState = STATE_OUT_OF_SERVICE it.addNetworkRegistrationInfo(nriNotInService) } ) assertThat(latest).isFalse() Loading @@ -838,18 +855,17 @@ class MobileConnectionRepositoryTest : SysuiTestCase() { var latest: Boolean? = null val job = underTest.isInService.onEach { latest = it }.launchIn(this) // Mock the service state here so we can make it specifically IWLAN val serviceState: ServiceState = mock() whenever(serviceState.state).thenReturn(STATE_OUT_OF_SERVICE) whenever(serviceState.dataRegistrationState).thenReturn(STATE_IN_SERVICE) // See [com.android.settingslib.Utils.isInService] for more info. This is one way to // make the network look like IWLAN val networkRegWlan: NetworkRegistrationInfo = mock() whenever(serviceState.getNetworkRegistrationInfo(any(), any())) .thenReturn(networkRegWlan) whenever(networkRegWlan.registrationState) .thenReturn(NetworkRegistrationInfo.REGISTRATION_STATE_HOME) val iwlanData = NetworkRegistrationInfo.Builder() .setDomain(DOMAIN_PS) .setTransportType(TRANSPORT_TYPE_WLAN) .setRegistrationState(REGISTRATION_STATE_HOME) .build() val serviceState = ServiceState().also { it.voiceRegState = STATE_OUT_OF_SERVICE it.addNetworkRegistrationInfo(iwlanData) } getTelephonyCallbackForType<ServiceStateListener>().onServiceStateChanged(serviceState) assertThat(latest).isFalse() Loading