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

Commit a4114d3b authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Stop local ringback on SRVCC.

When a call undergoes SRVCC is may be playing local ringback.  Ensuring
that the local ringback will stop in this case.

Also fixed flakey test in the ImsPhoneCallTest; this drove some changes
in ImsPhoneCall changing how the ImsPhone is retrieved; the
TelephonyTestCase does some black magic to replace instances of things
at test setup.  Realistically there is no reason you can't get just the
phone from the ImsPhoneCallTracker and use that to avoid the black magic.

Test: Added new unit test for this case.
Bug: 119917326
Change-Id: I5e79b410f36d7a56c0a885bd35eecaadf13973db
parent 08024bc3
Loading
Loading
Loading
Loading
+21 −11
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ public class ImsPhoneCall extends Call {

    /*package*/ ImsPhoneCallTracker mOwner;

    private boolean mRingbackTonePlayed = false;
    private boolean mIsRingbackTonePlaying = false;

    // Determines what type of ImsPhoneCall this is.  ImsPhoneCallTracker uses instances of
    // ImsPhoneCall to for fg, bg, etc calls.  This is used as a convenience for logging so that it
@@ -96,7 +96,7 @@ public class ImsPhoneCall extends Call {
    @Override
    public Phone
    getPhone() {
        return mOwner.mPhone;
        return mOwner.getPhone();
    }

    @Override
@@ -314,17 +314,17 @@ public class ImsPhoneCall extends Call {
        //ImsCall.Listener.onCallProgressing can be invoked several times
        //and ringback tone mode can be changed during the call setup procedure
        if (state == State.ALERTING) {
            if (mRingbackTonePlayed && !isLocalTone(imsCall)) {
                mOwner.mPhone.stopRingbackTone();
                mRingbackTonePlayed = false;
            } else if (!mRingbackTonePlayed && isLocalTone(imsCall)) {
                mOwner.mPhone.startRingbackTone();
                mRingbackTonePlayed = true;
            if (mIsRingbackTonePlaying && !isLocalTone(imsCall)) {
                getPhone().stopRingbackTone();
                mIsRingbackTonePlaying = false;
            } else if (!mIsRingbackTonePlaying && isLocalTone(imsCall)) {
                getPhone().startRingbackTone();
                mIsRingbackTonePlaying = true;
            }
        } else {
            if (mRingbackTonePlayed) {
                mOwner.mPhone.stopRingbackTone();
                mRingbackTonePlayed = false;
            if (mIsRingbackTonePlaying) {
                getPhone().stopRingbackTone();
                mIsRingbackTonePlaying = false;
            }
        }

@@ -360,6 +360,16 @@ public class ImsPhoneCall extends Call {
        mOwner.logState();
    }

    /**
     * Stops ringback tone playing if it is playing.
     */
    public void maybeStopRingback() {
        if (mIsRingbackTonePlaying) {
            getPhone().stopRingbackTone();
            mIsRingbackTonePlaying = false;
        }
    }

    private void takeOver(ImsPhoneCall that) {
        mConnections = that.mConnections;
        mState = that.mState;
+10 −0
Original line number Diff line number Diff line
@@ -2720,6 +2720,12 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {

            ImsPhoneConnection conn = findConnection(imsCall);
            if (conn != null) {
                ImsPhoneCall imsPhoneCall = conn.getCall();
                if (imsPhoneCall != null) {
                    // We might be playing ringback on the handover connection; we should stop
                    // playing it at this point (otherwise it could play indefinitely).
                    imsPhoneCall.maybeStopRingback();
                }
                if (conn.getDisconnectCause() == DisconnectCause.NOT_DISCONNECTED) {
                    if (isHandoverToWifi) {
                        removeMessages(EVENT_CHECK_FOR_WIFI_HANDOVER);
@@ -4072,4 +4078,8 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
    public void setAlwaysPlayRemoteHoldTone(boolean shouldPlayRemoteHoldTone) {
        mAlwaysPlayRemoteHoldTone = shouldPlayRemoteHoldTone;
    }

    public ImsPhone getPhone() {
        return mPhone;
    }
}
+18 −2
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.telephony.ims.ImsStreamMediaProfile;
import android.test.suitebuilder.annotation.SmallTest;
@@ -54,6 +55,7 @@ public class ImsPhoneCallTest extends TelephonyTest {
        replaceInstance(ImsPhoneCallTracker.class, "mPhone", mImsCT, mImsPhone);

        mImsCallUT = new ImsPhoneCall(mImsCT, ImsPhoneCall.CONTEXT_FOREGROUND);
        when(mImsCT.getPhone()).thenReturn(mImsPhone);
        mMediaProfile = new ImsStreamMediaProfile();
    }

@@ -119,8 +121,6 @@ public class ImsPhoneCallTest extends TelephonyTest {
        }
    }

    @FlakyTest
    @Ignore
    @Test
    @SmallTest
    public void testUpdateRingBackTone() {
@@ -136,6 +136,22 @@ public class ImsPhoneCallTest extends TelephonyTest {
        assertEquals(Call.State.ACTIVE, mImsCallUT.getState());
    }

    @Test
    @SmallTest
    public void testStopRingingOnHandover() {
        //Mock local tone
        mMediaProfile.mAudioDirection = ImsStreamMediaProfile.DIRECTION_INACTIVE;
        mImsCallProfile.mMediaProfile = mMediaProfile;

        mImsCallUT.update(null, mImsCall, Call.State.ALERTING);
        verify(mImsPhone, times(1)).startRingbackTone();
        assertEquals(Call.State.ALERTING, mImsCallUT.getState());

        // Emulate ringback terminate on handover.
        mImsCallUT.maybeStopRingback();
        verify(mImsPhone, times(1)).stopRingbackTone();
    }

    @Test
    @SmallTest
    public void testSwitchWith() {