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

Commit 21b57933 authored by Hall Liu's avatar Hall Liu Committed by android-build-merger
Browse files

Merge "Extend HoldSwapState for outgoing calls"

am: 2e106bf4

Change-Id: I57a0432a4eafdf918f7cdd8b9499e08012216522
parents 6470dd60 2e106bf4
Loading
Loading
Loading
Loading
+47 −11
Original line number Diff line number Diff line
@@ -302,6 +302,8 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
        HOLDING_TO_ANSWER_INCOMING,
        // Pending resuming the foreground call after some kind of failure
        PENDING_RESUME_FOREGROUND_AFTER_FAILURE,
        // Pending holding a call to dial another outgoing call
        HOLDING_TO_DIAL_OUTGOING,
    }

    //***** Instance Variables
@@ -966,7 +968,7 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
            // Cache the video state for pending MO call.
            mPendingCallVideoState = videoState;
            mPendingIntentExtras = dialArgs.intentExtras;
            holdActiveCall();
            holdActiveCallForPendingMo();
        }

        ImsPhoneCall.State fgState = ImsPhoneCall.State.IDLE;
@@ -1334,6 +1336,28 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
        }
    }

    private void holdActiveCallForPendingMo() throws CallStateException {
        if (mHoldSwitchingState == HoldSwapState.PENDING_SINGLE_CALL_HOLD
                || mHoldSwitchingState == HoldSwapState.SWAPPING_ACTIVE_AND_HELD) {
            logi("Ignoring hold request while already holding or swapping");
            return;
        }
        ImsCall callToHold = mForegroundCall.getImsCall();

        mHoldSwitchingState = HoldSwapState.HOLDING_TO_DIAL_OUTGOING;
        logHoldSwapState("holdActiveCallForPendingMo");

        mForegroundCall.switchWith(mBackgroundCall);
        try {
            callToHold.hold();
            mMetrics.writeOnImsCommand(mPhone.getPhoneId(), callToHold.getSession(),
                    ImsCommand.IMS_CMD_HOLD);
        } catch (ImsException e) {
            mForegroundCall.switchWith(mBackgroundCall);
            throw new CallStateException(e.getMessage());
        }
    }

    /**
     * Holds the active call, possibly resuming the already-held background call if it exists.
     */
@@ -2390,9 +2414,6 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
                if (mRingingCall.getState().isRinging()) {
                    // Drop pending MO. We should address incoming call first
                    mPendingMO = null;
                } else if (mPendingMO != null
                        && mPendingMO.getDisconnectCause() == DisconnectCause.NOT_DISCONNECTED) {
                    sendEmptyMessage(EVENT_DIAL_PENDINGMO);
                }
            }

@@ -2437,6 +2458,19 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
                    logHoldSwapState("onCallTerminated hold to answer case");
                    sendEmptyMessage(EVENT_RESUME_NOW_FOREGROUND_CALL);
                }
            } else if (mHoldSwitchingState == HoldSwapState.HOLDING_TO_DIAL_OUTGOING) {
                // The call that we were gonna hold might've gotten terminated. If that's the case,
                // dial mPendingMo if present.
                if (mPendingMO == null
                        || mPendingMO.getDisconnectCause() != DisconnectCause.NOT_DISCONNECTED) {
                    mHoldSwitchingState = HoldSwapState.INACTIVE;
                    logHoldSwapState("onCallTerminated hold to dial but no pendingMo");
                }
                if (imsCall != mPendingMO.getImsCall()) {
                    sendEmptyMessage(EVENT_DIAL_PENDINGMO);
                    mHoldSwitchingState = HoldSwapState.INACTIVE;
                    logHoldSwapState("onCallTerminated hold to dial, dial pendingMo");
                }
            }

            if (mShouldUpdateImsConfigOnDisconnect) {
@@ -2477,14 +2511,12 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
                    } else if (mRingingCall.getState() == ImsPhoneCall.State.WAITING
                            && mHoldSwitchingState == HoldSwapState.HOLDING_TO_ANSWER_INCOMING) {
                        sendEmptyMessage(EVENT_ANSWER_WAITING_CALL);
                    } else {
                        //when multiple connections belong to background call,
                        //only the first callback reaches here
                        //otherwise the oldState is already HOLDING
                        if (mPendingMO != null) {
                    } else if (mPendingMO != null
                            && mHoldSwitchingState == HoldSwapState.HOLDING_TO_DIAL_OUTGOING) {
                        dialPendingMO();
                        }

                        mHoldSwitchingState = HoldSwapState.INACTIVE;
                        logHoldSwapState("onCallHeld hold to dial");
                    } else {
                        // In this case there will be no call resumed, so we can assume that we
                        // are done switching fg and bg calls now.
                        // This may happen if there is no BG call and we are holding a call so that
@@ -2531,6 +2563,7 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
                        mCallExpectedToResume = null;
                    }
                }
                mHoldSwitchingState = HoldSwapState.INACTIVE;
                mPhone.notifySuppServiceFailed(Phone.SuppService.HOLD);
            }
            mMetrics.writeOnImsCallHoldFailed(mPhone.getPhoneId(), imsCall.getCallSession(),
@@ -3399,6 +3432,9 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
            case PENDING_RESUME_FOREGROUND_AFTER_FAILURE:
                holdSwapState = "PENDING_RESUME_FOREGROUND_AFTER_FAILURE";
                break;
            case HOLDING_TO_DIAL_OUTGOING:
                holdSwapState = "HOLDING_TO_DIAL_OUTGOING";
                break;
        }
        logi("holdSwapState set to " + holdSwapState + " at " + loc);
    }