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

Commit 62eb209e authored by Pranav Madapurmath's avatar Pranav Madapurmath Committed by Automerger Merge Worker
Browse files
parents 6cb4d610 537c3ddd
Loading
Loading
Loading
Loading
+22 −13
Original line number Diff line number Diff line
@@ -429,21 +429,30 @@ public class CreateConnectionProcessor implements CreateConnectionResponse {
            // Get user preferred PA if it exists.
            PhoneAccount preferredPA = mPhoneAccountRegistrar.getPhoneAccountUnchecked(
                    preferredPAH);
            if (mCall.isIncoming() && preferredPA != null) {
                // The phone account for the incoming call should be used.
                mAttemptRecords.add(new CallAttemptRecord(preferredPA.getAccountHandle(),
                        preferredPA.getAccountHandle()));
            } else {
                // Next, add all SIM phone accounts which can place emergency calls.
                sortSimPhoneAccountsForEmergency(allAccounts, preferredPA);
                Log.i(this, "The preferred PA is: %s", preferredPA);
                // and pick the first one that can place emergency calls.
                for (PhoneAccount phoneAccount : allAccounts) {
                    if (phoneAccount.hasCapabilities(PhoneAccount.CAPABILITY_PLACE_EMERGENCY_CALLS)
                        && phoneAccount.hasCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION)) {
                            && phoneAccount.hasCapabilities(
                            PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION)) {
                        PhoneAccountHandle phoneAccountHandle = phoneAccount.getAccountHandle();
                    Log.i(this, "Will try PSTN account %s for emergency", phoneAccountHandle);
                        Log.i(this, "Will try PSTN account %s for emergency",
                                phoneAccountHandle);
                        mAttemptRecords.add(new CallAttemptRecord(phoneAccountHandle,
                                phoneAccountHandle));
                    // Add only one emergency SIM PhoneAccount to the attempt list, telephony will
                    // perform retries if the call fails.
                        // Add only one emergency SIM PhoneAccount to the attempt list, telephony
                        // will perform retries if the call fails.
                        break;
                    }
                }
            }

            // Next, add the connection manager account as a backup if it can place emergency calls.
            PhoneAccountHandle callManagerHandle =
+37 −0
Original line number Diff line number Diff line
@@ -516,6 +516,43 @@ public class CreateConnectionProcessorTest extends TelecomTestCase {
        verify(mMockCreateConnectionResponse).handleCreateConnectionSuccess(mockCallIdMapper, null);
    }

    /**
     * Ensure that the call goes out on the PhoneAccount for the incoming call and not the
     * Telephony preferred emergency account.
     */
    @SmallTest
    @Test
    public void testMTEmergencyCallMultiSimUserPreferred() throws Exception {
        when(mMockCall.isEmergencyCall()).thenReturn(true);
        when(mMockCall.isTestEmergencyCall()).thenReturn(false);
        when(mMockCall.isIncoming()).thenReturn(true);
        ConnectionServiceWrapper service = makeConnectionServiceWrapper();
        PhoneAccount emergencyPhoneAccount1 = makeEmergencyPhoneAccount("tel_emer1", 0, null);
        mapToSubSlot(emergencyPhoneAccount1, 1 /*subId*/, 0 /*slotId*/);
        setTargetPhoneAccount(mMockCall, emergencyPhoneAccount1.getAccountHandle());
        phoneAccounts.add(emergencyPhoneAccount1);
        // Make this the user preferred phone account
        setTargetPhoneAccount(mMockCall, emergencyPhoneAccount1.getAccountHandle());
        PhoneAccount emergencyPhoneAccount2 = makeEmergencyPhoneAccount("tel_emer2",
                PhoneAccount.CAPABILITY_EMERGENCY_PREFERRED, null);
        mapToSubSlot(emergencyPhoneAccount2, 2 /*subId*/, 1 /*slotId*/);
        phoneAccounts.add(emergencyPhoneAccount2);
        PhoneAccountHandle emergencyPhoneAccountHandle2 = emergencyPhoneAccount2.getAccountHandle();

        mTestCreateConnectionProcessor.process();

        verify(mMockCall).setConnectionManagerPhoneAccount(
                eq(emergencyPhoneAccount1.getAccountHandle()));
        // The account we're using to place the call should be the user preferred account
        verify(mMockCall).setTargetPhoneAccount(eq(emergencyPhoneAccount1.getAccountHandle()));
        verify(mMockCall).setConnectionService(eq(service));
        verify(service).createConnection(eq(mMockCall), any(CreateConnectionResponse.class));
        // Notify successful connection to call
        CallIdMapper mockCallIdMapper = mock(CallIdMapper.class);
        mTestCreateConnectionProcessor.handleCreateConnectionSuccess(mockCallIdMapper, null);
        verify(mMockCreateConnectionResponse).handleCreateConnectionSuccess(mockCallIdMapper, null);
    }

    /**
     * If the user preferred PhoneAccount is associated with an invalid slot, place on the other,
     * valid slot.