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

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

Merge "Add option to use Ringtone looping API in Telecom config.xml" am: 9cb2041a

am: d2932af8

Change-Id: I47ee56cca898e3229d9b70133b6605ac5e7a9574
parents 81fa0817 d2932af8
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -55,4 +55,9 @@
         When false, a fancy vibration pattern which ramps up and down will be used.
         Devices should overlay this value based on the type of vibration hardware they employ. -->
    <bool name="use_simple_vibration_pattern">false</bool>

    <!-- When true, if Telecom is playing the ringtone, it will attempt to pause for some time
         between repeats of the ringtone.
         When false, the ringtone will be looping with no pause. -->
    <bool name="should_pause_between_ringtone_repeats">true</bool>
</resources>
+29 −1
Original line number Diff line number Diff line
@@ -47,6 +47,26 @@ public class AsyncRingtonePlayer {
    /** The current ringtone. Only used by the ringtone thread. */
    private Ringtone mRingtone;

    /**
     * Determines if the {@link AsyncRingtonePlayer} should pause between repeats of the ringtone.
     * When {@code true}, the system will check if the ringtone has stopped every
     * {@link #RESTART_RINGER_MILLIS} and restart the ringtone if it has stopped.  This does not
     * guarantee that there is {@link #RESTART_RINGER_MILLIS} between each repeat of the ringtone,
     * rather it ensures that for short ringtones, or ringtones which are not a multiple of
     * {@link #RESTART_RINGER_MILLIS} in duration that there will be some pause between repetitions.
     * When {@code false}, the ringtone will be looped continually with no attempt to pause between
     * repeats.
     */
    private boolean mShouldPauseBetweenRepeat = true;

    public AsyncRingtonePlayer() {
        // Empty
    }

    public AsyncRingtonePlayer(boolean shouldPauseBetweenRepeat) {
        mShouldPauseBetweenRepeat = shouldPauseBetweenRepeat;
    }

    /** Plays the ringtone. */
    public void play(RingtoneFactory factory, Call incomingCall) {
        Log.d(this, "Posting play.");
@@ -144,7 +164,15 @@ public class AsyncRingtonePlayer {
            }
        }

        if (mShouldPauseBetweenRepeat) {
            // We're trying to pause between repeats, so the ringtone will not intentionally loop.
            // Instead, we'll use a handler message to perform repeats.
            handleRepeat();
        } else {
            mRingtone.setLooping(true);
            mRingtone.play();
            Log.i(this, "Play ringtone, looping.");
        }
    }

    private void handleRepeat() {
+5 −1
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import com.android.server.telecom.PhoneNumberUtilsAdapterImpl;
import com.android.server.telecom.ProximitySensorManagerFactory;
import com.android.server.telecom.InCallWakeLockController;
import com.android.server.telecom.ProximitySensorManager;
import com.android.server.telecom.R;
import com.android.server.telecom.TelecomSystem;
import com.android.server.telecom.TelecomWakeLock;
import com.android.server.telecom.Timeouts;
@@ -85,6 +86,9 @@ public class TelecomService extends Service implements TelecomSystem.Component {
            NotificationChannelManager notificationChannelManager =
                    new NotificationChannelManager();
            notificationChannelManager.createChannels(context);

            boolean shouldPauseBetweenRingtoneRepeat = context.getResources().getBoolean(
                    R.bool.should_pause_between_ringtone_repeats);
            TelecomSystem.setInstance(
                    new TelecomSystem(
                            context,
@@ -166,7 +170,7 @@ public class TelecomService extends Service implements TelecomSystem.Component {
                            },
                            ConnectionServiceFocusManager::new,
                            new Timeouts.Adapter(),
                            new AsyncRingtonePlayer(),
                            new AsyncRingtonePlayer(shouldPauseBetweenRingtoneRepeat),
                            new PhoneNumberUtilsAdapterImpl(),
                            new IncomingCallNotifier(context),
                            ToneGenerator::new,