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

Commit 371804bb authored by Automerger Merge Worker's avatar Automerger Merge Worker Committed by Android (Google) Code Review
Browse files

Merge "Merge "Add trace for seekbar updates" into udc-dev am: 6d243ffc am: cbdbeab6"

parents e3895b97 821012da
Loading
Loading
Loading
Loading
+10 −1
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@ import android.media.MediaMetadata
import android.media.session.MediaController
import android.media.session.MediaController
import android.media.session.PlaybackState
import android.media.session.PlaybackState
import android.os.SystemClock
import android.os.SystemClock
import android.os.Trace
import android.view.GestureDetector
import android.view.GestureDetector
import android.view.MotionEvent
import android.view.MotionEvent
import android.view.View
import android.view.View
@@ -40,6 +41,8 @@ import javax.inject.Inject
private const val POSITION_UPDATE_INTERVAL_MILLIS = 100L
private const val POSITION_UPDATE_INTERVAL_MILLIS = 100L
private const val MIN_FLING_VELOCITY_SCALE_FACTOR = 10
private const val MIN_FLING_VELOCITY_SCALE_FACTOR = 10


private const val TRACE_POSITION_NAME = "SeekBarPollingPosition"

private fun PlaybackState.isInMotion(): Boolean {
private fun PlaybackState.isInMotion(): Boolean {
    return this.state == PlaybackState.STATE_PLAYING ||
    return this.state == PlaybackState.STATE_PLAYING ||
        this.state == PlaybackState.STATE_FAST_FORWARDING ||
        this.state == PlaybackState.STATE_FAST_FORWARDING ||
@@ -295,14 +298,20 @@ constructor(
    @WorkerThread
    @WorkerThread
    private fun checkIfPollingNeeded() {
    private fun checkIfPollingNeeded() {
        val needed = listening && !scrubbing && playbackState?.isInMotion() ?: false
        val needed = listening && !scrubbing && playbackState?.isInMotion() ?: false
        val traceCookie = controller?.sessionToken.hashCode()
        if (needed) {
        if (needed) {
            if (cancel == null) {
            if (cancel == null) {
                cancel =
                Trace.beginAsyncSection(TRACE_POSITION_NAME, traceCookie)
                val cancelPolling =
                    bgExecutor.executeRepeatedly(
                    bgExecutor.executeRepeatedly(
                        this::checkPlaybackPosition,
                        this::checkPlaybackPosition,
                        0L,
                        0L,
                        POSITION_UPDATE_INTERVAL_MILLIS
                        POSITION_UPDATE_INTERVAL_MILLIS
                    )
                    )
                cancel = Runnable {
                    cancelPolling.run()
                    Trace.endAsyncSection(TRACE_POSITION_NAME, traceCookie)
                }
            }
            }
        } else {
        } else {
            cancel?.run()
            cancel?.run()