Do not extend timeout if not playing
Before, we'd always extend the timeout upon media state updates, this means that going from STOPPED to PAUSED would reset the timeout. This is not desirable. Test: atest MediaTimeoutListenerTest Bug: 157587326 Change-Id: Ie06904c90561e6c2bd23c0c7f4df76c2b597d899
This commit is contained in:
@@ -87,12 +87,15 @@ class MediaTimeoutListener @Inject constructor(
|
||||
if (DEBUG) {
|
||||
Log.v(TAG, "onPlaybackStateChanged: $state")
|
||||
}
|
||||
expireMediaTimeout(key, "playback state ativity - $state, $key")
|
||||
|
||||
if (state == null || !isPlayingState(state.state)) {
|
||||
if (DEBUG) {
|
||||
Log.v(TAG, "schedule timeout for $key")
|
||||
}
|
||||
if (cancellation != null) {
|
||||
if (DEBUG) Log.d(TAG, "cancellation already exists, continuing.")
|
||||
return
|
||||
}
|
||||
expireMediaTimeout(key, "PLAYBACK STATE CHANGED - $state")
|
||||
cancellation = mainExecutor.executeDelayed({
|
||||
cancellation = null
|
||||
@@ -103,6 +106,7 @@ class MediaTimeoutListener @Inject constructor(
|
||||
timeoutCallback(key, timedOut)
|
||||
}, PAUSED_MEDIA_TIMEOUT)
|
||||
} else {
|
||||
expireMediaTimeout(key, "playback started - $state, $key")
|
||||
timedOut = false
|
||||
timeoutCallback(key, timedOut)
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ class MediaTimeoutListenerTest : SysuiTestCase() {
|
||||
|
||||
@Test
|
||||
fun testOnPlaybackStateChanged_cancelsTimeout_whenResumed() {
|
||||
// Assuming we're have a pending timeout
|
||||
// Assuming we have a pending timeout
|
||||
testOnPlaybackStateChanged_schedulesTimeout_whenPaused()
|
||||
|
||||
mediaCallbackCaptor.value.onPlaybackStateChanged(PlaybackState.Builder()
|
||||
@@ -139,6 +139,17 @@ class MediaTimeoutListenerTest : SysuiTestCase() {
|
||||
verify(cancellationRunnable).run()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnPlaybackStateChanged_reusesTimeout_whenNotPlaying() {
|
||||
// Assuming we have a pending timeout
|
||||
testOnPlaybackStateChanged_schedulesTimeout_whenPaused()
|
||||
|
||||
clearInvocations(cancellationRunnable)
|
||||
mediaCallbackCaptor.value.onPlaybackStateChanged(PlaybackState.Builder()
|
||||
.setState(PlaybackState.STATE_STOPPED, 0L, 0f).build())
|
||||
verify(cancellationRunnable, never()).run()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testTimeoutCallback_invokedIfTimeout() {
|
||||
// Assuming we're have a pending timeout
|
||||
|
||||
Reference in New Issue
Block a user