Merge "Do not extend timeout if not playing" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
ad26c28ca0
@@ -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