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

Commit ce89c854 authored by Pranav Madapurmath's avatar Pranav Madapurmath
Browse files

Dual sim MT emergency call issue

When dual sim is enabled and we have a sim assigned to a work profile as
well as the personal, MT emergency calls do not succeed. When the
Telephony preferred emergency account is different from the sim that is
receiving the call, there would not be any actively ringing call for
that sim. We should instead receive the call over the phone account of
the MT call.

Fixes: 279070364
Test: Unit
Test: Manual (tested dual sim scenario on work/profile)
Test: Manual (tested single sim cases - no regression observed)
Change-Id: I46993ebe9d0b2e989703a148fddbd98c1c23a694
parent 8947db1b
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.