Merge "Add play/pause button when state has ACTION_PLAY_PAUSE" into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
767d362b56
@@ -843,18 +843,23 @@ class MediaDataManager(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a [MediaAction] representing one of
|
* Create a [MediaAction] for a given action and media session
|
||||||
* - [PlaybackState.ACTION_PLAY]
|
*
|
||||||
* - [PlaybackState.ACTION_PAUSE]
|
* @param controller MediaController for the session
|
||||||
* - [PlaybackState.ACTION_SKIP_TO_PREVIOUS]
|
* @param stateActions The actions included with the session's [PlaybackState]
|
||||||
* - [PlaybackState.ACTION_SKIP_TO_NEXT]
|
* @param action A [PlaybackState.Actions] value representing what action to generate. One of:
|
||||||
|
* [PlaybackState.ACTION_PLAY]
|
||||||
|
* [PlaybackState.ACTION_PAUSE]
|
||||||
|
* [PlaybackState.ACTION_SKIP_TO_PREVIOUS]
|
||||||
|
* [PlaybackState.ACTION_SKIP_TO_NEXT]
|
||||||
|
* @return A [MediaAction] with correct values set, or null if the state doesn't support it
|
||||||
*/
|
*/
|
||||||
private fun getStandardAction(
|
private fun getStandardAction(
|
||||||
controller: MediaController,
|
controller: MediaController,
|
||||||
stateActions: Long,
|
stateActions: Long,
|
||||||
action: Long
|
@PlaybackState.Actions action: Long
|
||||||
): MediaAction? {
|
): MediaAction? {
|
||||||
if (stateActions and action == 0L) {
|
if (!includesAction(stateActions, action)) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -895,6 +900,17 @@ class MediaDataManager(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the actions from a [PlaybackState] include a specific action
|
||||||
|
*/
|
||||||
|
private fun includesAction(stateActions: Long, @PlaybackState.Actions action: Long): Boolean {
|
||||||
|
if ((action == PlaybackState.ACTION_PLAY || action == PlaybackState.ACTION_PAUSE) &&
|
||||||
|
(stateActions and PlaybackState.ACTION_PLAY_PAUSE > 0L)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return (stateActions and action != 0L)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a [MediaAction] representing a [PlaybackState.CustomAction]
|
* Get a [MediaAction] representing a [PlaybackState.CustomAction]
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -780,6 +780,25 @@ class MediaDataManagerTest : SysuiTestCase() {
|
|||||||
assertThat(actions.custom1!!.contentDescription).isEqualTo(customDesc[1])
|
assertThat(actions.custom1!!.contentDescription).isEqualTo(customDesc[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testPlaybackActions_playPause_hasButton() {
|
||||||
|
whenever(mediaFlags.areMediaSessionActionsEnabled(any(), any())).thenReturn(true)
|
||||||
|
val stateActions = PlaybackState.ACTION_PLAY_PAUSE
|
||||||
|
val stateBuilder = PlaybackState.Builder().setActions(stateActions)
|
||||||
|
whenever(controller.playbackState).thenReturn(stateBuilder.build())
|
||||||
|
|
||||||
|
addNotificationAndLoad()
|
||||||
|
|
||||||
|
assertThat(mediaDataCaptor.value!!.semanticActions).isNotNull()
|
||||||
|
val actions = mediaDataCaptor.value!!.semanticActions!!
|
||||||
|
|
||||||
|
assertThat(actions.playOrPause).isNotNull()
|
||||||
|
assertThat(actions.playOrPause!!.contentDescription).isEqualTo(
|
||||||
|
context.getString(R.string.controls_media_button_play))
|
||||||
|
actions.playOrPause!!.action!!.run()
|
||||||
|
verify(transportControls).play()
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testPlaybackLocationChange_isLogged() {
|
fun testPlaybackLocationChange_isLogged() {
|
||||||
// Media control added for local playback
|
// Media control added for local playback
|
||||||
|
|||||||
Reference in New Issue
Block a user