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

Commit a93c7cee authored by James Lemieux's avatar James Lemieux
Browse files

Ensure gradually increasing volume is immune to time jumps

Bug: 26115367
Change-Id: I3a4fda31fa797402d6edcf2f01b7240106bb8ab3
parent 30576572
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.telephony.TelephonyManager;
import android.text.format.DateUtils;
@@ -329,7 +330,7 @@ public final class AsyncRingtonePlayer {

                    // Compute the time at which the crescendo will stop.
                    mCrescendoDuration = getCrescendoDurationMillis(context);
                    mCrescendoStopTime = System.currentTimeMillis() + mCrescendoDuration;
                    mCrescendoStopTime = now() + mCrescendoDuration;
                    scheduleVolumeAdjustment = true;
                }

@@ -419,7 +420,7 @@ public final class AsyncRingtonePlayer {
            }

            // If the crescendo is complete set the volume to the maximum; we're done.
            final long currentTime = System.currentTimeMillis();
            final long currentTime = now();
            if (currentTime > mCrescendoStopTime) {
                mCrescendoDuration = 0;
                mCrescendoStopTime = 0;
@@ -536,7 +537,7 @@ public final class AsyncRingtonePlayer {

                // Compute the time at which the crescendo will stop.
                mCrescendoDuration = getCrescendoDurationMillis(context);
                mCrescendoStopTime = System.currentTimeMillis() + mCrescendoDuration;
                mCrescendoStopTime = now() + mCrescendoDuration;
                scheduleVolumeAdjustment = true;
            }

@@ -600,7 +601,7 @@ public final class AsyncRingtonePlayer {
            }

            // If the crescendo is complete set the volume to the maximum; we're done.
            final long currentTime = System.currentTimeMillis();
            final long currentTime = now();
            if (currentTime > mCrescendoStopTime) {
                mCrescendoDuration = 0;
                mCrescendoStopTime = 0;
@@ -615,5 +616,12 @@ public final class AsyncRingtonePlayer {
            return true;
        }
    }

    /**
     * @return the current elapsed time which is immune to device time changes
     */
    private static long now() {
        return SystemClock.elapsedRealtime();
    }
}