Add UT cases to test CAPABILITY_EMERGENCY_CALLS_ONLY on PSTN account
Bug: 319648880
Test: atest TelecomAccountRegistryTest
Flag: EXEMPT test only
Change-Id: I8c167479b13a25f235666a29b45395e9fa0f39a0
diff --git a/tests/src/com/android/services/telephony/TelecomAccountRegistryTest.java b/tests/src/com/android/services/telephony/TelecomAccountRegistryTest.java
index 13166a6..fc544b0 100644
--- a/tests/src/com/android/services/telephony/TelecomAccountRegistryTest.java
+++ b/tests/src/com/android/services/telephony/TelecomAccountRegistryTest.java
@@ -217,6 +217,30 @@
PhoneAccount.CAPABILITY_EMERGENCY_CALLS_ONLY)).isTrue();
}
+ @Test
+ public void onLocaleChanged_withSubVoiceCapable_shouldNotRegisterEmergencyOnlyAccount() {
+ overrideSubscriptionServiceCapabilities(
+ new int[]{SubscriptionManager.SERVICE_CAPABILITY_VOICE});
+ onLocaleChanged();
+
+ PhoneAccount phoneAccount = verifyAndCaptureRegisteredPhoneAccount();
+
+ assertThat(phoneAccount.hasCapabilities(
+ PhoneAccount.CAPABILITY_EMERGENCY_CALLS_ONLY)).isFalse();
+ }
+
+ @Test
+ public void onLocaleChanged_withSubNotVoiceCapable_shouldRegisterEmergencyOnlyAccount() {
+ overrideSubscriptionServiceCapabilities(
+ new int[]{SubscriptionManager.SERVICE_CAPABILITY_DATA});
+ onLocaleChanged();
+
+ PhoneAccount phoneAccount = verifyAndCaptureRegisteredPhoneAccount();
+
+ assertThat(phoneAccount.hasCapabilities(
+ PhoneAccount.CAPABILITY_EMERGENCY_CALLS_ONLY)).isTrue();
+ }
+
private PhoneAccount verifyAndCaptureRegisteredPhoneAccount() {
ArgumentCaptor<PhoneAccount> phoneAccountArgumentCaptor =
ArgumentCaptor.forClass(PhoneAccount.class);
@@ -278,4 +302,13 @@
Intent intent = new Intent(TelephonyManager.ACTION_NETWORK_COUNTRY_CHANGED);
mLocaleChangedBroadcastReceiver.onReceive(mMockedContext, intent);
}
+
+ private void overrideSubscriptionServiceCapabilities(int[] capabilities) {
+ PersistableBundle bundle = new PersistableBundle();
+ bundle.putIntArray(CarrierConfigManager.KEY_CELLULAR_SERVICE_CAPABILITIES_INT_ARRAY,
+ capabilities);
+
+ when(mPhoneGlobals.getCarrierConfigForSubId(anyInt())).thenReturn(bundle);
+ mTestableLooper.processAllMessages();
+ }
}