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

Commit 007313b8 authored by Beth Thibodeau's avatar Beth Thibodeau
Browse files

Update media visibility on lock screen

Media carousel visibility on lock screen follows the notification
setting - if notifications are disabled on lock screen, hide media carousel
everywhere, not just in the keyguard layout

Bug: 314333719
Test: manual
Test: atest MediaHierarchyManagerTest
Flag: NONE

Change-Id: I4f618e4013db894291e6fca9d49bceb1cb7e4bd9
Merged-In: I4f618e4013db894291e6fca9d49bceb1cb7e4bd9
parent 89c545f4
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import androidx.annotation.VisibleForTesting
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.media.dagger.MediaModule.KEYGUARD
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.statusbar.NotificationLockscreenUserManager
import com.android.systemui.statusbar.StatusBarState
import com.android.systemui.statusbar.SysuiStatusBarStateController
import com.android.systemui.statusbar.notification.stack.MediaContainerView
@@ -43,7 +42,6 @@ class KeyguardMediaController @Inject constructor(
    @param:Named(KEYGUARD) private val mediaHost: MediaHost,
    private val bypassController: KeyguardBypassController,
    private val statusBarStateController: SysuiStatusBarStateController,
    private val notifLockscreenUserManager: NotificationLockscreenUserManager,
    private val context: Context,
    configurationController: ConfigurationController
) {
@@ -163,8 +161,7 @@ class KeyguardMediaController @Inject constructor(
        // mediaHost.visible required for proper animations handling
        visible = mediaHost.visible &&
                !bypassController.bypassEnabled &&
                keyguardOrUserSwitcher &&
                notifLockscreenUserManager.shouldShowLockscreenNotifications()
                keyguardOrUserSwitcher
        if (visible) {
            showMediaPlayer()
        } else {
+1 −0
Original line number Diff line number Diff line
@@ -176,6 +176,7 @@ class MediaCarouselController @Inject constructor(
     * It will be called when the container is out of view.
     */
    lateinit var updateUserVisibility: () -> Unit
    lateinit var updateHostVisibility: () -> Unit

    private val isReorderingAllowed: Boolean
        get() = visualStabilityProvider.isReorderingAllowed
+13 −0
Original line number Diff line number Diff line
@@ -451,6 +451,7 @@ class MediaHierarchyManager @Inject constructor(
                    mediaCarouselController.logSmartspaceImpression(qsExpanded)
                }
                mediaCarouselController.mediaCarouselScrollHandler.visibleToUser = isVisibleToUser()
                mediaCarouselController.updateHostVisibility()
            }

            override fun onDozeAmountChanged(linear: Float, eased: Float) {
@@ -510,6 +511,11 @@ class MediaHierarchyManager @Inject constructor(
        mediaCarouselController.updateUserVisibility = {
            mediaCarouselController.mediaCarouselScrollHandler.visibleToUser = isVisibleToUser()
        }
        mediaCarouselController.updateHostVisibility = {
            mediaHosts.forEach {
                it?.updateViewVisibility()
            }
        }
    }

    private fun updateConfiguration() {
@@ -555,6 +561,13 @@ class MediaHierarchyManager @Inject constructor(
        mediaCarouselController.closeGuts()
    }

    /** Return true if the carousel should be hidden because lockscreen is currently visible */
    fun isLockedAndHidden(): Boolean {
        return !notifLockscreenUserManager.shouldShowLockscreenNotifications() &&
                (statusbarState == StatusBarState.SHADE_LOCKED ||
                        statusbarState == StatusBarState.KEYGUARD)
    }

    private fun createUniqueObjectHost(): UniqueObjectHostView {
        val viewHost = UniqueObjectHostView(context)
        viewHost.addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
+8 −2
Original line number Diff line number Diff line
@@ -167,8 +167,14 @@ class MediaHost constructor(
        }
    }

    private fun updateViewVisibility() {
        state.visible = if (showsOnlyActiveMedia) {
    /**
     * Updates this host's state based on the current media data's status, and invokes listeners if
     * the visibility has changed
     */
    fun updateViewVisibility() {
        state.visible = if (mediaHierarchyManager.isLockedAndHidden()) {
            false
        } else if (showsOnlyActiveMedia) {
            mediaDataManager.hasActiveMediaOrRecommendation()
        } else {
            mediaDataManager.hasAnyMediaOrRecommendation()
+0 −16
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.view.View.GONE
import android.view.View.VISIBLE
import android.widget.FrameLayout
import com.android.systemui.SysuiTestCase
import com.android.systemui.statusbar.NotificationLockscreenUserManager
import com.android.systemui.statusbar.StatusBarState
import com.android.systemui.statusbar.SysuiStatusBarStateController
import com.android.systemui.statusbar.notification.stack.MediaContainerView
@@ -53,8 +52,6 @@ class KeyguardMediaControllerTest : SysuiTestCase() {
    @Mock
    private lateinit var configurationController: ConfigurationController

    @Mock
    private lateinit var notificationLockscreenUserManager: NotificationLockscreenUserManager
    @JvmField @Rule
    val mockito = MockitoJUnit.rule()

@@ -67,15 +64,12 @@ class KeyguardMediaControllerTest : SysuiTestCase() {
        // default state is positive, media should show up
        whenever(mediaHost.visible).thenReturn(true)
        whenever(statusBarStateController.state).thenReturn(StatusBarState.KEYGUARD)
        whenever(notificationLockscreenUserManager.shouldShowLockscreenNotifications())
                .thenReturn(true)
        whenever(mediaHost.hostView).thenReturn(hostView)
        hostView.layoutParams = FrameLayout.LayoutParams(100, 100)
        keyguardMediaController = KeyguardMediaController(
            mediaHost,
            bypassController,
            statusBarStateController,
            notificationLockscreenUserManager,
            context,
            configurationController
        )
@@ -105,16 +99,6 @@ class KeyguardMediaControllerTest : SysuiTestCase() {
        assertThat(mediaContainerView.visibility).isEqualTo(visibility)
    }

    @Test
    fun testHiddenOnKeyguard_whenNotificationsAreHidden() {
        whenever(notificationLockscreenUserManager.shouldShowLockscreenNotifications())
                .thenReturn(false)

        keyguardMediaController.refreshMediaPosition()

        assertThat(mediaContainerView.visibility).isEqualTo(GONE)
    }

    @Test
    fun testActivatesSplitShadeContainerInSplitShadeMode() {
        val splitShadeContainer = FrameLayout(context)
Loading