Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 10206461 authored by Michael Mikhail's avatar Michael Mikhail
Browse files

Use new flag for drawables reuse

Flag: com.android.systemui.media_controls_drawables_reuse_bugfix
Bug: 358402034
Test: build.
Change-Id: Ia1d38426cc532141a5ee4ff8cd56774668641f3e
parent 5b25a727
Loading
Loading
Loading
Loading
+4 −1
Original line number Original line Diff line number Diff line
@@ -1325,10 +1325,13 @@ flag {
}
}


flag {
flag {
  name: "media_controls_drawables_reuse"
  name: "media_controls_drawables_reuse_bugfix"
  namespace: "systemui"
  namespace: "systemui"
  description: "Re-use created media drawables for media controls"
  description: "Re-use created media drawables for media controls"
  bug: "358402034"
  bug: "358402034"
  metadata {
    purpose: PURPOSE_BUGFIX
  }
}
}


flag {
flag {
+7 −7
Original line number Original line Diff line number Diff line
@@ -18,7 +18,7 @@ package com.android.systemui.media.controls.shared


import android.content.Context
import android.content.Context
import android.graphics.drawable.Drawable
import android.graphics.drawable.Drawable
import com.android.systemui.Flags.mediaControlsDrawablesReuse
import com.android.systemui.Flags.mediaControlsDrawablesReuseBugfix
import com.android.systemui.res.R
import com.android.systemui.res.R


object MediaControlDrawables {
object MediaControlDrawables {
@@ -34,21 +34,21 @@ object MediaControlDrawables {
    private var homeDevices: Drawable? = null
    private var homeDevices: Drawable? = null


    fun getNextIcon(context: Context): Drawable? {
    fun getNextIcon(context: Context): Drawable? {
        if (!mediaControlsDrawablesReuse()) {
        if (!mediaControlsDrawablesReuseBugfix()) {
            return context.getDrawable(R.drawable.ic_media_next)
            return context.getDrawable(R.drawable.ic_media_next)
        }
        }
        return nextIcon ?: context.getDrawable(R.drawable.ic_media_next).also { nextIcon = it }
        return nextIcon ?: context.getDrawable(R.drawable.ic_media_next).also { nextIcon = it }
    }
    }


    fun getPrevIcon(context: Context): Drawable? {
    fun getPrevIcon(context: Context): Drawable? {
        if (!mediaControlsDrawablesReuse()) {
        if (!mediaControlsDrawablesReuseBugfix()) {
            return context.getDrawable(R.drawable.ic_media_prev)
            return context.getDrawable(R.drawable.ic_media_prev)
        }
        }
        return prevIcon ?: context.getDrawable(R.drawable.ic_media_prev).also { prevIcon = it }
        return prevIcon ?: context.getDrawable(R.drawable.ic_media_prev).also { prevIcon = it }
    }
    }


    fun getLeAudioSharing(context: Context): Drawable? {
    fun getLeAudioSharing(context: Context): Drawable? {
        if (!mediaControlsDrawablesReuse()) {
        if (!mediaControlsDrawablesReuseBugfix()) {
            return context.getDrawable(com.android.settingslib.R.drawable.ic_bt_le_audio_sharing)
            return context.getDrawable(com.android.settingslib.R.drawable.ic_bt_le_audio_sharing)
        }
        }
        return leAudioSharing
        return leAudioSharing
@@ -58,7 +58,7 @@ object MediaControlDrawables {
    }
    }


    fun getAntenna(context: Context): Drawable? {
    fun getAntenna(context: Context): Drawable? {
        if (!mediaControlsDrawablesReuse()) {
        if (!mediaControlsDrawablesReuseBugfix()) {
            return context.getDrawable(R.drawable.settings_input_antenna)
            return context.getDrawable(R.drawable.settings_input_antenna)
        }
        }
        return antenna
        return antenna
@@ -66,7 +66,7 @@ object MediaControlDrawables {
    }
    }


    fun getGroupDevice(context: Context): Drawable? {
    fun getGroupDevice(context: Context): Drawable? {
        if (!mediaControlsDrawablesReuse()) {
        if (!mediaControlsDrawablesReuseBugfix()) {
            return context.getDrawable(com.android.settingslib.R.drawable.ic_media_group_device)
            return context.getDrawable(com.android.settingslib.R.drawable.ic_media_group_device)
        }
        }
        return groupDevice
        return groupDevice
@@ -76,7 +76,7 @@ object MediaControlDrawables {
    }
    }


    fun getHomeDevices(context: Context): Drawable? {
    fun getHomeDevices(context: Context): Drawable? {
        if (!mediaControlsDrawablesReuse()) {
        if (!mediaControlsDrawablesReuseBugfix()) {
            return context.getDrawable(R.drawable.ic_media_home_devices)
            return context.getDrawable(R.drawable.ic_media_home_devices)
        }
        }
        return homeDevices
        return homeDevices
+2 −2
Original line number Original line Diff line number Diff line
@@ -1524,7 +1524,7 @@ class MediaDataProcessorTest(flags: FlagsParameterization) : SysuiTestCase() {
    }
    }


    @Test
    @Test
    @EnableFlags(Flags.FLAG_MEDIA_CONTROLS_DRAWABLES_REUSE)
    @EnableFlags(Flags.FLAG_MEDIA_CONTROLS_DRAWABLES_REUSE_BUGFIX)
    fun postWithPlaybackActions_drawablesReused() {
    fun postWithPlaybackActions_drawablesReused() {
        whenever(notificationLockscreenUserManager.isCurrentProfile(USER_ID)).thenReturn(true)
        whenever(notificationLockscreenUserManager.isCurrentProfile(USER_ID)).thenReturn(true)
        whenever(notificationLockscreenUserManager.isProfileAvailable(USER_ID)).thenReturn(true)
        whenever(notificationLockscreenUserManager.isProfileAvailable(USER_ID)).thenReturn(true)
@@ -1557,7 +1557,7 @@ class MediaDataProcessorTest(flags: FlagsParameterization) : SysuiTestCase() {
    }
    }


    @Test
    @Test
    @DisableFlags(Flags.FLAG_MEDIA_CONTROLS_DRAWABLES_REUSE)
    @DisableFlags(Flags.FLAG_MEDIA_CONTROLS_DRAWABLES_REUSE_BUGFIX)
    fun postWithPlaybackActions_drawablesNotReused() {
    fun postWithPlaybackActions_drawablesNotReused() {
        whenever(notificationLockscreenUserManager.isCurrentProfile(USER_ID)).thenReturn(true)
        whenever(notificationLockscreenUserManager.isCurrentProfile(USER_ID)).thenReturn(true)
        whenever(notificationLockscreenUserManager.isProfileAvailable(USER_ID)).thenReturn(true)
        whenever(notificationLockscreenUserManager.isProfileAvailable(USER_ID)).thenReturn(true)
+11 −11
Original line number Original line Diff line number Diff line
@@ -169,7 +169,7 @@ public class MediaDeviceManagerTest : SysuiTestCase() {


        context.orCreateTestableResources.addOverride(
        context.orCreateTestableResources.addOverride(
            R.drawable.ic_media_home_devices,
            R.drawable.ic_media_home_devices,
            OTHER_DEVICE_ICON_STUB
            OTHER_DEVICE_ICON_STUB,
        )
        )
    }
    }


@@ -384,7 +384,7 @@ public class MediaDeviceManagerTest : SysuiTestCase() {
        deviceCallback.onAboutToConnectDeviceAdded(
        deviceCallback.onAboutToConnectDeviceAdded(
            "fakeAddress",
            "fakeAddress",
            "AboutToConnectDeviceName",
            "AboutToConnectDeviceName",
            mock(Drawable::class.java)
            mock(Drawable::class.java),
        )
        )
        // Run and reset the executors and listeners so we only focus on new events.
        // Run and reset the executors and listeners so we only focus on new events.
        fakeBgExecutor.runAllReady()
        fakeBgExecutor.runAllReady()
@@ -423,7 +423,7 @@ public class MediaDeviceManagerTest : SysuiTestCase() {
    }
    }


    @Test
    @Test
    @EnableFlags(com.android.systemui.Flags.FLAG_MEDIA_CONTROLS_DRAWABLES_REUSE)
    @EnableFlags(com.android.systemui.Flags.FLAG_MEDIA_CONTROLS_DRAWABLES_REUSE_BUGFIX)
    fun onMediaDataLoaded_withRemotePlaybackType_usesNonNullRoutingSessionName_drawableReused() {
    fun onMediaDataLoaded_withRemotePlaybackType_usesNonNullRoutingSessionName_drawableReused() {
        whenever(routingSession.name).thenReturn(REMOTE_DEVICE_NAME)
        whenever(routingSession.name).thenReturn(REMOTE_DEVICE_NAME)
        whenever(routingSession.selectedRoutes).thenReturn(listOf("selectedRoute", "selectedRoute"))
        whenever(routingSession.selectedRoutes).thenReturn(listOf("selectedRoute", "selectedRoute"))
@@ -437,7 +437,7 @@ public class MediaDeviceManagerTest : SysuiTestCase() {
    }
    }


    @Test
    @Test
    @DisableFlags(com.android.systemui.Flags.FLAG_MEDIA_CONTROLS_DRAWABLES_REUSE)
    @DisableFlags(com.android.systemui.Flags.FLAG_MEDIA_CONTROLS_DRAWABLES_REUSE_BUGFIX)
    fun onMediaDataLoaded_withRemotePlaybackType_usesNonNullRoutingSessionName_drawableNotReused() {
    fun onMediaDataLoaded_withRemotePlaybackType_usesNonNullRoutingSessionName_drawableNotReused() {
        whenever(routingSession.name).thenReturn(REMOTE_DEVICE_NAME)
        whenever(routingSession.name).thenReturn(REMOTE_DEVICE_NAME)
        whenever(routingSession.selectedRoutes).thenReturn(listOf("selectedRoute", "selectedRoute"))
        whenever(routingSession.selectedRoutes).thenReturn(listOf("selectedRoute", "selectedRoute"))
@@ -479,7 +479,7 @@ public class MediaDeviceManagerTest : SysuiTestCase() {


    @Test
    @Test
    @RequiresFlagsEnabled(FLAG_USE_PLAYBACK_INFO_FOR_ROUTING_CONTROLS)
    @RequiresFlagsEnabled(FLAG_USE_PLAYBACK_INFO_FOR_ROUTING_CONTROLS)
    @EnableFlags(com.android.systemui.Flags.FLAG_MEDIA_CONTROLS_DRAWABLES_REUSE)
    @EnableFlags(com.android.systemui.Flags.FLAG_MEDIA_CONTROLS_DRAWABLES_REUSE_BUGFIX)
    fun onMediaDataLoaded_withRemotePlaybackInfo_noMatchingRoutingSession_drawableReused() {
    fun onMediaDataLoaded_withRemotePlaybackInfo_noMatchingRoutingSession_drawableReused() {
        whenever(playbackInfo.playbackType).thenReturn(PlaybackInfo.PLAYBACK_TYPE_REMOTE)
        whenever(playbackInfo.playbackType).thenReturn(PlaybackInfo.PLAYBACK_TYPE_REMOTE)
        whenever(mr2.getRoutingSessionForMediaController(any())).thenReturn(null)
        whenever(mr2.getRoutingSessionForMediaController(any())).thenReturn(null)
@@ -494,7 +494,7 @@ public class MediaDeviceManagerTest : SysuiTestCase() {


    @Test
    @Test
    @RequiresFlagsEnabled(FLAG_USE_PLAYBACK_INFO_FOR_ROUTING_CONTROLS)
    @RequiresFlagsEnabled(FLAG_USE_PLAYBACK_INFO_FOR_ROUTING_CONTROLS)
    @DisableFlags(com.android.systemui.Flags.FLAG_MEDIA_CONTROLS_DRAWABLES_REUSE)
    @DisableFlags(com.android.systemui.Flags.FLAG_MEDIA_CONTROLS_DRAWABLES_REUSE_BUGFIX)
    fun onMediaDataLoaded_withRemotePlaybackInfo_noMatchingRoutingSession_drawableNotReused() {
    fun onMediaDataLoaded_withRemotePlaybackInfo_noMatchingRoutingSession_drawableNotReused() {
        whenever(playbackInfo.playbackType).thenReturn(PlaybackInfo.PLAYBACK_TYPE_REMOTE)
        whenever(playbackInfo.playbackType).thenReturn(PlaybackInfo.PLAYBACK_TYPE_REMOTE)
        whenever(mr2.getRoutingSessionForMediaController(any())).thenReturn(null)
        whenever(mr2.getRoutingSessionForMediaController(any())).thenReturn(null)
@@ -856,7 +856,7 @@ public class MediaDeviceManagerTest : SysuiTestCase() {
    @DisableFlags(Flags.FLAG_LEGACY_LE_AUDIO_SHARING)
    @DisableFlags(Flags.FLAG_LEGACY_LE_AUDIO_SHARING)
    @EnableFlags(
    @EnableFlags(
        Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
        Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
        com.android.systemui.Flags.FLAG_MEDIA_CONTROLS_DRAWABLES_REUSE
        com.android.systemui.Flags.FLAG_MEDIA_CONTROLS_DRAWABLES_REUSE_BUGFIX,
    )
    )
    fun onBroadcastStarted_currentMediaDeviceDataIsBroadcasting_drawablesReused() {
    fun onBroadcastStarted_currentMediaDeviceDataIsBroadcasting_drawablesReused() {
        val broadcastCallback = setupBroadcastCallback()
        val broadcastCallback = setupBroadcastCallback()
@@ -874,7 +874,7 @@ public class MediaDeviceManagerTest : SysuiTestCase() {
    @Test
    @Test
    @DisableFlags(
    @DisableFlags(
        Flags.FLAG_LEGACY_LE_AUDIO_SHARING,
        Flags.FLAG_LEGACY_LE_AUDIO_SHARING,
        com.android.systemui.Flags.FLAG_MEDIA_CONTROLS_DRAWABLES_REUSE
        com.android.systemui.Flags.FLAG_MEDIA_CONTROLS_DRAWABLES_REUSE_BUGFIX,
    )
    )
    @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
    @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
    fun onBroadcastStarted_currentMediaDeviceDataIsBroadcasting_drawablesNotReused() {
    fun onBroadcastStarted_currentMediaDeviceDataIsBroadcasting_drawablesNotReused() {
@@ -893,7 +893,7 @@ public class MediaDeviceManagerTest : SysuiTestCase() {
    @Test
    @Test
    @EnableFlags(
    @EnableFlags(
        Flags.FLAG_LEGACY_LE_AUDIO_SHARING,
        Flags.FLAG_LEGACY_LE_AUDIO_SHARING,
        com.android.systemui.Flags.FLAG_MEDIA_CONTROLS_DRAWABLES_REUSE
        com.android.systemui.Flags.FLAG_MEDIA_CONTROLS_DRAWABLES_REUSE_BUGFIX,
    )
    )
    @DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
    @DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
    fun onBroadcastStarted_legacy_currentMediaDeviceDataIsNotBroadcasting_drawableReused() {
    fun onBroadcastStarted_legacy_currentMediaDeviceDataIsNotBroadcasting_drawableReused() {
@@ -913,7 +913,7 @@ public class MediaDeviceManagerTest : SysuiTestCase() {
    @EnableFlags(Flags.FLAG_LEGACY_LE_AUDIO_SHARING)
    @EnableFlags(Flags.FLAG_LEGACY_LE_AUDIO_SHARING)
    @DisableFlags(
    @DisableFlags(
        Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
        Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
        com.android.systemui.Flags.FLAG_MEDIA_CONTROLS_DRAWABLES_REUSE
        com.android.systemui.Flags.FLAG_MEDIA_CONTROLS_DRAWABLES_REUSE_BUGFIX,
    )
    )
    fun onBroadcastStarted_legacy_currentMediaDeviceDataIsNotBroadcasting_drawableNotReused() {
    fun onBroadcastStarted_legacy_currentMediaDeviceDataIsNotBroadcasting_drawableNotReused() {
        val broadcastCallback = setupBroadcastCallback()
        val broadcastCallback = setupBroadcastCallback()
@@ -984,7 +984,7 @@ public class MediaDeviceManagerTest : SysuiTestCase() {


                override fun onBroadcastMetadataChanged(
                override fun onBroadcastMetadataChanged(
                    broadcastId: Int,
                    broadcastId: Int,
                    metadata: BluetoothLeBroadcastMetadata
                    metadata: BluetoothLeBroadcastMetadata,
                ) {}
                ) {}
            }
            }