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

Commit c68ef683 authored by Xiangyu/Malcolm Chen's avatar Xiangyu/Malcolm Chen Committed by Android (Google) Code Review
Browse files

Merge "Switch to SIM with voice call on hold." into qt-r1-dev

parents 4991bce9 cbdf4b37
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -321,7 +321,7 @@ public class PhoneSwitcher extends Handler {
        // subscription.
        mPhoneIdInVoiceCall = SubscriptionManager.INVALID_PHONE_INDEX;
        for (Phone phone : mPhones) {
            if (isCallActive(phone) || isCallActive(phone.getImsPhone())) {
            if (isPhoneInVoiceCall(phone) || isPhoneInVoiceCall(phone.getImsPhone())) {
                mPhoneIdInVoiceCall = phone.getPhoneId();
                break;
            }
@@ -1232,13 +1232,20 @@ public class PhoneSwitcher extends Handler {
                subId, needValidation ? 1 : 0, callback).sendToTarget();
    }

    private boolean isCallActive(Phone phone) {
    private boolean isPhoneInVoiceCall(Phone phone) {
        if (phone == null) {
            return false;
        }

        // A phone in voice call might trigger data being switched to it.
        // We only report true if its precise call state is ACTIVE, ALERTING or HOLDING.
        // The reason is data switching is interrupting, so we only switch when necessary and
        // acknowledged by the users. For incoming call, we don't switch until answered
        // (RINGING -> ACTIVE), for outgoing call we don't switch until call is connected
        // in network (DIALING -> ALERTING).
        return (phone.getForegroundCall().getState() == Call.State.ACTIVE
                || phone.getForegroundCall().getState() == Call.State.ALERTING);
                || phone.getForegroundCall().getState() == Call.State.ALERTING
                || phone.getBackgroundCall().getState() == Call.State.HOLDING);
    }

    private void updateHalCommandToUse() {
+16 −1
Original line number Diff line number Diff line
@@ -91,6 +91,8 @@ public class PhoneSwitcherTest extends TelephonyTest {
    @Mock
    private GsmCdmaCall mActiveCall;
    @Mock
    private GsmCdmaCall mHoldingCall;
    @Mock
    private GsmCdmaCall mInactiveCall;

    // The thread that mPhoneSwitcher will handle events in.
@@ -116,6 +118,7 @@ public class PhoneSwitcherTest extends TelephonyTest {

        doReturn(Call.State.ACTIVE).when(mActiveCall).getState();
        doReturn(Call.State.IDLE).when(mInactiveCall).getState();
        doReturn(Call.State.HOLDING).when(mHoldingCall).getState();
    }

    @After
@@ -572,7 +575,6 @@ public class PhoneSwitcherTest extends TelephonyTest {
        notifyDataEnabled(false);
        notifyPhoneAsInCall(mPhone2);
        verify(mMockRadioConfig, never()).setPreferredDataModem(anyInt(), any());
        waitABit();
        assertTrue(mPhoneSwitcher.shouldApplyNetworkRequest(internetRequest, 0));
        assertFalse(mPhoneSwitcher.shouldApplyNetworkRequest(internetRequest, 1));

@@ -588,6 +590,13 @@ public class PhoneSwitcherTest extends TelephonyTest {
        verify(mMockRadioConfig).setPreferredDataModem(eq(0), any());
        assertTrue(mPhoneSwitcher.shouldApplyNetworkRequest(internetRequest, 0));
        assertFalse(mPhoneSwitcher.shouldApplyNetworkRequest(internetRequest, 1));
        clearInvocations(mMockRadioConfig);

        // Phone2 has holding call, but data is turned off. So no data switching should happen.
        notifyPhoneAsInHoldingCall(mPhone2);
        verify(mMockRadioConfig).setPreferredDataModem(eq(1), any());
        assertTrue(mPhoneSwitcher.shouldApplyNetworkRequest(internetRequest, 1));
        assertFalse(mPhoneSwitcher.shouldApplyNetworkRequest(internetRequest, 0));

        mHandlerThread.quit();
    }
@@ -878,6 +887,12 @@ public class PhoneSwitcherTest extends TelephonyTest {
        waitABit();
    }

    private void notifyPhoneAsInHoldingCall(Phone phone) {
        doReturn(mHoldingCall).when(phone).getBackgroundCall();
        mPhoneSwitcher.sendEmptyMessage(EVENT_PRECISE_CALL_STATE_CHANGED);
        waitABit();
    }

    private void notifyPhoneAsInactive(Phone phone) {
        doReturn(mInactiveCall).when(phone).getForegroundCall();
        mPhoneSwitcher.sendEmptyMessage(EVENT_PRECISE_CALL_STATE_CHANGED);