Merge "Handle null media metadata" into rvc-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
4c438e2082
@@ -316,18 +316,13 @@ class MediaDataManager(
|
||||
as MediaSession.Token?
|
||||
val metadata = mediaControllerFactory.create(token).metadata
|
||||
|
||||
if (metadata == null) {
|
||||
// TODO: handle this better, removing media notification
|
||||
return
|
||||
}
|
||||
|
||||
// Foreground and Background colors computed from album art
|
||||
val notif: Notification = sbn.notification
|
||||
var artworkBitmap = metadata.getBitmap(MediaMetadata.METADATA_KEY_ART)
|
||||
var artworkBitmap = metadata?.getBitmap(MediaMetadata.METADATA_KEY_ART)
|
||||
if (artworkBitmap == null) {
|
||||
artworkBitmap = metadata.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART)
|
||||
artworkBitmap = metadata?.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART)
|
||||
}
|
||||
if (artworkBitmap == null) {
|
||||
if (artworkBitmap == null && metadata != null) {
|
||||
artworkBitmap = loadBitmapFromUri(metadata)
|
||||
}
|
||||
val artWorkIcon = if (artworkBitmap == null) {
|
||||
@@ -363,16 +358,16 @@ class MediaDataManager(
|
||||
val smallIconDrawable: Drawable = sbn.notification.smallIcon.loadDrawable(context)
|
||||
|
||||
// Song name
|
||||
var song: CharSequence? = metadata.getString(MediaMetadata.METADATA_KEY_DISPLAY_TITLE)
|
||||
var song: CharSequence? = metadata?.getString(MediaMetadata.METADATA_KEY_DISPLAY_TITLE)
|
||||
if (song == null) {
|
||||
song = metadata.getString(MediaMetadata.METADATA_KEY_TITLE)
|
||||
song = metadata?.getString(MediaMetadata.METADATA_KEY_TITLE)
|
||||
}
|
||||
if (song == null) {
|
||||
song = HybridGroupManager.resolveTitle(notif)
|
||||
}
|
||||
|
||||
// Artist name
|
||||
var artist: CharSequence? = metadata.getString(MediaMetadata.METADATA_KEY_ARTIST)
|
||||
var artist: CharSequence? = metadata?.getString(MediaMetadata.METADATA_KEY_ARTIST)
|
||||
if (artist == null) {
|
||||
artist = HybridGroupManager.resolveText(notif)
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ private fun PlaybackState.computePosition(duration: Long): Long {
|
||||
|
||||
/** ViewModel for seek bar in QS media player. */
|
||||
class SeekBarViewModel @Inject constructor(@Background private val bgExecutor: RepeatableExecutor) {
|
||||
private var _data = Progress(false, false, null, null)
|
||||
private var _data = Progress(false, false, null, 0)
|
||||
set(value) {
|
||||
field = value
|
||||
_progress.postValue(value)
|
||||
@@ -186,10 +186,10 @@ class SeekBarViewModel @Inject constructor(@Background private val bgExecutor: R
|
||||
val mediaMetadata = controller?.metadata
|
||||
val seekAvailable = ((playbackState?.actions ?: 0L) and PlaybackState.ACTION_SEEK_TO) != 0L
|
||||
val position = playbackState?.position?.toInt()
|
||||
val duration = mediaMetadata?.getLong(MediaMetadata.METADATA_KEY_DURATION)?.toInt()
|
||||
val duration = mediaMetadata?.getLong(MediaMetadata.METADATA_KEY_DURATION)?.toInt() ?: 0
|
||||
val enabled = if (playbackState == null ||
|
||||
playbackState?.getState() == PlaybackState.STATE_NONE ||
|
||||
(duration != null && duration <= 0)) false else true
|
||||
(duration <= 0)) false else true
|
||||
_data = Progress(enabled, seekAvailable, position, duration)
|
||||
checkIfPollingNeeded()
|
||||
}
|
||||
@@ -408,6 +408,6 @@ class SeekBarViewModel @Inject constructor(@Background private val bgExecutor: R
|
||||
val enabled: Boolean,
|
||||
val seekAvailable: Boolean,
|
||||
val elapsedTime: Int?,
|
||||
val duration: Int?
|
||||
val duration: Int
|
||||
)
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class SeekBarObserverTest : SysuiTestCase() {
|
||||
fun seekBarGone() {
|
||||
// WHEN seek bar is disabled
|
||||
val isEnabled = false
|
||||
val data = SeekBarViewModel.Progress(isEnabled, false, null, null)
|
||||
val data = SeekBarViewModel.Progress(isEnabled, false, null, 0)
|
||||
observer.onChanged(data)
|
||||
// THEN seek bar shows just a thin line with no text
|
||||
assertThat(seekBarView.isEnabled()).isFalse()
|
||||
|
||||
@@ -203,6 +203,22 @@ public class SeekBarViewModelTest : SysuiTestCase() {
|
||||
assertThat(viewModel.progress.value!!.enabled).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun updateDurationNoMetadata() {
|
||||
// GIVEN that the metadata is null
|
||||
whenever(mockController.getMetadata()).thenReturn(null)
|
||||
// AND a valid playback state (ie. media session is not destroyed)
|
||||
val state = PlaybackState.Builder().run {
|
||||
setState(PlaybackState.STATE_PLAYING, 200L, 1f)
|
||||
build()
|
||||
}
|
||||
whenever(mockController.getPlaybackState()).thenReturn(state)
|
||||
// WHEN the controller is updated
|
||||
viewModel.updateController(mockController)
|
||||
// THEN the seek bar is disabled
|
||||
assertThat(viewModel.progress.value!!.enabled).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun updateElapsedTime() {
|
||||
// GIVEN that the PlaybackState contains the current position
|
||||
|
||||
Reference in New Issue
Block a user