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

Commit 9abff530 authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Fix issue where disconnect tone is truncated on call disconnect.

The tone generator path waits until the tone is done playing before
signaling to CallAudioManager that the tone has completed.  The media
path was not waiting for tone playback to complete before signaling
CallAudioManager.  As a result, CallAudioManager would release audio
focus before the tone stopped playing, sometimes resulting in it being
cut off or playing over the wrong audio route.

Test: Manual.
Bug: 111313134
Change-Id: I8f1a098f89b7e2db09bb719c04991804c3e92fbc
parent 87c0eaff
Loading
Loading
Loading
Loading
+14 −0
Original line number Original line Diff line number Diff line
@@ -28,6 +28,9 @@ import android.telecom.Logging.Session;


import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;


import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
/**
 * Play a call-related tone (ringback, busy signal, etc.) either through ToneGenerator, or using a
 * Play a call-related tone (ringback, busy signal, etc.) either through ToneGenerator, or using a
 * media resource file.
 * media resource file.
@@ -347,17 +350,28 @@ public class InCallTonePlayer extends Thread {
                    .build();
                    .build();
            mToneMediaPlayer = mMediaPlayerFactory.get(toneResourceId, attributes);
            mToneMediaPlayer = mMediaPlayerFactory.get(toneResourceId, attributes);
            mToneMediaPlayer.setLooping(false);
            mToneMediaPlayer.setLooping(false);
            int durationMillis = mToneMediaPlayer.getDuration();
            final CountDownLatch toneLatch = new CountDownLatch(1);
            mToneMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            mToneMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                @Override
                @Override
                public void onCompletion(MediaPlayer mp) {
                public void onCompletion(MediaPlayer mp) {
                    Log.i(this, "playMediaTone: toneResourceId=%d completed.", toneResourceId);
                    synchronized (this) {
                    synchronized (this) {
                        mState = STATE_OFF;
                        mState = STATE_OFF;
                    }
                    }
                    mToneMediaPlayer.release();
                    mToneMediaPlayer.release();
                    mToneMediaPlayer = null;
                    mToneMediaPlayer = null;
                    toneLatch.countDown();
                }
                }
            });
            });
            mToneMediaPlayer.start();
            mToneMediaPlayer.start();
            try {
                // Wait for the tone to stop playing; timeout at 2x the length of the file just to
                // be on the safe side.
                toneLatch.await(durationMillis * 2, TimeUnit.MILLISECONDS);
            } catch (InterruptedException ie) {
                Log.e(this, ie, "playMediaTone: tone playback interrupted.");
            }
        }
        }


    }
    }