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

Commit c68af5f2 authored by Sooraj Sasindran's avatar Sooraj Sasindran Committed by donaldahn
Browse files

Switch data in ringing phase

Bug: 227396837
Test: unit test

Merged-In: I92039a196502561c1fe4955a5ae1b5695697402d
Change-Id: I92039a196502561c1fe4955a5ae1b5695697402d
parent c9092789
Loading
Loading
Loading
Loading
+2 −9
Original line number Diff line number Diff line
@@ -71,7 +71,6 @@ import android.util.LocalLog;
import com.android.ims.ImsException;
import com.android.ims.ImsManager;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.Call;
import com.android.internal.telephony.CommandException;
import com.android.internal.telephony.ISetOpportunisticDataCallback;
import com.android.internal.telephony.IccCard;
@@ -1636,14 +1635,8 @@ public class PhoneSwitcher extends Handler {
        }

        // 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.getBackgroundCall().isIdle());
        return (!phone.getBackgroundCall().isIdle()
                || !phone.getForegroundCall().isIdle());
    }

    private void updateHalCommandToUse() {
+75 −0
Original line number Diff line number Diff line
@@ -109,6 +109,8 @@ public class PhoneSwitcherTest extends TelephonyTest {
    private GsmCdmaCall mActiveCall;
    private GsmCdmaCall mHoldingCall;
    private GsmCdmaCall mInactiveCall;
    private GsmCdmaCall mDialCall;
    private GsmCdmaCall mIncomingCall;
    private ISetOpportunisticDataCallback mSetOpptDataCallback1;
    private ISetOpportunisticDataCallback mSetOpptDataCallback2;
    PhoneSwitcher.ImsRegTechProvider mMockImsRegTechProvider;
@@ -139,6 +141,8 @@ public class PhoneSwitcherTest extends TelephonyTest {
        mActiveCall = mock(GsmCdmaCall.class);
        mHoldingCall = mock(GsmCdmaCall.class);
        mInactiveCall = mock(GsmCdmaCall.class);
        mDialCall = mock(GsmCdmaCall.class);
        mIncomingCall = mock(GsmCdmaCall.class);
        mSetOpptDataCallback1 = mock(ISetOpportunisticDataCallback.class);
        mSetOpptDataCallback2 = mock(ISetOpportunisticDataCallback.class);
        mMockImsRegTechProvider = mock(PhoneSwitcher.ImsRegTechProvider.class);
@@ -150,6 +154,8 @@ 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();
        doReturn(Call.State.DIALING).when(mDialCall).getState();
        doReturn(Call.State.INCOMING).when(mIncomingCall).getState();

        doReturn(true).when(mInactiveCall).isIdle();
        doReturn(false).when(mActiveCall).isIdle();
@@ -650,6 +656,63 @@ public class PhoneSwitcherTest extends TelephonyTest {
        assertEquals(1, mPhoneSwitcher.getPreferredDataPhoneId());
    }

    @Test
    @SmallTest
    public void testNonDefaultDataPhoneInCall_ImsCallDialingOnLte_shouldSwitchDds()
            throws Exception {
        initialize();
        setAllPhonesInactive();

        // Phone 0 has sub 1, phone 1 has sub 2.
        // Sub 1 is default data sub.
        // Both are active subscriptions are active sub, as they are in both active slots.
        setSlotIndexToSubId(0, 1);
        setSlotIndexToSubId(1, 2);
        setDefaultDataSubId(1);
        processAllMessages();

        // Phone 0 should be the default data phoneId.
        assertEquals(0, mPhoneSwitcher.getPreferredDataPhoneId());

        // Phone2 has active IMS call on LTE. And data of DEFAULT apn is enabled. This should
        // trigger data switch.
        doReturn(mImsPhone).when(mPhone2).getImsPhone();
        doReturn(true).when(mDataEnabledSettings2).isDataEnabled(ApnSetting.TYPE_DEFAULT);
        mockImsRegTech(1, REGISTRATION_TECH_LTE);
        notifyPhoneAsInDial(mImsPhone);

        // Phone 1 should become the default data phone.
        assertEquals(1, mPhoneSwitcher.getPreferredDataPhoneId());
    }
    @Test
    @SmallTest
    public void testNonDefaultDataPhoneInCall_ImsCallIncomingOnLte_shouldSwitchDds()
            throws Exception {
        initialize();
        setAllPhonesInactive();

        // Phone 0 has sub 1, phone 1 has sub 2.
        // Sub 1 is default data sub.
        // Both are active subscriptions are active sub, as they are in both active slots.
        setSlotIndexToSubId(0, 1);
        setSlotIndexToSubId(1, 2);
        setDefaultDataSubId(1);
        processAllMessages();

        // Phone 0 should be the default data phoneId.
        assertEquals(0, mPhoneSwitcher.getPreferredDataPhoneId());

        // Phone2 has active IMS call on LTE. And data of DEFAULT apn is enabled. This should
        // trigger data switch.
        doReturn(mImsPhone).when(mPhone2).getImsPhone();
        doReturn(true).when(mDataEnabledSettings2).isDataEnabled(ApnSetting.TYPE_DEFAULT);
        mockImsRegTech(1, REGISTRATION_TECH_LTE);
        notifyPhoneAsInIncomingCall(mImsPhone);

        // Phone 1 should become the default data phone.
        assertEquals(1, mPhoneSwitcher.getPreferredDataPhoneId());
    }

    @Test
    @SmallTest
    public void testNonDefaultDataPhoneInCall_ImsCallOnWlan_shouldNotSwitchDds() throws Exception {
@@ -1287,6 +1350,18 @@ public class PhoneSwitcherTest extends TelephonyTest {
        processAllMessages();
    }

    private void notifyPhoneAsInDial(Phone phone) {
        doReturn(mDialCall).when(phone).getForegroundCall();
        mPhoneSwitcher.sendEmptyMessage(EVENT_PRECISE_CALL_STATE_CHANGED);
        processAllMessages();
    }

    private void notifyPhoneAsInIncomingCall(Phone phone) {
        doReturn(mIncomingCall).when(phone).getForegroundCall();
        mPhoneSwitcher.sendEmptyMessage(EVENT_PRECISE_CALL_STATE_CHANGED);
        processAllMessages();
    }

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