Loading packages/SystemUI/src/com/android/systemui/media/MediaDeviceManager.kt +10 −14 Original line number Diff line number Diff line Loading @@ -109,11 +109,9 @@ class MediaDeviceManager @Inject constructor( } @MainThread private fun processDevice(key: String, oldKey: String?, device: MediaDevice?) { val enabled = device != null val data = MediaDeviceData(enabled, device?.iconWithoutBackground, device?.name) private fun processDevice(key: String, oldKey: String?, device: MediaDeviceData?) { listeners.forEach { it.onMediaDeviceChanged(key, oldKey, data) it.onMediaDeviceChanged(key, oldKey, device) } } Loading @@ -135,7 +133,7 @@ class MediaDeviceManager @Inject constructor( get() = controller?.sessionToken private var started = false private var playbackType = PLAYBACK_TYPE_UNKNOWN private var current: MediaDevice? = null private var current: MediaDeviceData? = null set(value) { if (!started || value != field) { field = value Loading Loading @@ -201,15 +199,13 @@ class MediaDeviceManager @Inject constructor( @WorkerThread private fun updateCurrent() { val device = localMediaManager.getCurrentConnectedDevice() controller?.let { val route = mr2manager.getRoutingSessionForMediaController(it) // If we get a null route, then don't trust the device. Just set to null to disable the // output switcher chip. current = if (route != null) device else null } ?: run { current = device } val device = localMediaManager.currentConnectedDevice val route = controller?.let { mr2manager.getRoutingSessionForMediaController(it)} // If we have a controller but get a null route, then don't trust the device val enabled = device != null && (controller == null || route != null) val name = route?.name?.toString() ?: device?.name current = MediaDeviceData(enabled, device?.iconWithoutBackground, name) } } } packages/SystemUI/tests/src/com/android/systemui/media/MediaControlPanelTest.kt +1 −1 Original line number Diff line number Diff line Loading @@ -122,7 +122,7 @@ public class MediaControlPanelTest : SysuiTestCase() { private lateinit var session: MediaSession private val device = MediaDeviceData(true, null, DEVICE_NAME) private val disabledDevice = MediaDeviceData(false, null, null) private val disabledDevice = MediaDeviceData(false, null, "Disabled Device") @JvmField @Rule val mockito = MockitoJUnit.rule() Loading packages/SystemUI/tests/src/com/android/systemui/media/MediaDeviceManagerTest.kt +15 −8 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ private const val PACKAGE = "PKG" private const val SESSION_KEY = "SESSION_KEY" private const val SESSION_TITLE = "SESSION_TITLE" private const val DEVICE_NAME = "DEVICE_NAME" private const val REMOTE_DEVICE_NAME = "REMOTE_DEVICE_NAME" private const val USER_ID = 0 private fun <T> eq(value: T): T = Mockito.eq(value) ?: value Loading Loading @@ -195,8 +196,6 @@ public class MediaDeviceManagerTest : SysuiTestCase() { // THEN the device should be disabled val data = captureDeviceData(KEY) assertThat(data.enabled).isFalse() assertThat(data.name).isNull() assertThat(data.icon).isNull() } @Test Loading Loading @@ -262,6 +261,20 @@ public class MediaDeviceManagerTest : SysuiTestCase() { verify(listener).onKeyRemoved(eq(KEY)) } @Test fun deviceNameFromMR2RouteInfo() { // GIVEN that MR2Manager returns a valid routing session whenever(route.name).thenReturn(REMOTE_DEVICE_NAME) // WHEN a notification is added manager.onMediaDataLoaded(KEY, null, mediaData) fakeBgExecutor.runAllReady() fakeFgExecutor.runAllReady() // THEN it uses the route name (instead of device name) val data = captureDeviceData(KEY) assertThat(data.enabled).isTrue() assertThat(data.name).isEqualTo(REMOTE_DEVICE_NAME) } @Test fun deviceDisabledWhenMR2ReturnsNullRouteInfo() { // GIVEN that MR2Manager returns null for routing session Loading @@ -273,8 +286,6 @@ public class MediaDeviceManagerTest : SysuiTestCase() { // THEN the device is disabled val data = captureDeviceData(KEY) assertThat(data.enabled).isFalse() assertThat(data.name).isNull() assertThat(data.icon).isNull() } @Test Loading @@ -294,8 +305,6 @@ public class MediaDeviceManagerTest : SysuiTestCase() { // THEN the device is disabled val data = captureDeviceData(KEY) assertThat(data.enabled).isFalse() assertThat(data.name).isNull() assertThat(data.icon).isNull() } @Test Loading @@ -315,8 +324,6 @@ public class MediaDeviceManagerTest : SysuiTestCase() { // THEN the device is disabled val data = captureDeviceData(KEY) assertThat(data.enabled).isFalse() assertThat(data.name).isNull() assertThat(data.icon).isNull() } @Test Loading Loading
packages/SystemUI/src/com/android/systemui/media/MediaDeviceManager.kt +10 −14 Original line number Diff line number Diff line Loading @@ -109,11 +109,9 @@ class MediaDeviceManager @Inject constructor( } @MainThread private fun processDevice(key: String, oldKey: String?, device: MediaDevice?) { val enabled = device != null val data = MediaDeviceData(enabled, device?.iconWithoutBackground, device?.name) private fun processDevice(key: String, oldKey: String?, device: MediaDeviceData?) { listeners.forEach { it.onMediaDeviceChanged(key, oldKey, data) it.onMediaDeviceChanged(key, oldKey, device) } } Loading @@ -135,7 +133,7 @@ class MediaDeviceManager @Inject constructor( get() = controller?.sessionToken private var started = false private var playbackType = PLAYBACK_TYPE_UNKNOWN private var current: MediaDevice? = null private var current: MediaDeviceData? = null set(value) { if (!started || value != field) { field = value Loading Loading @@ -201,15 +199,13 @@ class MediaDeviceManager @Inject constructor( @WorkerThread private fun updateCurrent() { val device = localMediaManager.getCurrentConnectedDevice() controller?.let { val route = mr2manager.getRoutingSessionForMediaController(it) // If we get a null route, then don't trust the device. Just set to null to disable the // output switcher chip. current = if (route != null) device else null } ?: run { current = device } val device = localMediaManager.currentConnectedDevice val route = controller?.let { mr2manager.getRoutingSessionForMediaController(it)} // If we have a controller but get a null route, then don't trust the device val enabled = device != null && (controller == null || route != null) val name = route?.name?.toString() ?: device?.name current = MediaDeviceData(enabled, device?.iconWithoutBackground, name) } } }
packages/SystemUI/tests/src/com/android/systemui/media/MediaControlPanelTest.kt +1 −1 Original line number Diff line number Diff line Loading @@ -122,7 +122,7 @@ public class MediaControlPanelTest : SysuiTestCase() { private lateinit var session: MediaSession private val device = MediaDeviceData(true, null, DEVICE_NAME) private val disabledDevice = MediaDeviceData(false, null, null) private val disabledDevice = MediaDeviceData(false, null, "Disabled Device") @JvmField @Rule val mockito = MockitoJUnit.rule() Loading
packages/SystemUI/tests/src/com/android/systemui/media/MediaDeviceManagerTest.kt +15 −8 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ private const val PACKAGE = "PKG" private const val SESSION_KEY = "SESSION_KEY" private const val SESSION_TITLE = "SESSION_TITLE" private const val DEVICE_NAME = "DEVICE_NAME" private const val REMOTE_DEVICE_NAME = "REMOTE_DEVICE_NAME" private const val USER_ID = 0 private fun <T> eq(value: T): T = Mockito.eq(value) ?: value Loading Loading @@ -195,8 +196,6 @@ public class MediaDeviceManagerTest : SysuiTestCase() { // THEN the device should be disabled val data = captureDeviceData(KEY) assertThat(data.enabled).isFalse() assertThat(data.name).isNull() assertThat(data.icon).isNull() } @Test Loading Loading @@ -262,6 +261,20 @@ public class MediaDeviceManagerTest : SysuiTestCase() { verify(listener).onKeyRemoved(eq(KEY)) } @Test fun deviceNameFromMR2RouteInfo() { // GIVEN that MR2Manager returns a valid routing session whenever(route.name).thenReturn(REMOTE_DEVICE_NAME) // WHEN a notification is added manager.onMediaDataLoaded(KEY, null, mediaData) fakeBgExecutor.runAllReady() fakeFgExecutor.runAllReady() // THEN it uses the route name (instead of device name) val data = captureDeviceData(KEY) assertThat(data.enabled).isTrue() assertThat(data.name).isEqualTo(REMOTE_DEVICE_NAME) } @Test fun deviceDisabledWhenMR2ReturnsNullRouteInfo() { // GIVEN that MR2Manager returns null for routing session Loading @@ -273,8 +286,6 @@ public class MediaDeviceManagerTest : SysuiTestCase() { // THEN the device is disabled val data = captureDeviceData(KEY) assertThat(data.enabled).isFalse() assertThat(data.name).isNull() assertThat(data.icon).isNull() } @Test Loading @@ -294,8 +305,6 @@ public class MediaDeviceManagerTest : SysuiTestCase() { // THEN the device is disabled val data = captureDeviceData(KEY) assertThat(data.enabled).isFalse() assertThat(data.name).isNull() assertThat(data.icon).isNull() } @Test Loading @@ -315,8 +324,6 @@ public class MediaDeviceManagerTest : SysuiTestCase() { // THEN the device is disabled val data = captureDeviceData(KEY) assertThat(data.enabled).isFalse() assertThat(data.name).isNull() assertThat(data.icon).isNull() } @Test Loading