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

Commit 5a341d24 authored by Lais Andrade's avatar Lais Andrade Committed by Android (Google) Code Review
Browse files

Merge "Always stop Ringtone instance in AsyncRingtonePlayer"

parents dfbe9ec1 cd9213eb
Loading
Loading
Loading
Loading
+15 −8
Original line number Diff line number Diff line
@@ -172,13 +172,13 @@ public class AsyncRingtonePlayer {
            // Use haptic-only ringtone or do not play anything.
            if (!isRingerAudible || Uri.EMPTY.equals(incomingCall.getRingtone())) {
                if (isVibrationEnabled) {
                    mRingtone = factory.getHapticOnlyRingtone();
                    setRingtone(factory.getHapticOnlyRingtone());
                    if (mRingtone == null) {
                        completeHapticFuture(false /* ringtoneHasHaptics */);
                        return;
                    }
                } else {
                    mRingtone = null;
                    setRingtone(null);
                    completeHapticFuture(false /* ringtoneHasHaptics */);
                    return;
                }
@@ -188,7 +188,7 @@ public class AsyncRingtonePlayer {
            Log.i(this, "handlePlay: Play ringtone.");

            if (mRingtone == null) {
                mRingtone = factory.getRingtone(incomingCall, volumeShaperConfig);
                setRingtone(factory.getRingtone(incomingCall, volumeShaperConfig));
                if (mRingtone == null) {
                    Uri ringtoneUri = incomingCall.getRingtone();
                    String ringtoneUriString = (ringtoneUri == null) ? "null" :
@@ -240,11 +240,7 @@ public class AsyncRingtonePlayer {
        ThreadUtil.checkNotOnMainThread();
        Log.i(this, "Stop ringtone.");

        if (mRingtone != null) {
            Log.d(this, "Ringtone.stop() invoked.");
            mRingtone.stop();
            mRingtone = null;
        }
        setRingtone(null);

        synchronized(this) {
            if (mHandler.hasMessages(EVENT_PLAY)) {
@@ -262,6 +258,17 @@ public class AsyncRingtonePlayer {
        return mRingtone != null;
    }

    private void setRingtone(@Nullable Ringtone ringtone) {
        // Make sure that any previously created instance of Ringtone is stopped so the MediaPlayer
        // can be released, before replacing mRingtone with a new instance. This is always created
        // as a looping Ringtone, so if not stopped it will keep playing on the background.
        if (mRingtone != null) {
            Log.d(this, "Ringtone.stop() invoked.");
            mRingtone.stop();
        }
        mRingtone = ringtone;
    }

    private void completeHapticFuture(boolean ringtoneHasHaptics) {
        if (mHapticsFuture != null) {
            mHapticsFuture.complete(ringtoneHasHaptics);