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

Commit 01731076 authored by Tyler Gunn's avatar Tyler Gunn Committed by android-build-merger
Browse files

Merge "Fix issue where disconnect tone is truncated on call disconnect." am: f5b8f186

am: 43ba31ab

Change-Id: Ic6ab8a04f11cb094f770e1263f73f985b16862d8
parents 8047e589 43ba31ab
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -28,6 +28,9 @@ import android.telecom.Logging.Session;

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
 * media resource file.
@@ -347,17 +350,28 @@ public class InCallTonePlayer extends Thread {
                    .build();
            mToneMediaPlayer = mMediaPlayerFactory.get(toneResourceId, attributes);
            mToneMediaPlayer.setLooping(false);
            int durationMillis = mToneMediaPlayer.getDuration();
            final CountDownLatch toneLatch = new CountDownLatch(1);
            mToneMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                @Override
                public void onCompletion(MediaPlayer mp) {
                    Log.i(this, "playMediaTone: toneResourceId=%d completed.", toneResourceId);
                    synchronized (this) {
                        mState = STATE_OFF;
                    }
                    mToneMediaPlayer.release();
                    mToneMediaPlayer = null;
                    toneLatch.countDown();
                }
            });
            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.");
            }
        }

    }