From be0adabd7a775be7071f862816139360688506a3 Mon Sep 17 00:00:00 2001 From: Justin Weir Date: Mon, 23 May 2022 17:24:29 -0400 Subject: [PATCH] Add a unique ID to MediaDeviceData Both InfoMediaDevice and PhoneMediaDevice implement getIcon by calling mContext.getDrawable and do not cache the result. Each time, they appear to supply a fresh icon object inside MediaDeviceManager.updateCurrent, causing it to always update the field MediaDeviceManager.current in its setter. This resulted in a lot of unnecessary work being sent to the fgExecutor on every volume change event, causing jank in the volume dialog. Adding each device's unique ID to the media data and not setting the field on ID matches eliminates the unnecessary calls. Fixes: 225624315 Test: Manually tested and verified lack of dropped frames in Perfetto Change-Id: I5d8fdcdf18c30a87274a8bf07e3f6a07afd650e1 --- .../SystemUI/src/com/android/systemui/media/MediaData.kt | 5 ++++- .../src/com/android/systemui/media/MediaDeviceManager.kt | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaData.kt b/packages/SystemUI/src/com/android/systemui/media/MediaData.kt index d04ec40c9f28e..360f86548e13e 100644 --- a/packages/SystemUI/src/com/android/systemui/media/MediaData.kt +++ b/packages/SystemUI/src/com/android/systemui/media/MediaData.kt @@ -212,5 +212,8 @@ data class MediaDeviceData val name: CharSequence?, /** Optional intent to override the default output switcher for this control */ - val intent: PendingIntent? = null + val intent: PendingIntent? = null, + + /** Unique id for this device */ + val id: String? = null ) diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaDeviceManager.kt b/packages/SystemUI/src/com/android/systemui/media/MediaDeviceManager.kt index 11ee6578e27d9..8558859638d5b 100644 --- a/packages/SystemUI/src/com/android/systemui/media/MediaDeviceManager.kt +++ b/packages/SystemUI/src/com/android/systemui/media/MediaDeviceManager.kt @@ -155,7 +155,8 @@ class MediaDeviceManager @Inject constructor( private var playbackType = PLAYBACK_TYPE_UNKNOWN private var current: MediaDeviceData? = null set(value) { - if (!started || value != field) { + val hasSameId = value?.id != null && value.id == field?.id + if (!started || (!hasSameId && value != field)) { field = value fgExecutor.execute { processDevice(key, oldKey, value) @@ -263,7 +264,7 @@ class MediaDeviceManager @Inject constructor( // 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) + current = MediaDeviceData(enabled, device?.iconWithoutBackground, name, id = device?.id) } } }