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

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

Listen for ConnectionEvent and use the InCallToneMonitor to play the tone

BUG=25357778

Change-Id: Iad4f36f9b01670a2f188e726895a8349aeeb1502
parent ac7542b5
Loading
Loading
Loading
Loading
+44 −0
Original line number Diff line number Diff line
@@ -104,6 +104,7 @@ public class Call implements CreateConnectionResponse {
        void onPhoneAccountChanged(Call call);
        void onConferenceableCallsChanged(Call call);
        boolean onCanceledViaNewOutgoingCallBroadcast(Call call);
        void onHoldToneRequested(Call call);
    }

    public abstract static class ListenerBase implements Listener {
@@ -161,6 +162,9 @@ public class Call implements CreateConnectionResponse {
        public boolean onCanceledViaNewOutgoingCallBroadcast(Call call) {
            return false;
        }

        @Override
        public void onHoldToneRequested(Call call) {}
    }

    private final OnQueryCompleteListener mCallerInfoQueryListener =
@@ -365,6 +369,14 @@ public class Call implements CreateConnectionResponse {
    // Set to true once the NewOutgoingCallIntentBroadcast comes back and is processed.
    private boolean mIsNewOutgoingCallIntentBroadcastDone = false;


    /**
     * Indicates whether the call is remotely held.  A call is considered remotely held when
     * {@link #onConnectionEvent(String)} receives the {@link Connection#EVENT_ON_HOLD_TONE_START}
     * event.
     */
    private boolean mIsRemotelyHeld = false;

    /**
     * Persists the specified parameters and initializes the new instance.
     *
@@ -1921,4 +1933,36 @@ public class Call implements CreateConnectionResponse {
    public void setNewOutgoingCallIntentBroadcastIsDone() {
        mIsNewOutgoingCallIntentBroadcastDone = true;
    }

    /**
     * Determines if the call has been held by the remote party.
     *
     * @return {@code true} if the call is remotely held, {@code false} otherwise.
     */
    public boolean isRemotelyHeld() {
        return mIsRemotelyHeld;
    }

    /**
     * Handles Connection events received from a {@link ConnectionService}.
     *
     * @param event The event.
     */
    public void onConnectionEvent(String event) {
        if (Connection.EVENT_ON_HOLD_TONE_START.equals(event)) {
            mIsRemotelyHeld = true;
            Log.event(this, Log.Events.REMOTELY_HELD);
            // Inform listeners of the fact that a call hold tone was received.  This will trigger
            // the CallAudioManager to play a tone via the InCallTonePlayer.
            for (Listener l : mListeners) {
                l.onHoldToneRequested(this);
            }
        } else if (Connection.EVENT_ON_HOLD_TONE_END.equals(event)) {
            mIsRemotelyHeld = false;
            Log.event(this, Log.Events.REMOTELY_UNHELD);
            for (Listener l : mListeners) {
                l.onHoldToneRequested(this);
            }
        }
    }
}
+60 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ public class CallAudioManager extends CallsManagerListenerBase {

    private Call mForegroundCall;
    private boolean mIsTonePlaying = false;
    private InCallTonePlayer mHoldTonePlayer;

    public CallAudioManager(CallAudioRouteStateMachine callAudioRouteStateMachine,
            CallsManager callsManager,
@@ -213,6 +214,19 @@ public class CallAudioManager extends CallsManagerListenerBase {
        }
    }

    /**
     * Play or stop a call hold tone for a call.  Triggered via
     * {@link Connection#sendConnectionEvent(String)} when the
     * {@link Connection#EVENT_ON_HOLD_TONE_START} event or
     * {@link Connection#EVENT_ON_HOLD_TONE_STOP} event is passed through to the
     *
     * @param call The call which requested the hold tone.
     */
    @Override
    public void onHoldToneRequested(Call call) {
        maybePlayHoldTone();
    }

    @Override
    public void onIsVoipAudioModeChanged(Call call) {
        if (call != mForegroundCall) {
@@ -486,6 +500,7 @@ public class CallAudioManager extends CallsManagerListenerBase {

        if (mForegroundCall != oldForegroundCall) {
            mDtmfLocalTonePlayer.onForegroundCallChanged(oldForegroundCall, mForegroundCall);
            maybePlayHoldTone();
        }
    }

@@ -554,6 +569,51 @@ public class CallAudioManager extends CallsManagerListenerBase {
        mRingbackPlayer.stopRingbackForCall(call);
    }

    /**
     * Determines if a hold tone should be played and then starts or stops it accordingly.
     */
    private void maybePlayHoldTone() {
        if (shouldPlayHoldTone()) {
            if (mHoldTonePlayer == null) {
                mHoldTonePlayer = mPlayerFactory.createPlayer(InCallTonePlayer.TONE_CALL_WAITING);
                mHoldTonePlayer.start();
            }
        } else {
            if (mHoldTonePlayer != null) {
                mHoldTonePlayer.stopTone();
                mHoldTonePlayer = null;
            }
        }
    }

    /**
     * Determines if a hold tone should be played.
     * A hold tone should be played only if foreground call is equals with call which is
     * remotely held.
     *
     * @return {@code true} if the the hold tone should be played, {@code false} otherwise.
     */
    private boolean shouldPlayHoldTone() {
        Call foregroundCall = getForegroundCall();
        // If there is no foreground call, no hold tone should play.
        if (foregroundCall == null) {
            return false;
        }

        // If another call is ringing, no hold tone should play.
        if (mCallsManager.hasRingingCall()) {
            return false;
        }

        // If the foreground call isn't active, no hold tone should play. This might happen, for
        // example, if the user puts a remotely held call on hold itself.
        if (!foregroundCall.isActive()) {
            return false;
        }

        return foregroundCall.isRemotelyHeld();
    }

    private void dumpCallsInCollection(IndentingPrintWriter pw, Collection<Call> calls) {
        for (Call call : calls) {
            if (call != null) pw.println(call.getId());
+16 −1
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ public class CallsManager extends Call.ListenerBase
        void onVideoStateChanged(Call call);
        void onCanAddCallChanged(boolean canAddCall);
        void onSessionModifyRequestReceived(Call call, VideoProfile videoProfile);
        void onHoldToneRequested(Call call);
    }

    private static final String TAG = "CallsManager";
@@ -522,11 +523,25 @@ public class CallsManager extends Call.ListenerBase
        }
    }

    @VisibleForTesting
    public Collection<Call> getCalls() {
        return Collections.unmodifiableCollection(mCalls);
    }

    /**
     * Play or stop a call hold tone for a call.  Triggered via
     * {@link Connection#sendConnectionEvent(String)} when the
     * {@link Connection#EVENT_ON_HOLD_TONE_START} event or
     * {@link Connection#EVENT_ON_HOLD_TONE_STOP} event is passed through to the
     *
     * @param call The call which requested the hold tone.
     */
    @Override
    public void onHoldToneRequested(Call call) {
        for (CallsManagerListener listener : mListeners) {
            listener.onHoldToneRequested(call);
        }
    }

    @VisibleForTesting
    public Call getForegroundCall() {
        if (mCallAudioManager == null) {
+4 −0
Original line number Diff line number Diff line
@@ -80,4 +80,8 @@ public class CallsManagerListenerBase implements CallsManager.CallsManagerListen
    public void onSessionModifyRequestReceived(Call call, VideoProfile videoProfile) {

    }

    @Override
    public void onHoldToneRequested(Call call) {
    }
}
+17 −0
Original line number Diff line number Diff line
@@ -587,6 +587,23 @@ public class ConnectionServiceWrapper extends ServiceBinder {
                Log.endSession();
            }
        }

        @Override
        public void onConnectionEvent(String callId, String event) {
            Log.startSession("CSW.oCE");
            long token = Binder.clearCallingIdentity();
            try {
                synchronized (mLock) {
                    Call call = mCallIdMapper.getCall(callId);
                    if (call != null) {
                        call.onConnectionEvent(event);
                    }
                }
            } finally {
                Binder.restoreCallingIdentity(token);
                Log.endSession();
            }
        }
    }

    private final Adapter mAdapter = new Adapter();
Loading