-
Notifications
You must be signed in to change notification settings - Fork 306
Treat KEYCODE_MEDIA_PLAY as play-only to stop repeated Android Auto pauses #5535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
joashrajin
wants to merge
5
commits into
main
from
pcdroid-516-wireless-android-auto-repeatedly-pauses-when-bluetooth-is
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ca5057e
Treat KEYCODE_MEDIA_PLAY as play-only to stop redundant head unit pauses
joashrajin dbdc25e
Update CHANGELOG
joashrajin 13a6806
Extract PlaybackManager.playIfNotPlaying for play-only media key hand…
joashrajin e5a237a
Update changelog for 8.18
joashrajin 3cc6cc5
Merge remote-tracking branch 'origin/main' into pcdroid-516-wireless-…
joashrajin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
.../com/shiftyjelly/pocketcasts/repositories/playback/PlaybackManagerPlayIfNotPlayingTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package au.com.shiftyjelly.pocketcasts.repositories.playback | ||
|
|
||
| import au.com.shiftyjelly.pocketcasts.analytics.SourceView | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import org.mockito.kotlin.any | ||
| import org.mockito.kotlin.eq | ||
| import org.mockito.kotlin.mock | ||
| import org.mockito.kotlin.never | ||
| import org.mockito.kotlin.verify | ||
| import org.mockito.kotlin.whenever | ||
| import org.robolectric.RobolectricTestRunner | ||
|
|
||
| @RunWith(RobolectricTestRunner::class) | ||
| class PlaybackManagerPlayIfNotPlayingTest { | ||
|
|
||
| private val playbackManager = mock<PlaybackManager>().also { | ||
| whenever(it.playIfNotPlaying(any())).thenCallRealMethod() | ||
| } | ||
|
|
||
| @Test | ||
| fun `does nothing while already playing`() { | ||
| whenever(playbackManager.isPlaying()).thenReturn(true) | ||
|
|
||
| playbackManager.playIfNotPlaying(sourceView = SourceView.MEDIA_BUTTON_BROADCAST_ACTION) | ||
|
|
||
| verify(playbackManager, never()).playQueue(any(), any()) | ||
| verify(playbackManager, never()).pause(any(), any()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `plays the queue while not playing`() { | ||
| whenever(playbackManager.isPlaying()).thenReturn(false) | ||
|
|
||
| playbackManager.playIfNotPlaying(sourceView = SourceView.MEDIA_BUTTON_BROADCAST_ACTION) | ||
|
|
||
| verify(playbackManager).playQueue(eq(SourceView.MEDIA_BUTTON_BROADCAST_ACTION), any()) | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This guard is identical to the one just added in
Media3SessionCallback.handleMediaButtonSingleTap(comment,isPlaying()check, log line, early return). Since the two callbacks must stay behaviourally in lockstep for play-only semantics, consider hoisting this into a single shared helper — e.g. an extension onPlaybackManager:Then both single-tap handlers become
if (playOnly) playbackManager.playIfNotPlaying(source) else playbackManager.playPause(source). This also removes the doubleisPlaying()read (guard +playPause()) and the tiny TOCTOU window between them. Non-blocking — the current duplication is correct, just drift-prone.