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

Commit bd0d6d8f authored by Grace Jia's avatar Grace Jia Committed by Android (Google) Code Review
Browse files

Merge "Refactor CallsManager listener to track disconnected tone playing...

Merge "Refactor CallsManager listener to track disconnected tone playing status for each calls." into main
parents 663bd936 97668aa7
Loading
Loading
Loading
Loading
+11 −10
Original line number Diff line number Diff line
@@ -307,7 +307,7 @@ public class CallAudioManager extends CallsManagerListenerBase {
                VideoProfile.isReceptionEnabled(newVideoState);

        if (isUpgradeRequest) {
            mPlayerFactory.createPlayer(InCallTonePlayer.TONE_VIDEO_UPGRADE).startTone();
            mPlayerFactory.createPlayer(call, InCallTonePlayer.TONE_VIDEO_UPGRADE).startTone();
        }
    }

@@ -316,7 +316,7 @@ public class CallAudioManager extends CallsManagerListenerBase {
            // We only play tones for foreground calls.
            return;
        }
        mPlayerFactory.createPlayer(InCallTonePlayer.TONE_RTT_REQUEST).startTone();
        mPlayerFactory.createPlayer(call, InCallTonePlayer.TONE_RTT_REQUEST).startTone();
    }

    /**
@@ -329,7 +329,7 @@ public class CallAudioManager extends CallsManagerListenerBase {
     */
    @Override
    public void onHoldToneRequested(Call call) {
        maybePlayHoldTone();
        maybePlayHoldTone(call);
    }

    @Override
@@ -628,7 +628,7 @@ public class CallAudioManager extends CallsManagerListenerBase {
    }

    @VisibleForTesting
    public void setIsTonePlaying(boolean isTonePlaying) {
    public void setIsTonePlaying(Call call, boolean isTonePlaying) {
        Log.i(this, "setIsTonePlaying; isTonePlaying=%b", isTonePlaying);
        mIsTonePlaying = isTonePlaying;
        mCallAudioModeStateMachine.sendMessageWithArgs(
@@ -637,7 +637,7 @@ public class CallAudioManager extends CallsManagerListenerBase {
                makeArgsForModeStateMachine());

        if (!isTonePlaying && mIsDisconnectedTonePlaying) {
            mCallsManager.onDisconnectedTonePlaying(false);
            mCallsManager.onDisconnectedTonePlaying(call, false);
            mIsDisconnectedTonePlaying = false;
        }
    }
@@ -823,7 +823,7 @@ public class CallAudioManager extends CallsManagerListenerBase {
                        makeArgsForModeStateMachine());
            }
            mDtmfLocalTonePlayer.onForegroundCallChanged(oldForegroundCall, mForegroundCall);
            maybePlayHoldTone();
            maybePlayHoldTone(oldForegroundCall);
        }
    }

@@ -926,9 +926,9 @@ public class CallAudioManager extends CallsManagerListenerBase {
            Log.d(this, "Found a disconnected call with tone to play %d.", toneToPlay);

            if (toneToPlay != InCallTonePlayer.TONE_INVALID) {
                boolean didToneStart = mPlayerFactory.createPlayer(toneToPlay).startTone();
                boolean didToneStart = mPlayerFactory.createPlayer(call, toneToPlay).startTone();
                if (didToneStart) {
                    mCallsManager.onDisconnectedTonePlaying(true);
                    mCallsManager.onDisconnectedTonePlaying(call, true);
                    mIsDisconnectedTonePlaying = true;
                }
            }
@@ -948,10 +948,11 @@ public class CallAudioManager extends CallsManagerListenerBase {
    /**
     * Determines if a hold tone should be played and then starts or stops it accordingly.
     */
    private void maybePlayHoldTone() {
    private void maybePlayHoldTone(Call call) {
        if (shouldPlayHoldTone()) {
            if (mHoldTonePlayer == null) {
                mHoldTonePlayer = mPlayerFactory.createPlayer(InCallTonePlayer.TONE_CALL_WAITING);
                mHoldTonePlayer = mPlayerFactory.createPlayer(call,
                        InCallTonePlayer.TONE_CALL_WAITING);
                mHoldTonePlayer.startTone();
            }
        } else {
+1 −1
Original line number Diff line number Diff line
@@ -522,7 +522,7 @@ public class CallDiagnosticServiceController extends CallsManagerListenerBase {
                callId, messageId, message);
        if (mPlayerFactory != null) {
            // Play that tone!
            mPlayerFactory.createPlayer(InCallTonePlayer.TONE_IN_CALL_QUALITY_NOTIFICATION)
            mPlayerFactory.createPlayer(call, InCallTonePlayer.TONE_IN_CALL_QUALITY_NOTIFICATION)
                    .startTone();
        }
        call.displayDiagnosticMessage(messageId, message);
+5 −4
Original line number Diff line number Diff line
@@ -212,7 +212,7 @@ public class CallsManager extends Call.ListenerBase
        void onHoldToneRequested(Call call);
        void onExternalCallChanged(Call call, boolean isExternalCall);
        void onCallStreamingStateChanged(Call call, boolean isStreaming);
        void onDisconnectedTonePlaying(boolean isTonePlaying);
        void onDisconnectedTonePlaying(Call call, boolean isTonePlaying);
        void onConnectionTimeChanged(Call call);
        void onConferenceStateChanged(Call call, boolean isConference);
        void onCdmaConferenceSwap(Call call);
@@ -3612,14 +3612,15 @@ public class CallsManager extends Call.ListenerBase
     * Called when disconnect tone is started or stopped, including any InCallTone
     * after disconnected call.
     *
     * @param call
     * @param isTonePlaying true if the disconnected tone is started, otherwise the disconnected
     *                      tone is stopped.
     */
    @VisibleForTesting
    public void onDisconnectedTonePlaying(boolean isTonePlaying) {
    public void onDisconnectedTonePlaying(Call call, boolean isTonePlaying) {
        Log.v(this, "onDisconnectedTonePlaying, %s", isTonePlaying ? "started" : "stopped");
        for (CallsManagerListener listener : mListeners) {
            listener.onDisconnectedTonePlaying(isTonePlaying);
            listener.onDisconnectedTonePlaying(call, isTonePlaying);
        }
    }

+2 −2
Original line number Diff line number Diff line
@@ -16,10 +16,10 @@

package com.android.server.telecom;

import android.telecom.AudioState;
import android.telecom.CallAudioState;
import android.telecom.CallEndpoint;
import android.telecom.VideoProfile;

import java.util.Set;

/**
@@ -112,7 +112,7 @@ public abstract class CallsManagerListenerBase implements CallsManager.CallsMana
    }

    @Override
    public void onDisconnectedTonePlaying(boolean isTonePlaying) {
    public void onDisconnectedTonePlaying(Call call, boolean isTonePlaying) {
    }

    @Override
+7 −4
Original line number Diff line number Diff line
@@ -69,8 +69,8 @@ public class InCallTonePlayer extends Thread {
            mCallAudioManager = callAudioManager;
        }

        public InCallTonePlayer createPlayer(int tone) {
            return new InCallTonePlayer(tone, mCallAudioManager,
        public InCallTonePlayer createPlayer(Call call, int tone) {
            return new InCallTonePlayer(call, tone, mCallAudioManager,
                    mCallAudioRoutePeripheralAdapter, mLock, mToneGeneratorFactory,
                    mMediaPlayerFactory, mAudioManagerAdapter);
        }
@@ -212,6 +212,7 @@ public class InCallTonePlayer extends Thread {
    private Session mSession;
    private final Object mSessionLock = new Object();

    private final Call mCall;
    private final ToneGeneratorFactory mToneGenerator;
    private final MediaPlayerFactory mMediaPlayerFactory;
    private final AudioManagerAdapter mAudioManagerAdapter;
@@ -228,6 +229,7 @@ public class InCallTonePlayer extends Thread {
     * @param toneId ID of the tone to play, see TONE_* constants.
     */
    private InCallTonePlayer(
            Call call,
            int toneId,
            CallAudioManager callAudioManager,
            CallAudioRoutePeripheralAdapter callAudioRoutePeripheralAdapter,
@@ -235,6 +237,7 @@ public class InCallTonePlayer extends Thread {
            ToneGeneratorFactory toneGeneratorFactory,
            MediaPlayerFactory mediaPlayerFactor,
            AudioManagerAdapter audioManagerAdapter) {
        mCall = call;
        mState = STATE_OFF;
        mToneId = toneId;
        mCallAudioManager = callAudioManager;
@@ -476,7 +479,7 @@ public class InCallTonePlayer extends Thread {
        }

        if (sTonesPlaying.incrementAndGet() == 1) {
            mCallAudioManager.setIsTonePlaying(true);
            mCallAudioManager.setIsTonePlaying(mCall, true);
        }

        synchronized (mSessionLock) {
@@ -524,7 +527,7 @@ public class InCallTonePlayer extends Thread {
                    Log.i(InCallTonePlayer.this,
                            "cleanUpTonePlayer(): tonesPlaying=%d, tone completed", newToneCount);
                    if (mCallAudioManager != null) {
                        mCallAudioManager.setIsTonePlaying(false);
                        mCallAudioManager.setIsTonePlaying(mCall, false);
                    } else {
                        Log.w(InCallTonePlayer.this,
                                "cleanUpTonePlayer(): mCallAudioManager is null!");
Loading