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

Commit 1aceda35 authored by repo sync's avatar repo sync
Browse files

Support Invite w/ Replaces request.

bug:3326870
Change-Id: Idbfbe7e3cc6ba83874d42bfb7d149866f454e70a
parent 14f14863
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -71,6 +71,14 @@ interface ISipSessionListener {
     */
    void onCallBusy(in ISipSession session);

    /**
     * Called when the call is being transferred to a new one.
     *
     * @param newSession the new session that the call will be transferred to
     * @param sessionDescription the new peer's session description
     */
    void onCallTransferring(in ISipSession newSession, String sessionDescription);

    /**
     * Called when an error occurs during session initialization and
     * termination.
+56 −1
Original line number Diff line number Diff line
@@ -170,6 +170,7 @@ public class SipAudioCall {
    private SipProfile mLocalProfile;
    private SipAudioCall.Listener mListener;
    private SipSession mSipSession;
    private SipSession mTransferringSession;

    private long mSessionId = System.currentTimeMillis();
    private String mPeerSd;
@@ -347,6 +348,27 @@ public class SipAudioCall {
        }
    }

    private synchronized void transferToNewSession() {
        if (mTransferringSession == null) return;
        SipSession origin = mSipSession;
        mSipSession = mTransferringSession;
        mTransferringSession = null;

        // stop the replaced call.
        if (mAudioStream != null) {
            mAudioStream.join(null);
        } else {
            try {
                mAudioStream = new AudioStream(InetAddress.getByName(
                        getLocalIp()));
            } catch (Throwable t) {
                Log.i(TAG, "transferToNewSession(): " + t);
            }
        }
        if (origin != null) origin.endCall();
        startAudio();
    }

    private SipSession.Listener createListener() {
        return new SipSession.Listener() {
            @Override
@@ -404,6 +426,13 @@ public class SipAudioCall {
                mPeerSd = sessionDescription;
                Log.v(TAG, "onCallEstablished()" + mPeerSd);

                // TODO: how to notify the UI that the remote party is changed
                if ((mTransferringSession != null)
                        && (session == mTransferringSession)) {
                    transferToNewSession();
                    return;
                }

                Listener listener = mListener;
                if (listener != null) {
                    try {
@@ -420,7 +449,17 @@ public class SipAudioCall {

            @Override
            public void onCallEnded(SipSession session) {
                Log.d(TAG, "sip call ended: " + session);
                Log.d(TAG, "sip call ended: " + session + " mSipSession:" + mSipSession);
                // reset the trasnferring session if it is the one.
                if (session == mTransferringSession) {
                    mTransferringSession = null;
                    return;
                }
                // or ignore the event if the original session is being
                // transferred to the new one.
                if ((mTransferringSession != null) ||
                    (session != mSipSession)) return;

                Listener listener = mListener;
                if (listener != null) {
                    try {
@@ -489,6 +528,22 @@ public class SipAudioCall {
            public void onRegistrationDone(SipSession session, int duration) {
                // irrelevant
            }

            @Override
            public void onCallTransferring(SipSession newSession,
                    String sessionDescription) {
                Log.v(TAG, "onCallTransferring mSipSession:"
                        + mSipSession + " newSession:" + newSession);
                mTransferringSession = newSession;
                // session changing request
                try {
                    String answer = createAnswer(sessionDescription).encode();
                    newSession.answerCall(answer, SESSION_TIMEOUT);
                } catch (Throwable e) {
                    Log.e(TAG, "onCallTransferring()", e);
                    newSession.endCall();
                }
            }
        };
    }

+21 −0
Original line number Diff line number Diff line
@@ -159,6 +159,17 @@ public final class SipSession {
        public void onCallBusy(SipSession session) {
        }

        /**
         * Called when the call is being transferred to a new one.
         *
         * @hide
         * @param newSession the new session that the call will be transferred to
         * @param sessionDescription the new peer's session description
         */
        public void onCallTransferring(SipSession newSession,
                String sessionDescription) {
        }

        /**
         * Called when an error occurs during session initialization and
         * termination.
@@ -489,6 +500,16 @@ public final class SipSession {
                }
            }

            public void onCallTransferring(ISipSession session,
                    String sessionDescription) {
                if (mListener != null) {
                    mListener.onCallTransferring(
                            new SipSession(session, SipSession.this.mListener),
                            sessionDescription);

                }
            }

            public void onCallChangeFailed(ISipSession session, int errorCode,
                    String message) {
                if (mListener != null) {
+4 −0
Original line number Diff line number Diff line
@@ -42,6 +42,10 @@ public class SipSessionAdapter extends ISipSessionListener.Stub {
    public void onCallBusy(ISipSession session) {
    }

    public void onCallTransferring(ISipSession session,
            String sessionDescription) {
    }

    public void onCallChangeFailed(ISipSession session, int errorCode,
            String message) {
    }
+1 −1
Original line number Diff line number Diff line
@@ -314,7 +314,7 @@ class SipHelper {
        }
    }

    private ServerTransaction getServerTransaction(RequestEvent event)
    public ServerTransaction getServerTransaction(RequestEvent event)
            throws SipException {
        ServerTransaction transaction = event.getServerTransaction();
        if (transaction == null) {
Loading