diff options
| -rw-r--r-- | packages/SettingsLib/src/com/android/settingslib/Utils.java | 27 | ||||
| -rw-r--r-- | packages/SettingsLib/tests/robotests/src/com/android/settingslib/UtilsTest.java | 40 |
2 files changed, 59 insertions, 8 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/Utils.java b/packages/SettingsLib/src/com/android/settingslib/Utils.java index d32e85f01962..ee44d0a606aa 100644 --- a/packages/SettingsLib/src/com/android/settingslib/Utils.java +++ b/packages/SettingsLib/src/com/android/settingslib/Utils.java @@ -1,7 +1,5 @@ package com.android.settingslib; -import static android.telephony.ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN; - import android.annotation.ColorInt; import android.content.Context; import android.content.Intent; @@ -25,6 +23,8 @@ import android.os.UserHandle; import android.os.UserManager; import android.print.PrintManager; import android.provider.Settings; +import android.telephony.AccessNetworkConstants; +import android.telephony.NetworkRegistrationInfo; import android.telephony.ServiceState; import com.android.internal.annotations.VisibleForTesting; @@ -420,15 +420,30 @@ public class Utils { // 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 - int state = serviceState.getState(); - int dataState = serviceState.getDataRegState(); + final int state = serviceState.getState(); + final int dataState = serviceState.getDataRegState(); + if (state == ServiceState.STATE_OUT_OF_SERVICE || state == ServiceState.STATE_EMERGENCY_ONLY) { - if (dataState == ServiceState.STATE_IN_SERVICE - && serviceState.getDataNetworkType() != RIL_RADIO_TECHNOLOGY_IWLAN) { + if (dataState == ServiceState.STATE_IN_SERVICE && isNotInIwlan(serviceState)) { return ServiceState.STATE_IN_SERVICE; } } return state; } + + 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; + } } diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/UtilsTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/UtilsTest.java index 4d76e44a3c50..51806e0d3c03 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/UtilsTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/UtilsTest.java @@ -38,6 +38,8 @@ import android.media.AudioManager; import android.os.SystemProperties; import android.os.UserHandle; import android.provider.Settings; +import android.telephony.AccessNetworkConstants; +import android.telephony.NetworkRegistrationInfo; import android.telephony.ServiceState; import android.text.TextUtils; @@ -74,6 +76,8 @@ public class UtilsTest { private LocationManager mLocationManager; @Mock private ServiceState mServiceState; + @Mock + private NetworkRegistrationInfo mNetworkRegistrationInfo; @Before public void setUp() { @@ -216,6 +220,7 @@ public class UtilsTest { @Test public void isInService_voiceInService_returnTrue() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE); + assertThat(Utils.isInService(mServiceState)).isTrue(); } @@ -223,15 +228,23 @@ public class UtilsTest { public void isInService_voiceOutOfServiceDataInService_returnTrue() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getDataRegState()).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); + assertThat(Utils.isInService(mServiceState)).isTrue(); } @Test public void isInService_voiceOutOfServiceDataInServiceOnIwLan_returnFalse() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); - when(mServiceState.getDataNetworkType()) - .thenReturn(ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN); + when(mServiceState.getNetworkRegistrationInfo(NetworkRegistrationInfo.DOMAIN_PS, + AccessNetworkConstants.TRANSPORT_TYPE_WLAN)).thenReturn(mNetworkRegistrationInfo); + when(mNetworkRegistrationInfo.getRegistrationState()).thenReturn( + NetworkRegistrationInfo.REGISTRATION_STATE_HOME); when(mServiceState.getDataRegState()).thenReturn(ServiceState.STATE_IN_SERVICE); + assertThat(Utils.isInService(mServiceState)).isFalse(); } @@ -239,12 +252,14 @@ public class UtilsTest { public void isInService_voiceOutOfServiceDataOutOfService_returnFalse() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getDataRegState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); + assertThat(Utils.isInService(mServiceState)).isFalse(); } @Test public void isInService_ServiceStatePowerOff_returnFalse() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_POWER_OFF); + assertThat(Utils.isInService(mServiceState)).isFalse(); } @@ -257,6 +272,7 @@ public class UtilsTest { @Test public void getCombinedServiceState_ServiceStatePowerOff_returnPowerOff() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_POWER_OFF); + assertThat(Utils.getCombinedServiceState(mServiceState)).isEqualTo( ServiceState.STATE_POWER_OFF); } @@ -264,6 +280,7 @@ public class UtilsTest { @Test public void getCombinedServiceState_voiceInService_returnInService() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE); + assertThat(Utils.getCombinedServiceState(mServiceState)).isEqualTo( ServiceState.STATE_IN_SERVICE); } @@ -272,14 +289,33 @@ public class UtilsTest { public void getCombinedServiceState_voiceOutOfServiceDataInService_returnInService() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getDataRegState()).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); + assertThat(Utils.getCombinedServiceState(mServiceState)).isEqualTo( ServiceState.STATE_IN_SERVICE); } @Test + public void getCombinedServiceState_voiceOutOfServiceDataInServiceOnIwLan_returnOutOfService() { + when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); + when(mServiceState.getDataRegState()).thenReturn(ServiceState.STATE_IN_SERVICE); + when(mServiceState.getNetworkRegistrationInfo(NetworkRegistrationInfo.DOMAIN_PS, + AccessNetworkConstants.TRANSPORT_TYPE_WLAN)).thenReturn(mNetworkRegistrationInfo); + when(mNetworkRegistrationInfo.getRegistrationState()).thenReturn( + NetworkRegistrationInfo.REGISTRATION_STATE_HOME); + + assertThat(Utils.getCombinedServiceState(mServiceState)).isEqualTo( + ServiceState.STATE_OUT_OF_SERVICE); + } + + @Test public void getCombinedServiceState_voiceOutOfServiceDataOutOfService_returnOutOfService() { when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); when(mServiceState.getDataRegState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE); + assertThat(Utils.getCombinedServiceState(mServiceState)).isEqualTo( ServiceState.STATE_OUT_OF_SERVICE); } |