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

Commit f0e75385 authored by yongnamcha's avatar yongnamcha Committed by Yongnam Cha
Browse files

Aligning the API call sequence for IMS call status

This commit fixes an issue with aligning the API call sequence for IMS call status.

Bug: 369458304
Test: Testing by equipment, atest ImsCallInfoTrackerTest
Flag: EXEMPT bugfix
Change-Id: I3ad8c247c656c8c18328d91fc3191184d1f7438e
parent 67a53cfa
Loading
Loading
Loading
Loading
+29 −2
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ public class ImsCallInfo {
    private @Nullable ImsPhoneConnection mConnection = null;
    private Call.State mState = Call.State.IDLE;
    private boolean mIsHeldByRemote = false;
    private boolean mShouldIgnoreUpdate = false;
    private @RadioAccessNetworkType int mCallRadioTech = AccessNetworkType.UNKNOWN;

    public ImsCallInfo(int index) {
@@ -44,18 +45,22 @@ public class ImsCallInfo {
        mConnection = null;
        mState = Call.State.IDLE;
        mIsHeldByRemote = false;
        mShouldIgnoreUpdate = false;
        mCallRadioTech = AccessNetworkType.UNKNOWN;
    }

    /**
     * Updates the state of the IMS call.
     * Initializes the state of the IMS call when this object is just created or re-used.
     *
     * @param c The instance of {@link ImsPhoneConnection}.
     */
    public void update(@NonNull ImsPhoneConnection c) {
    public void init(@NonNull ImsPhoneConnection c) {
        mConnection = c;
        mState = c.getState();
        mCallRadioTech = getCallRadioTech(c);
        // MO call: Need to wait for any state changes from ImsCall.
        // MT call: Ready to update the state.
        mShouldIgnoreUpdate = !isIncoming();
    }

    /**
@@ -70,6 +75,7 @@ public class ImsCallInfo {
        Call.State state = c.getState();
        int callRadioTech = getCallRadioTech(c);
        boolean changed = mState != state || mCallRadioTech != callRadioTech;

        mState = state;
        mCallRadioTech = callRadioTech;

@@ -81,6 +87,22 @@ public class ImsCallInfo {
            mIsHeldByRemote = false;
        }

        if (shouldIgnoreUpdate()) {
            if (!c.isAlive()) {
                // Even if the call state or attributes are updated,
                // there is no need to update the call state
                // because the call state has never been updated to the modem.
                //
                // For example, the call has created and cancelled by user immediately
                // before receiving any state changes from ImsCall.
                changed = false;
            } else {
                // Enforce IMS call state update even if the call state is the same.
                changed = true;
                mShouldIgnoreUpdate = false;
            }
        }

        return changed;
    }

@@ -114,6 +136,11 @@ public class ImsCallInfo {
        return mConnection.isEmergencyCall();
    }

    /** @return {@code true} if the update should be ignored. */
    public boolean shouldIgnoreUpdate() {
        return mShouldIgnoreUpdate;
    }

    /** @return the radio technology used for current connection. */
    public @RadioAccessNetworkType int getCallRadioTech() {
        return mCallRadioTech;
+6 −3
Original line number Diff line number Diff line
@@ -70,10 +70,12 @@ public class ImsCallInfoTracker {
            ImsCallInfo imsCallInfo = it.next();
            mQueue.remove(imsCallInfo);

            imsCallInfo.update(c);
            imsCallInfo.init(c);
            mImsCallInfo.put(c, imsCallInfo);

            if (!imsCallInfo.shouldIgnoreUpdate()) {
                notifyImsCallStatus();
            }

            if (DBG) dump();
        }
@@ -170,7 +172,8 @@ public class ImsCallInfoTracker {
    }

    private void notifyImsCallStatus() {
        Collection<ImsCallInfo> infos = mImsCallInfo.values();
        Collection<ImsCallInfo> infos = mImsCallInfo.values()
                .stream().filter(info -> !info.shouldIgnoreUpdate()).toList();
        ArrayList<ImsCallInfo> imsCallInfo = new ArrayList<ImsCallInfo>(infos);
        sort(imsCallInfo);
        mPhone.updateImsCallStatus(imsCallInfo, null);
+43 −5
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

@@ -67,9 +68,12 @@ public class ImsCallInfoTrackerTest extends TelephonyTest {
    public void testDialingNormalCall() throws Exception {
        ArgumentCaptor<List<ImsCallInfo>> captor = ArgumentCaptor.forClass(List.class);

        ImsPhoneConnection c = getConnection(Call.State.DIALING, false);
        ImsPhoneConnection c = getConnection(Call.State.IDLE, false);
        mImsCallInfoTracker.addImsCallStatus(c);

        doReturn(Call.State.DIALING).when(c).getState();
        mImsCallInfoTracker.updateImsCallStatus(c);

        verify(mImsPhone, times(1)).updateImsCallStatus(captor.capture(), any());

        List<ImsCallInfo> imsCallInfos = captor.getValue();
@@ -92,9 +96,12 @@ public class ImsCallInfoTrackerTest extends TelephonyTest {
    public void testDialingEmergencyCall() throws Exception {
        ArgumentCaptor<List<ImsCallInfo>> captor = ArgumentCaptor.forClass(List.class);

        ImsPhoneConnection c = getConnection(Call.State.DIALING, true);
        ImsPhoneConnection c = getConnection(Call.State.IDLE, true);
        mImsCallInfoTracker.addImsCallStatus(c);

        doReturn(Call.State.DIALING).when(c).getState();
        mImsCallInfoTracker.updateImsCallStatus(c);

        verify(mImsPhone, times(1)).updateImsCallStatus(captor.capture(), any());

        List<ImsCallInfo> imsCallInfos = captor.getValue();
@@ -368,9 +375,12 @@ public class ImsCallInfoTrackerTest extends TelephonyTest {
    public void testSrvccCompleted() throws Exception {
        ArgumentCaptor<List<ImsCallInfo>> captor = ArgumentCaptor.forClass(List.class);

        ImsPhoneConnection c = getConnection(Call.State.DIALING, false);
        ImsPhoneConnection c = getConnection(Call.State.IDLE, false);
        mImsCallInfoTracker.addImsCallStatus(c);

        doReturn(Call.State.DIALING).when(c).getState();
        mImsCallInfoTracker.updateImsCallStatus(c);

        verify(mImsPhone, times(1)).updateImsCallStatus(captor.capture(), any());

        List<ImsCallInfo> imsCallInfos = captor.getValue();
@@ -391,9 +401,12 @@ public class ImsCallInfoTrackerTest extends TelephonyTest {
    @Test
    public void testNetworkChanged() throws Exception {
        ArgumentCaptor<List<ImsCallInfo>> captor = ArgumentCaptor.forClass(List.class);
        ImsPhoneConnection c = getConnection(Call.State.ACTIVE, false);
        ImsPhoneConnection c = getConnection(Call.State.IDLE, false);
        mImsCallInfoTracker.addImsCallStatus(c);

        doReturn(Call.State.DIALING).when(c).getState();
        mImsCallInfoTracker.updateImsCallStatus(c);

        verify(mImsPhone, times(1)).updateImsCallStatus(captor.capture(), any());

        List<ImsCallInfo> imsCallInfos = captor.getValue();
@@ -417,9 +430,12 @@ public class ImsCallInfoTrackerTest extends TelephonyTest {
    public void testClearAllOrphanedConnections() throws Exception {
        ArgumentCaptor<List<ImsCallInfo>> captor = ArgumentCaptor.forClass(List.class);

        ImsPhoneConnection c = getConnection(Call.State.DIALING, false);
        ImsPhoneConnection c = getConnection(Call.State.IDLE, false);
        mImsCallInfoTracker.addImsCallStatus(c);

        doReturn(Call.State.DIALING).when(c).getState();
        mImsCallInfoTracker.updateImsCallStatus(c);

        verify(mImsPhone, times(1)).updateImsCallStatus(captor.capture(), any());

        List<ImsCallInfo> imsCallInfos = captor.getValue();
@@ -443,10 +459,32 @@ public class ImsCallInfoTrackerTest extends TelephonyTest {
        assertEquals(Call.State.IDLE, info.getCallState());
    }

    @Test
    public void testAddImsCallStatus() throws Exception {
        ArgumentCaptor<List<ImsCallInfo>> captor = ArgumentCaptor.forClass(List.class);

        ImsPhoneConnection c = getConnection(Call.State.DIALING, false);
        mImsCallInfoTracker.addImsCallStatus(c);
        verify(mImsPhone, never()).updateImsCallStatus(any(), any());

        c = getConnection(Call.State.INCOMING, false);
        mImsCallInfoTracker.addImsCallStatus(c);
        verify(mImsPhone, times(1)).updateImsCallStatus(captor.capture(), any());

        List<ImsCallInfo> imsCallInfos = captor.getValue();
        assertNotNull(imsCallInfos);
        assertEquals(1, imsCallInfos.size());

        ImsCallInfo info = imsCallInfos.get(0);
        assertNotNull(info);
        assertEquals(Call.State.INCOMING, info.getCallState());
    }

    private ImsPhoneConnection getConnection(Call.State state, boolean isEmergency) {
        ImsPhoneConnection c = mock(ImsPhoneConnection.class);
        doReturn(isEmergency).when(c).isEmergencyCall();
        doReturn(state).when(c).getState();
        doReturn(true).when(c).isAlive();
        doReturn(ServiceState.RIL_RADIO_TECHNOLOGY_LTE).when(c).getCallRadioTech();
        switch (state) {
            case INCOMING:
+5 −1
Original line number Diff line number Diff line
@@ -2554,10 +2554,14 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest {
        // Dialing
        ImsPhoneConnection connection = placeCall();

        ImsCall imsCall = connection.getImsCall();
        imsCall.getImsCallSessionListenerProxy().callSessionInitiating(imsCall.getSession(),
                new ImsCallProfile());

        verify(mImsPhone, times(1)).updateImsCallStatus(any(), any());

        // Alerting
        ImsCall imsCall = connection.getImsCall();
        imsCall = connection.getImsCall();
        imsCall.getImsCallSessionListenerProxy().callSessionProgressing(imsCall.getSession(),
                new ImsStreamMediaProfile());