Block outgoing call if satellite is connected withing hysteresis time
Bug: 328117928
Manual Testing: b/328117928#comment3
Test Request Bugs: 329286654
Test: atest TelephonyConnectionServiceTest
Change-Id: Iaec3c4114086402a84ae14b1ca6f602f074281b6
diff --git a/src/com/android/services/telephony/TelephonyConnectionService.java b/src/com/android/services/telephony/TelephonyConnectionService.java
index 9300c84..92f7eab 100644
--- a/src/com/android/services/telephony/TelephonyConnectionService.java
+++ b/src/com/android/services/telephony/TelephonyConnectionService.java
@@ -4468,23 +4468,16 @@
return false;
}
- ServiceState serviceState = phone.getServiceState();
- if (serviceState == null) {
- return false;
- }
-
- if (!serviceState.isUsingNonTerrestrialNetwork()) {
+ if (!mSatelliteController.isInSatelliteModeForCarrierRoaming(phone)) {
// Device is not connected to satellite
return false;
}
- for (NetworkRegistrationInfo nri : serviceState.getNetworkRegistrationInfoList()) {
- if (nri.isNonTerrestrialNetwork()
- && nri.getAvailableServices().contains(
- NetworkRegistrationInfo.SERVICE_TYPE_VOICE)) {
- // Call is supported while using satellite
- return false;
- }
+ List<Integer> capabilities =
+ mSatelliteController.getCapabilitiesForCarrierRoamingSatelliteMode(phone);
+ if (capabilities.contains(NetworkRegistrationInfo.SERVICE_TYPE_VOICE)) {
+ // Call is supported while using satellite
+ return false;
}
// Call is disallowed while using satellite
diff --git a/tests/src/com/android/services/telephony/TelephonyConnectionServiceTest.java b/tests/src/com/android/services/telephony/TelephonyConnectionServiceTest.java
index f6b043a..bad3b4e 100644
--- a/tests/src/com/android/services/telephony/TelephonyConnectionServiceTest.java
+++ b/tests/src/com/android/services/telephony/TelephonyConnectionServiceTest.java
@@ -37,7 +37,7 @@
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
-import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -3483,13 +3483,10 @@
setupForCallTest();
// Call is not supported while using satellite
- NetworkRegistrationInfo nri = new NetworkRegistrationInfo.Builder()
- .setIsNonTerrestrialNetwork(true)
- .setAvailableServices(List.of(NetworkRegistrationInfo.SERVICE_TYPE_DATA))
- .build();
- ServiceState ss = new ServiceState();
- ss.addNetworkRegistrationInfo(nri);
- when(mPhone0.getServiceState()).thenReturn(ss);
+ when(mSatelliteController.isInSatelliteModeForCarrierRoaming(any())).thenReturn(true);
+ when(mSatelliteController.getCapabilitiesForCarrierRoamingSatelliteMode(any()))
+ .thenReturn(List.of(NetworkRegistrationInfo.SERVICE_TYPE_DATA));
+
mConnection = mTestConnectionService.onCreateOutgoingConnection(PHONE_ACCOUNT_HANDLE_1,
createConnectionRequest(PHONE_ACCOUNT_HANDLE_1, "1234", TELECOM_CALL_ID1));
DisconnectCause disconnectCause = mConnection.getDisconnectCause();
@@ -3497,16 +3494,40 @@
disconnectCause.getTelephonyDisconnectCause());
// Call is supported while using satellite
- nri = new NetworkRegistrationInfo.Builder()
- .setIsNonTerrestrialNetwork(true)
- .setAvailableServices(List.of(NetworkRegistrationInfo.SERVICE_TYPE_VOICE))
- .build();
- ss.addNetworkRegistrationInfo(nri);
+ when(mSatelliteController.getCapabilitiesForCarrierRoamingSatelliteMode(any()))
+ .thenReturn(List.of(NetworkRegistrationInfo.SERVICE_TYPE_VOICE));
+
+ // UnsupportedOperationException is thrown as we cannot perform actual call
+ assertThrows(UnsupportedOperationException.class, () -> mTestConnectionService
+ .onCreateOutgoingConnection(PHONE_ACCOUNT_HANDLE_1,
+ createConnectionRequest(PHONE_ACCOUNT_HANDLE_1, "1234", "TC@2")));
+ }
+
+ @Test
+ public void testNormalCallUsingSatelliteConnectedWithinHysteresisTime() throws Exception {
+ mSetFlagsRule.enableFlags(Flags.FLAG_CARRIER_ENABLED_SATELLITE_FLAG);
+
+ // Call is not supported when device is connected to satellite within hysteresis time
+ setupForCallTest();
+ when(mSatelliteController.isInSatelliteModeForCarrierRoaming(any())).thenReturn(true);
+ when(mSatelliteController.getCapabilitiesForCarrierRoamingSatelliteMode(any()))
+ .thenReturn(List.of(NetworkRegistrationInfo.SERVICE_TYPE_DATA));
+
mConnection = mTestConnectionService.onCreateOutgoingConnection(PHONE_ACCOUNT_HANDLE_1,
- createConnectionRequest(PHONE_ACCOUNT_HANDLE_1, "1234", "TC@2"));
- disconnectCause = mConnection.getDisconnectCause();
- assertNotEquals(android.telephony.DisconnectCause.SATELLITE_ENABLED,
+ createConnectionRequest(PHONE_ACCOUNT_HANDLE_1, "1234", TELECOM_CALL_ID1));
+ DisconnectCause disconnectCause = mConnection.getDisconnectCause();
+ assertEquals(android.telephony.DisconnectCause.SATELLITE_ENABLED,
disconnectCause.getTelephonyDisconnectCause());
+
+ // Call is supported when device is connected to satellite within hysteresis time
+ setupForCallTest();
+ when(mSatelliteController.getCapabilitiesForCarrierRoamingSatelliteMode(any())).thenReturn(
+ List.of(NetworkRegistrationInfo.SERVICE_TYPE_VOICE));
+
+ // UnsupportedOperationException is thrown as we cannot perform actual call
+ assertThrows(UnsupportedOperationException.class, () -> mTestConnectionService
+ .onCreateOutgoingConnection(PHONE_ACCOUNT_HANDLE_1,
+ createConnectionRequest(PHONE_ACCOUNT_HANDLE_1, "1234", "TC@2")));
}
@Test
@@ -3515,18 +3536,14 @@
setupForCallTest();
// Flag is disabled, so call is supported while using satellite
- NetworkRegistrationInfo nri = new NetworkRegistrationInfo.Builder()
- .setIsNonTerrestrialNetwork(true)
- .setAvailableServices(List.of(NetworkRegistrationInfo.SERVICE_TYPE_DATA))
- .build();
- ServiceState ss = new ServiceState();
- ss.addNetworkRegistrationInfo(nri);
- when(mPhone0.getServiceState()).thenReturn(ss);
- mConnection = mTestConnectionService.onCreateOutgoingConnection(PHONE_ACCOUNT_HANDLE_1,
- createConnectionRequest(PHONE_ACCOUNT_HANDLE_1, "1234", TELECOM_CALL_ID1));
- DisconnectCause disconnectCause = mConnection.getDisconnectCause();
- assertNotEquals(android.telephony.DisconnectCause.SATELLITE_ENABLED,
- disconnectCause.getTelephonyDisconnectCause());
+ when(mSatelliteController.isInSatelliteModeForCarrierRoaming(any())).thenReturn(true);
+ when(mSatelliteController.getCapabilitiesForCarrierRoamingSatelliteMode(any())).thenReturn(
+ List.of(NetworkRegistrationInfo.SERVICE_TYPE_VOICE));
+
+ // UnsupportedOperationException is thrown as we cannot perform actual call
+ assertThrows(UnsupportedOperationException.class, () -> mTestConnectionService
+ .onCreateOutgoingConnection(PHONE_ACCOUNT_HANDLE_1,
+ createConnectionRequest(PHONE_ACCOUNT_HANDLE_1, "1234", TELECOM_CALL_ID1)));
}
@Test
@@ -3535,22 +3552,17 @@
setupForCallTest();
// Call is not supported while using satellite
- NetworkRegistrationInfo nri = new NetworkRegistrationInfo.Builder()
- .setIsNonTerrestrialNetwork(true)
- .setAvailableServices(List.of(NetworkRegistrationInfo.SERVICE_TYPE_DATA))
- .build();
- ServiceState ss = new ServiceState();
- ss.addNetworkRegistrationInfo(nri);
- when(mPhone0.getServiceState()).thenReturn(ss);
+ when(mSatelliteController.isInSatelliteModeForCarrierRoaming(any())).thenReturn(true);
+ when(mSatelliteController.getCapabilitiesForCarrierRoamingSatelliteMode(any()))
+ .thenReturn(List.of(NetworkRegistrationInfo.SERVICE_TYPE_DATA));
// Wi-Fi call is possible
doReturn(true).when(mImsPhone).canMakeWifiCall();
when(mPhone0.getImsPhone()).thenReturn(mImsPhone);
- mConnection = mTestConnectionService.onCreateOutgoingConnection(PHONE_ACCOUNT_HANDLE_1,
- createConnectionRequest(PHONE_ACCOUNT_HANDLE_1, "1234", TELECOM_CALL_ID1));
- DisconnectCause disconnectCause = mConnection.getDisconnectCause();
- assertNotEquals(android.telephony.DisconnectCause.SATELLITE_ENABLED,
- disconnectCause.getTelephonyDisconnectCause());
+ // UnsupportedOperationException is thrown as we cannot perform actual call
+ assertThrows(UnsupportedOperationException.class, () -> mTestConnectionService
+ .onCreateOutgoingConnection(PHONE_ACCOUNT_HANDLE_1,
+ createConnectionRequest(PHONE_ACCOUNT_HANDLE_1, "1234", TELECOM_CALL_ID1)));
}
@Test
@@ -3570,13 +3582,12 @@
public void testIsAvailableForEmergencyCallsUsingNonTerrestrialNetwork_enableFlag() {
mSetFlagsRule.enableFlags(Flags.FLAG_CARRIER_ENABLED_SATELLITE_FLAG);
+ // Call is not supported while using satellite
+ when(mSatelliteController.isInSatelliteModeForCarrierRoaming(any())).thenReturn(true);
+ when(mSatelliteController.getCapabilitiesForCarrierRoamingSatelliteMode(any()))
+ .thenReturn(List.of(NetworkRegistrationInfo.SERVICE_TYPE_DATA));
Phone mockPhone = Mockito.mock(Phone.class);
- NetworkRegistrationInfo nri = new NetworkRegistrationInfo.Builder()
- .setIsNonTerrestrialNetwork(true)
- .setAvailableServices(List.of(NetworkRegistrationInfo.SERVICE_TYPE_DATA))
- .build();
ServiceState ss = new ServiceState();
- ss.addNetworkRegistrationInfo(nri);
ss.setEmergencyOnly(true);
ss.setState(ServiceState.STATE_EMERGENCY_ONLY);
when(mockPhone.getServiceState()).thenReturn(ss);
@@ -3593,13 +3604,12 @@
public void testIsAvailableForEmergencyCallsUsingNonTerrestrialNetwork_disableFlag() {
mSetFlagsRule.disableFlags(Flags.FLAG_CARRIER_ENABLED_SATELLITE_FLAG);
+ // Call is supported while using satellite
+ when(mSatelliteController.isInSatelliteModeForCarrierRoaming(any())).thenReturn(true);
+ when(mSatelliteController.getCapabilitiesForCarrierRoamingSatelliteMode(any()))
+ .thenReturn(List.of(NetworkRegistrationInfo.SERVICE_TYPE_VOICE));
Phone mockPhone = Mockito.mock(Phone.class);
- NetworkRegistrationInfo nri = new NetworkRegistrationInfo.Builder()
- .setIsNonTerrestrialNetwork(true)
- .setAvailableServices(List.of(NetworkRegistrationInfo.SERVICE_TYPE_VOICE))
- .build();
ServiceState ss = new ServiceState();
- ss.addNetworkRegistrationInfo(nri);
ss.setEmergencyOnly(true);
ss.setState(ServiceState.STATE_EMERGENCY_ONLY);
when(mockPhone.getServiceState()).thenReturn(ss);