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

Commit 12b416f0 authored by Hall Liu's avatar Hall Liu Committed by android-build-merger
Browse files

Merge "Reset the hold/swap state when catching exception" am: 90925537 am:...

Merge "Reset the hold/swap state when catching exception" am: 90925537 am: 7459e3c0 am: cd0786c0 am: 749afd4a
am: 2a83f44f

Change-Id: Id5ea9257940f55f965efa0174292fc0f188e30cb
parents 88973071 2a83f44f
Loading
Loading
Loading
Loading
+27 −14
Original line number Diff line number Diff line
@@ -1216,6 +1216,7 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
            logi("Ignoring hold request while already holding or swapping");
            return;
        }
        HoldSwapState oldHoldState = mHoldSwitchingState;
        ImsCall callToHold = mForegroundCall.getImsCall();

        mHoldSwitchingState = HoldSwapState.HOLDING_TO_DIAL_OUTGOING;
@@ -1228,6 +1229,8 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
                    ImsCommand.IMS_CMD_HOLD);
        } catch (ImsException e) {
            mForegroundCall.switchWith(mBackgroundCall);
            mHoldSwitchingState = oldHoldState;
            logHoldSwapState("holdActiveCallForPendingMo - fail");
            throw new CallStateException(e.getMessage());
        }
    }
@@ -1242,6 +1245,7 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
                logi("Ignoring hold request while already holding or swapping");
                return;
            }
            HoldSwapState oldHoldState = mHoldSwitchingState;
            ImsCall callToHold = mForegroundCall.getImsCall();
            if (mBackgroundCall.getState().isAlive()) {
                mCallExpectedToResume = mBackgroundCall.getImsCall();
@@ -1257,6 +1261,8 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
                        ImsCommand.IMS_CMD_HOLD);
            } catch (ImsException e) {
                mForegroundCall.switchWith(mBackgroundCall);
                mHoldSwitchingState = oldHoldState;
                logHoldSwapState("holdActiveCall - fail");
                throw new CallStateException(e.getMessage());
            }
        }
@@ -1270,6 +1276,7 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
                && mRingingCall.getState() == ImsPhoneCall.State.WAITING;
        if (switchingWithWaitingCall) {
            ImsCall callToHold = mForegroundCall.getImsCall();
            HoldSwapState oldHoldState = mHoldSwitchingState;
            mHoldSwitchingState = HoldSwapState.HOLDING_TO_ANSWER_INCOMING;
            mForegroundCall.switchWith(mBackgroundCall);
            logHoldSwapState("holdActiveCallForWaitingCall");
@@ -1279,6 +1286,8 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
                        ImsCommand.IMS_CMD_HOLD);
            } catch (ImsException e) {
                mForegroundCall.switchWith(mBackgroundCall);
                mHoldSwitchingState = oldHoldState;
                logHoldSwapState("holdActiveCallForWaitingCall - fail");
                throw new CallStateException(e.getMessage());
            }
        }
@@ -1288,7 +1297,6 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
     * Unhold the currently held call.
     */
    void unholdHeldCall() throws CallStateException {
        try {
        ImsCall imsCall = mBackgroundCall.getImsCall();
        if (mHoldSwitchingState == HoldSwapState.PENDING_SINGLE_CALL_UNHOLD
                || mHoldSwitchingState == HoldSwapState.SWAPPING_ACTIVE_AND_HELD) {
@@ -1297,17 +1305,22 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
        }
        if (imsCall != null) {
            mCallExpectedToResume = imsCall;
            HoldSwapState oldHoldState = mHoldSwitchingState;
            mHoldSwitchingState = HoldSwapState.PENDING_SINGLE_CALL_UNHOLD;
            mForegroundCall.switchWith(mBackgroundCall);
            logHoldSwapState("unholdCurrentCall");
            try {
                imsCall.resume();
                mMetrics.writeOnImsCommand(mPhone.getPhoneId(), imsCall.getSession(),
                        ImsCommand.IMS_CMD_RESUME);
            }
            } catch (ImsException e) {
                mForegroundCall.switchWith(mBackgroundCall);
                mHoldSwitchingState = oldHoldState;
                logHoldSwapState("unholdCurrentCall - fail");
                throw new CallStateException(e.getMessage());
            }
        }
    }

    private void resumeForegroundCall() throws ImsException {
        //resume foreground call after holding background call
+25 −0
Original line number Diff line number Diff line
@@ -389,6 +389,31 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest {
        assertEquals(1, mCTUT.mForegroundCall.getConnections().size());
    }

    @Test
    @SmallTest
    public void testImsHoldException() throws Exception {
        testImsMTCallAccept();
        doThrow(new ImsException()).when(mImsCall).hold();
        try {
            mCTUT.holdActiveCall();
            Assert.fail("No exception thrown");
        } catch (Exception e) {
            // expected
            verify(mImsCall).hold();
        }

        // After the first hold exception, try holding (successfully) again to make sure that it
        // goes through
        doNothing().when(mImsCall).hold();
        try {
            mCTUT.holdActiveCall();
            verify(mImsCall, times(2)).hold();
        } catch (Exception ex) {
            ex.printStackTrace();
            Assert.fail("unexpected exception thrown" + ex.getMessage());
        }
    }

    @Test
    @SmallTest
    public void testImsMTCallReject() {