summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Lucas Dupin <dupin@google.com> 2020-06-04 18:22:36 -0700
committer Lucas Dupin <dupin@google.com> 2020-06-04 18:22:36 -0700
commit6c4a1d00c7e98e381104bd3bdf026afa12eb4dbc (patch)
tree4713b6b919e48451aa51443d67ae0abb661e2521
parentcf7f7ca76217cdb803c2ad23a4176fca65ff64cd (diff)
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
-rw-r--r--packages/SystemUI/src/com/android/systemui/media/MediaTimeoutListener.kt6
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/media/MediaTimeoutListenerTest.kt13
2 files changed, 17 insertions, 2 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaTimeoutListener.kt b/packages/SystemUI/src/com/android/systemui/media/MediaTimeoutListener.kt
index 359c2f5e297c..3c3f4a977ee7 100644
--- a/packages/SystemUI/src/com/android/systemui/media/MediaTimeoutListener.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/MediaTimeoutListener.kt
@@ -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)
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/MediaTimeoutListenerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/MediaTimeoutListenerTest.kt
index 643a3352c30c..7d44327b0d38 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/media/MediaTimeoutListenerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/media/MediaTimeoutListenerTest.kt
@@ -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()
@@ -140,6 +140,17 @@ class MediaTimeoutListenerTest : SysuiTestCase() {
}
@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
testOnPlaybackStateChanged_schedulesTimeout_whenPaused()