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) {
|
if (DEBUG) {
|
||||||
Log.v(TAG, "onPlaybackStateChanged: $state")
|
Log.v(TAG, "onPlaybackStateChanged: $state")
|
||||||
}
|
}
|
||||||
expireMediaTimeout(key, "playback state ativity - $state, $key")
|
|
||||||
|
|
||||||
if (state == null || !isPlayingState(state.state)) {
|
if (state == null || !isPlayingState(state.state)) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.v(TAG, "schedule timeout for $key")
|
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")
|
expireMediaTimeout(key, "PLAYBACK STATE CHANGED - $state")
|
||||||
cancellation = mainExecutor.executeDelayed({
|
cancellation = mainExecutor.executeDelayed({
|
||||||
cancellation = null
|
cancellation = null
|
||||||
@@ -103,6 +106,7 @@ class MediaTimeoutListener @Inject constructor(
|
|||||||
timeoutCallback(key, timedOut)
|
timeoutCallback(key, timedOut)
|
||||||
}, PAUSED_MEDIA_TIMEOUT)
|
}, PAUSED_MEDIA_TIMEOUT)
|
||||||
} else {
|
} else {
|
||||||
|
expireMediaTimeout(key, "playback started - $state, $key")
|
||||||
timedOut = false
|
timedOut = false
|
||||||
timeoutCallback(key, timedOut)
|
timeoutCallback(key, timedOut)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ class MediaTimeoutListenerTest : SysuiTestCase() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testOnPlaybackStateChanged_cancelsTimeout_whenResumed() {
|
fun testOnPlaybackStateChanged_cancelsTimeout_whenResumed() {
|
||||||
// Assuming we're have a pending timeout
|
// Assuming we have a pending timeout
|
||||||
testOnPlaybackStateChanged_schedulesTimeout_whenPaused()
|
testOnPlaybackStateChanged_schedulesTimeout_whenPaused()
|
||||||
|
|
||||||
mediaCallbackCaptor.value.onPlaybackStateChanged(PlaybackState.Builder()
|
mediaCallbackCaptor.value.onPlaybackStateChanged(PlaybackState.Builder()
|
||||||
@@ -139,6 +139,17 @@ class MediaTimeoutListenerTest : SysuiTestCase() {
|
|||||||
verify(cancellationRunnable).run()
|
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
|
@Test
|
||||||
fun testTimeoutCallback_invokedIfTimeout() {
|
fun testTimeoutCallback_invokedIfTimeout() {
|
||||||
// Assuming we're have a pending timeout
|
// Assuming we're have a pending timeout
|
||||||
|
|||||||
Reference in New Issue
Block a user