Merge "[Mainline] decouple ServiceState.getDataNetworkType()"
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
package com.android.settingslib;
|
package com.android.settingslib;
|
||||||
|
|
||||||
import static android.telephony.ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN;
|
|
||||||
|
|
||||||
import android.annotation.ColorInt;
|
import android.annotation.ColorInt;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -25,6 +23,8 @@ import android.os.UserHandle;
|
|||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.print.PrintManager;
|
import android.print.PrintManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.telephony.AccessNetworkConstants;
|
||||||
|
import android.telephony.NetworkRegistrationInfo;
|
||||||
import android.telephony.ServiceState;
|
import android.telephony.ServiceState;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
@@ -420,15 +420,30 @@ public class Utils {
|
|||||||
// service" or "emergency calls only" text that indicates that voice
|
// service" or "emergency calls only" text that indicates that voice
|
||||||
// is not available. Note that we ignore the IWLAN service state
|
// is not available. Note that we ignore the IWLAN service state
|
||||||
// because that state indicates the use of VoWIFI and not cell service
|
// because that state indicates the use of VoWIFI and not cell service
|
||||||
int state = serviceState.getState();
|
final int state = serviceState.getState();
|
||||||
int dataState = serviceState.getDataRegState();
|
final int dataState = serviceState.getDataRegState();
|
||||||
|
|
||||||
if (state == ServiceState.STATE_OUT_OF_SERVICE
|
if (state == ServiceState.STATE_OUT_OF_SERVICE
|
||||||
|| state == ServiceState.STATE_EMERGENCY_ONLY) {
|
|| state == ServiceState.STATE_EMERGENCY_ONLY) {
|
||||||
if (dataState == ServiceState.STATE_IN_SERVICE
|
if (dataState == ServiceState.STATE_IN_SERVICE && isNotInIwlan(serviceState)) {
|
||||||
&& serviceState.getDataNetworkType() != RIL_RADIO_TECHNOLOGY_IWLAN) {
|
|
||||||
return ServiceState.STATE_IN_SERVICE;
|
return ServiceState.STATE_IN_SERVICE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return state;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ import android.media.AudioManager;
|
|||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.telephony.AccessNetworkConstants;
|
||||||
|
import android.telephony.NetworkRegistrationInfo;
|
||||||
import android.telephony.ServiceState;
|
import android.telephony.ServiceState;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
@@ -74,6 +76,8 @@ public class UtilsTest {
|
|||||||
private LocationManager mLocationManager;
|
private LocationManager mLocationManager;
|
||||||
@Mock
|
@Mock
|
||||||
private ServiceState mServiceState;
|
private ServiceState mServiceState;
|
||||||
|
@Mock
|
||||||
|
private NetworkRegistrationInfo mNetworkRegistrationInfo;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -216,6 +220,7 @@ public class UtilsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void isInService_voiceInService_returnTrue() {
|
public void isInService_voiceInService_returnTrue() {
|
||||||
when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE);
|
when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE);
|
||||||
|
|
||||||
assertThat(Utils.isInService(mServiceState)).isTrue();
|
assertThat(Utils.isInService(mServiceState)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,15 +228,23 @@ public class UtilsTest {
|
|||||||
public void isInService_voiceOutOfServiceDataInService_returnTrue() {
|
public void isInService_voiceOutOfServiceDataInService_returnTrue() {
|
||||||
when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
|
when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
|
||||||
when(mServiceState.getDataRegState()).thenReturn(ServiceState.STATE_IN_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();
|
assertThat(Utils.isInService(mServiceState)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isInService_voiceOutOfServiceDataInServiceOnIwLan_returnFalse() {
|
public void isInService_voiceOutOfServiceDataInServiceOnIwLan_returnFalse() {
|
||||||
when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
|
when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
|
||||||
when(mServiceState.getDataNetworkType())
|
when(mServiceState.getNetworkRegistrationInfo(NetworkRegistrationInfo.DOMAIN_PS,
|
||||||
.thenReturn(ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN);
|
AccessNetworkConstants.TRANSPORT_TYPE_WLAN)).thenReturn(mNetworkRegistrationInfo);
|
||||||
|
when(mNetworkRegistrationInfo.getRegistrationState()).thenReturn(
|
||||||
|
NetworkRegistrationInfo.REGISTRATION_STATE_HOME);
|
||||||
when(mServiceState.getDataRegState()).thenReturn(ServiceState.STATE_IN_SERVICE);
|
when(mServiceState.getDataRegState()).thenReturn(ServiceState.STATE_IN_SERVICE);
|
||||||
|
|
||||||
assertThat(Utils.isInService(mServiceState)).isFalse();
|
assertThat(Utils.isInService(mServiceState)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,12 +252,14 @@ public class UtilsTest {
|
|||||||
public void isInService_voiceOutOfServiceDataOutOfService_returnFalse() {
|
public void isInService_voiceOutOfServiceDataOutOfService_returnFalse() {
|
||||||
when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
|
when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
|
||||||
when(mServiceState.getDataRegState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
|
when(mServiceState.getDataRegState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
|
||||||
|
|
||||||
assertThat(Utils.isInService(mServiceState)).isFalse();
|
assertThat(Utils.isInService(mServiceState)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isInService_ServiceStatePowerOff_returnFalse() {
|
public void isInService_ServiceStatePowerOff_returnFalse() {
|
||||||
when(mServiceState.getState()).thenReturn(ServiceState.STATE_POWER_OFF);
|
when(mServiceState.getState()).thenReturn(ServiceState.STATE_POWER_OFF);
|
||||||
|
|
||||||
assertThat(Utils.isInService(mServiceState)).isFalse();
|
assertThat(Utils.isInService(mServiceState)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,6 +272,7 @@ public class UtilsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getCombinedServiceState_ServiceStatePowerOff_returnPowerOff() {
|
public void getCombinedServiceState_ServiceStatePowerOff_returnPowerOff() {
|
||||||
when(mServiceState.getState()).thenReturn(ServiceState.STATE_POWER_OFF);
|
when(mServiceState.getState()).thenReturn(ServiceState.STATE_POWER_OFF);
|
||||||
|
|
||||||
assertThat(Utils.getCombinedServiceState(mServiceState)).isEqualTo(
|
assertThat(Utils.getCombinedServiceState(mServiceState)).isEqualTo(
|
||||||
ServiceState.STATE_POWER_OFF);
|
ServiceState.STATE_POWER_OFF);
|
||||||
}
|
}
|
||||||
@@ -264,6 +280,7 @@ public class UtilsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getCombinedServiceState_voiceInService_returnInService() {
|
public void getCombinedServiceState_voiceInService_returnInService() {
|
||||||
when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE);
|
when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE);
|
||||||
|
|
||||||
assertThat(Utils.getCombinedServiceState(mServiceState)).isEqualTo(
|
assertThat(Utils.getCombinedServiceState(mServiceState)).isEqualTo(
|
||||||
ServiceState.STATE_IN_SERVICE);
|
ServiceState.STATE_IN_SERVICE);
|
||||||
}
|
}
|
||||||
@@ -272,14 +289,33 @@ public class UtilsTest {
|
|||||||
public void getCombinedServiceState_voiceOutOfServiceDataInService_returnInService() {
|
public void getCombinedServiceState_voiceOutOfServiceDataInService_returnInService() {
|
||||||
when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
|
when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
|
||||||
when(mServiceState.getDataRegState()).thenReturn(ServiceState.STATE_IN_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(
|
assertThat(Utils.getCombinedServiceState(mServiceState)).isEqualTo(
|
||||||
ServiceState.STATE_IN_SERVICE);
|
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
|
@Test
|
||||||
public void getCombinedServiceState_voiceOutOfServiceDataOutOfService_returnOutOfService() {
|
public void getCombinedServiceState_voiceOutOfServiceDataOutOfService_returnOutOfService() {
|
||||||
when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
|
when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
|
||||||
when(mServiceState.getDataRegState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
|
when(mServiceState.getDataRegState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
|
||||||
|
|
||||||
assertThat(Utils.getCombinedServiceState(mServiceState)).isEqualTo(
|
assertThat(Utils.getCombinedServiceState(mServiceState)).isEqualTo(
|
||||||
ServiceState.STATE_OUT_OF_SERVICE);
|
ServiceState.STATE_OUT_OF_SERVICE);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user