Handle possible null PlaybackState
Fixes: 170706598
Test: atest SeekBarViewModelTest
Change-Id: I78428dd2d48658878957a7b58948a73d3f6bfaad
(cherry picked from commit f06e4ffffe)
This commit is contained in:
@@ -91,9 +91,9 @@ class SeekBarViewModel @Inject constructor(@Background private val bgExecutor: R
|
|||||||
}
|
}
|
||||||
private var playbackState: PlaybackState? = null
|
private var playbackState: PlaybackState? = null
|
||||||
private var callback = object : MediaController.Callback() {
|
private var callback = object : MediaController.Callback() {
|
||||||
override fun onPlaybackStateChanged(state: PlaybackState) {
|
override fun onPlaybackStateChanged(state: PlaybackState?) {
|
||||||
playbackState = state
|
playbackState = state
|
||||||
if (PlaybackState.STATE_NONE.equals(playbackState)) {
|
if (playbackState == null || PlaybackState.STATE_NONE.equals(playbackState)) {
|
||||||
clearController()
|
clearController()
|
||||||
} else {
|
} else {
|
||||||
checkIfPollingNeeded()
|
checkIfPollingNeeded()
|
||||||
|
|||||||
@@ -654,4 +654,21 @@ public class SeekBarViewModelTest : SysuiTestCase() {
|
|||||||
fakeExecutor.runAllReady()
|
fakeExecutor.runAllReady()
|
||||||
verify(mockController).unregisterCallback(any())
|
verify(mockController).unregisterCallback(any())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun nullPlaybackStateUnregistersCallback() {
|
||||||
|
viewModel.updateController(mockController)
|
||||||
|
val captor = ArgumentCaptor.forClass(MediaController.Callback::class.java)
|
||||||
|
verify(mockController).registerCallback(captor.capture())
|
||||||
|
val callback = captor.value
|
||||||
|
// WHEN the callback receives a null state
|
||||||
|
callback.onPlaybackStateChanged(null)
|
||||||
|
with(fakeExecutor) {
|
||||||
|
advanceClockToNext()
|
||||||
|
runAllReady()
|
||||||
|
}
|
||||||
|
// THEN we unregister callback (as a result of clearing the controller)
|
||||||
|
fakeExecutor.runAllReady()
|
||||||
|
verify(mockController).unregisterCallback(any())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user