Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ac24f293 authored by Tyler Gunn's avatar Tyler Gunn
Browse files

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
parent 4dffc62f
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import java.util.HashSet;
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 @@ public class CreateConnectionProcessor implements CreateConnectionResponse {
            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)) {
+21 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import org.junit.Before;
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 @@ public class CreateConnectionProcessorTest extends TelecomTestCase {
        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 {