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

Commit 1537637c authored by Hung-ying Tyan's avatar Hung-ying Tyan Committed by Android Git Automerger
Browse files

am 3294d44b: Add confcall management to SIP calls

Merge commit '3294d44b' into gingerbread-plus-aosp

* commit '3294d44b':
  Add confcall management to SIP calls
parents 2ac479fa 3294d44b
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -322,7 +322,9 @@ public final class CallManager {
                }
                break;
        }
        audioManager.setMode(mode);
        // calling audioManager.setMode() multiple times in a short period of
        // time seems to break the audio recorder in in-call mode
        if (audioManager.getMode() != mode) audioManager.setMode(mode);
    }

    private Context getContext() {
+4 −2
Original line number Diff line number Diff line
@@ -85,8 +85,10 @@ abstract class SipConnectionBase extends Connection {
    protected void setState(Call.State state) {
        switch (state) {
            case ACTIVE:
                if (connectTime == 0) {
                    connectTimeReal = SystemClock.elapsedRealtime();
                    connectTime = System.currentTimeMillis();
                }
                break;
            case DISCONNECTED:
                duration = SystemClock.elapsedRealtime() - connectTimeReal;
+90 −69
Original line number Diff line number Diff line
@@ -100,7 +100,7 @@ public class SipPhone extends SipPhoneBase {
    }

    public String getPhoneName() {
        return mProfile.getProfileName();
        return "SIP:" + getUriString(mProfile);
    }

    public String getSipUri() {
@@ -222,6 +222,7 @@ public class SipPhone extends SipPhoneBase {
    }

    public void conference() throws CallStateException {
        synchronized (SipPhone.class) {
            if ((foregroundCall.getState() != SipCall.State.ACTIVE)
                    || (foregroundCall.getState() != SipCall.State.ACTIVE)) {
                throw new CallStateException("wrong state to merge calls: fg="
@@ -230,14 +231,17 @@ public class SipPhone extends SipPhoneBase {
            }
            foregroundCall.merge(backgroundCall);
        }
    }

    public void conference(Call that) throws CallStateException {
        synchronized (SipPhone.class) {
            if (!(that instanceof SipCall)) {
                throw new CallStateException("expect " + SipCall.class
                        + ", cannot merge with " + that.getClass());
            }
            foregroundCall.merge((SipCall) that);
        }
    }

    public boolean canTransfer() {
        return false;
@@ -248,6 +252,7 @@ public class SipPhone extends SipPhoneBase {
    }

    public void clearDisconnected() {
        synchronized (SipPhone.class) {
            ringingCall.clearDisconnected();
            foregroundCall.clearDisconnected();
            backgroundCall.clearDisconnected();
@@ -255,15 +260,18 @@ public class SipPhone extends SipPhoneBase {
            updatePhoneState();
            notifyPreciseCallStateChanged();
        }
    }

    public void sendDtmf(char c) {
        if (!PhoneNumberUtils.is12Key(c)) {
            Log.e(LOG_TAG,
                    "sendDtmf called with invalid character '" + c + "'");
        } else if (foregroundCall.getState().isAlive()) {
            synchronized (SipPhone.class) {
                foregroundCall.sendDtmf(c);
            }
        }
    }

    public void startDtmf(char c) {
        if (!PhoneNumberUtils.is12Key(c)) {
@@ -307,8 +315,10 @@ public class SipPhone extends SipPhoneBase {
    }

    public void setMute(boolean muted) {
        synchronized (SipPhone.class) {
            foregroundCall.setMute(muted);
        }
    }

    public boolean getMute() {
        return foregroundCall.getMute();
@@ -410,6 +420,7 @@ public class SipPhone extends SipPhoneBase {

        @Override
        public void hangup() throws CallStateException {
            synchronized (SipPhone.class) {
                Log.v(LOG_TAG, "hang up call: " + getState() + ": " + this
                        + " on phone " + getPhone());
                CallStateException excp = null;
@@ -423,6 +434,7 @@ public class SipPhone extends SipPhoneBase {
                if (excp != null) throw excp;
                setState(State.DISCONNECTING);
            }
        }

        void initIncomingCall(SipAudioCall sipAudioCall, boolean makeCallWait) {
            SipProfile callee = sipAudioCall.getPeerProfile();
@@ -454,19 +466,20 @@ public class SipPhone extends SipPhoneBase {
        }

        void hold() throws CallStateException {
            setState(State.HOLDING);
            AudioGroup audioGroup = getAudioGroup();
            if (audioGroup == null) return;
            if (audioGroup != null) {
                audioGroup.setMode(AudioGroup.MODE_ON_HOLD);
            setState(State.HOLDING);
            }
            for (Connection c : connections) ((SipConnection) c).hold();
        }

        void unhold() throws CallStateException {
            AudioGroup audioGroup = getAudioGroup();
            if (audioGroup == null) return;
            audioGroup.setMode(AudioGroup.MODE_NORMAL);
            setState(State.ACTIVE);
            for (Connection c : connections) ((SipConnection) c).unhold();
            AudioGroup audioGroup = new AudioGroup();
            for (Connection c : connections) {
                ((SipConnection) c).unhold(audioGroup);
            }
        }

        void setMute(boolean muted) {
@@ -483,17 +496,26 @@ public class SipPhone extends SipPhoneBase {
        }

        void merge(SipCall that) throws CallStateException {
            AudioGroup myGroup = getAudioGroup();
            AudioGroup audioGroup = getAudioGroup();
            for (Connection c : that.connections) {
                SipConnection conn = (SipConnection) c;
                conn.mergeTo(myGroup);
                connections.add(conn);
                conn.changeOwner(this);
                add(conn);
                if (conn.getState() == Call.State.HOLDING) {
                    conn.unhold(audioGroup);
                }
            }
            that.connections.clear();
            that.setState(Call.State.IDLE);
        }

        private void add(SipConnection conn) {
            SipCall call = conn.getCall();
            if (call == this) return;
            if (call != null) call.connections.remove(conn);

            connections.add(conn);
            conn.changeOwner(this);
        }

        void sendDtmf(char c) {
            AudioGroup audioGroup = getAudioGroup();
            if (audioGroup == null) return;
@@ -568,7 +590,6 @@ public class SipPhone extends SipPhoneBase {
    private class SipConnection extends SipConnectionBase {
        private SipCall mOwner;
        private SipAudioCall mSipAudioCall;
        private AudioGroup mOriginalGroup;
        private Call.State mState = Call.State.IDLE;
        private SipProfile mPeer;
        private boolean mIncoming = false;
@@ -673,6 +694,7 @@ public class SipPhone extends SipPhoneBase {
        }

        void hold() throws CallStateException {
            setState(Call.State.HOLDING);
            try {
                mSipAudioCall.holdCall();
            } catch (SipException e) {
@@ -680,7 +702,9 @@ public class SipPhone extends SipPhoneBase {
            }
        }

        void unhold() throws CallStateException {
        void unhold(AudioGroup audioGroup) throws CallStateException {
            mSipAudioCall.setAudioGroup(audioGroup);
            setState(Call.State.ACTIVE);
            try {
                mSipAudioCall.continueCall();
            } catch (SipException e) {
@@ -688,16 +712,6 @@ public class SipPhone extends SipPhoneBase {
            }
        }

        void mergeTo(AudioGroup group) throws CallStateException {
            AudioStream stream = mSipAudioCall.getAudioStream();
            if (stream == null) {
                throw new CallStateException("wrong state to merge: "
                        + mSipAudioCall.getState());
            }
            if (mOriginalGroup == null) mOriginalGroup = getAudioGroup();
            stream.join(group);
        }

        @Override
        protected void setState(Call.State state) {
            if (state == mState) return;
@@ -732,10 +746,9 @@ public class SipPhone extends SipPhoneBase {

        @Override
        public void hangup() throws CallStateException {
            // TODO: need to pull AudioStream out of the AudioGroup in case
            // this conn was part of a conf call
            synchronized (SipPhone.class) {
                Log.v(LOG_TAG, "hangup conn: " + mPeer.getUriString() + ": "
                    + ": on phone " + getPhone());
                        + ": on phone " + getPhone().getPhoneName());
                try {
                    mSipAudioCall.endCall();
                    setState(Call.State.DISCONNECTING);
@@ -744,17 +757,25 @@ public class SipPhone extends SipPhoneBase {
                    throw new CallStateException("hangup(): " + e);
                }
            }
        }

        @Override
        public void separate() throws CallStateException {
            // TODO: what's this for SIP?
            /*
            if (!disconnected) {
                owner.separate(this);
            } else {
                throw new CallStateException ("disconnected");
            synchronized (SipPhone.class) {
                SipCall call = (SipCall) SipPhone.this.getBackgroundCall();
                if (call.getState() != Call.State.IDLE) {
                    throw new CallStateException(
                            "cannot put conn back to a call in non-idle state: "
                            + call.getState());
                }
                Log.v(LOG_TAG, "separate conn: " + mPeer.getUriString()
                        + " from " + mOwner + " back to " + call);

                AudioGroup audioGroup = call.getAudioGroup(); // may be null
                call.add(this);
                mSipAudioCall.setAudioGroup(audioGroup);
                call.hold();
            }
            */
        }

        @Override
+0 −4
Original line number Diff line number Diff line
@@ -175,10 +175,6 @@ abstract class SipPhoneBase extends PhoneBase {
        return state;
    }

    public String getPhoneName() {
        return "SIP";
    }

    public int getPhoneType() {
        // FIXME: add SIP phone type
        return Phone.PHONE_TYPE_GSM;
+11 −1
Original line number Diff line number Diff line
@@ -244,7 +244,8 @@ public interface SipAudioCall {
     * Also, the {@code AudioStream} may change its group during a call (e.g.,
     * after the call is held/un-held). Finally, the {@code AudioGroup} object
     * returned by this method is undefined after the call ends or the
     * {@link #close} method is called.
     * {@link #close} method is called. If a group object is set by
     * {@link #setAudioGroup(AudioGroup)}, then this method returns that object.
     *
     * @return the {@link AudioGroup} object or null if the RTP stream has not
     *      yet been set up
@@ -252,6 +253,15 @@ public interface SipAudioCall {
     */
    AudioGroup getAudioGroup();

    /**
     * Sets the {@link AudioGroup} object which the {@link AudioStream} object
     * joins. If {@code audioGroup} is null, then the {@code AudioGroup} object
     * will be dynamically created when needed.
     *
     * @see #getAudioStream
     */
    void setAudioGroup(AudioGroup audioGroup);

    /**
     * Checks if the call is established.
     *
Loading