Filter self managed phone accounts out when finding emergency accts.
Filter out self managed phone accounts from the list of potential accts
when placing an emergency call. We will NEVER place a call over a self
managed phone account in an emergency situation.
Test: Added new test to verify that we don't try to place call over
the self-managed acct.
Bug: 208680522
Merged-In: I4be2bff670ce047916c48be541abe59c7d51331c
Change-Id: I66d2bd438742507b80990a49d68a0818bd270b8e
diff --git a/src/com/android/server/telecom/CreateConnectionProcessor.java b/src/com/android/server/telecom/CreateConnectionProcessor.java
index 2e67b08..e5b4197 100644
--- a/src/com/android/server/telecom/CreateConnectionProcessor.java
+++ b/src/com/android/server/telecom/CreateConnectionProcessor.java
@@ -39,6 +39,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
+import java.util.stream.Collectors;
/**
* This class creates connections to place new outgoing calls or to attach to an existing incoming
@@ -386,8 +387,13 @@
mAttemptRecords.clear();
// Phone accounts in profile do not handle emergency call, use phone accounts in
// current user.
+ // ONLY include phone accounts which are NOT self-managed; we will never consider a self
+ // managed phone account for placing an emergency call.
List<PhoneAccount> allAccounts = mPhoneAccountRegistrar
- .getAllPhoneAccountsOfCurrentUser();
+ .getAllPhoneAccountsOfCurrentUser()
+ .stream()
+ .filter(act -> !act.hasCapabilities(PhoneAccount.CAPABILITY_SELF_MANAGED))
+ .collect(Collectors.toList());
if (allAccounts.isEmpty() && mContext.getPackageManager().hasSystemFeature(
PackageManager.FEATURE_TELEPHONY)) {
diff --git a/tests/src/com/android/server/telecom/tests/CreateConnectionProcessorTest.java b/tests/src/com/android/server/telecom/tests/CreateConnectionProcessorTest.java
index 845a838..1a649dc 100644
--- a/tests/src/com/android/server/telecom/tests/CreateConnectionProcessorTest.java
+++ b/tests/src/com/android/server/telecom/tests/CreateConnectionProcessorTest.java
@@ -41,6 +41,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
+import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
@@ -546,6 +547,26 @@
verify(mMockCreateConnectionResponse).handleCreateConnectionSuccess(mockCallIdMapper, null);
}
+ /**
+ * Ensures that a self-managed phone account won't be considered when attempting to place an
+ * emergency call.
+ */
+ @SmallTest
+ @Test
+ public void testDontAttemptSelfManaged() {
+ when(mMockCall.isEmergencyCall()).thenReturn(true);
+ when(mMockCall.isTestEmergencyCall()).thenReturn(false);
+ when(mMockCall.getHandle()).thenReturn(Uri.parse(""));
+
+ PhoneAccount selfManagedAcct = makePhoneAccount("sm-acct",
+ PhoneAccount.CAPABILITY_SELF_MANAGED
+ | PhoneAccount.CAPABILITY_PLACE_EMERGENCY_CALLS);
+ phoneAccounts.add(selfManagedAcct);
+
+ mTestCreateConnectionProcessor.process();
+ verify(mMockCall, never()).setTargetPhoneAccount(any(PhoneAccountHandle.class));
+ }
+
@SmallTest
@Test
public void testEmergencyCallSimFailToConnectionManager() throws Exception {