Fixed a bug where the player was invisible

We were blocking location changes because of visibility
of hosts, but never listened to changes to it

Bug: 159494391
Test: kill sysui with player
Change-Id: I8a195b3e5a91210ed1c03a24d09f7bda5923b210
This commit is contained in:
Selim Cinek
2020-06-19 18:34:23 -07:00
parent afae4e715f
commit 7ba605bce5
5 changed files with 22 additions and 7 deletions

View File

@@ -56,7 +56,7 @@ class KeyguardMediaController @Inject constructor(
fun attach(mediaView: MediaHeaderView) {
view = mediaView
// First let's set the desired state that we want for this host
mediaHost.visibleChangedListener = { updateVisibility() }
mediaHost.addVisibilityChangeListener { updateVisibility() }
mediaHost.expansion = 0.0f
mediaHost.showsOnlyActiveMedia = true
mediaHost.falsingProtectionNeeded = true

View File

@@ -227,6 +227,10 @@ class MediaHierarchyManager @Inject constructor(
fun register(mediaObject: MediaHost): UniqueObjectHostView {
val viewHost = createUniqueObjectHost()
mediaObject.hostView = viewHost
mediaObject.addVisibilityChangeListener {
// Never animate because of a visibility change, only state changes should do that
updateDesiredLocation(forceNoAnimation = true)
}
mediaHosts[mediaObject.location] = mediaObject
if (mediaObject.location == desiredLocation) {
// In case we are overriding a view that is already visible, make sure we attach it
@@ -260,8 +264,10 @@ class MediaHierarchyManager @Inject constructor(
/**
* Updates the location that the view should be in. If it changes, an animation may be triggered
* going from the old desired location to the new one.
*
* @param forceNoAnimation optional parameter telling the system not to animate
*/
private fun updateDesiredLocation() {
private fun updateDesiredLocation(forceNoAnimation: Boolean = false) {
val desiredLocation = calculateLocation()
if (desiredLocation != this.desiredLocation) {
if (this.desiredLocation >= 0) {
@@ -270,7 +276,8 @@ class MediaHierarchyManager @Inject constructor(
val isNewView = this.desiredLocation == -1
this.desiredLocation = desiredLocation
// Let's perform a transition
val animate = shouldAnimateTransition(desiredLocation, previousLocation)
val animate = !forceNoAnimation &&
shouldAnimateTransition(desiredLocation, previousLocation)
val (animDuration, delay) = getAnimationParams(previousLocation, desiredLocation)
val host = getHost(desiredLocation)
mediaCarouselController.onDesiredLocationChanged(desiredLocation, host, animate,

View File

@@ -2,6 +2,7 @@ package com.android.systemui.media
import android.graphics.PointF
import android.graphics.Rect
import android.util.ArraySet
import android.view.View
import android.view.View.OnAttachStateChangeListener
import com.android.systemui.util.animation.MeasurementInput
@@ -20,7 +21,7 @@ class MediaHost @Inject constructor(
lateinit var hostView: UniqueObjectHostView
var location: Int = -1
private set
var visibleChangedListener: ((Boolean) -> Unit)? = null
private var visibleChangedListeners: ArraySet<(Boolean) -> Unit> = ArraySet()
private val tmpLocationOnScreen: IntArray = intArrayOf(0, 0)
@@ -58,6 +59,10 @@ class MediaHost @Inject constructor(
}
}
fun addVisibilityChangeListener(listener: (Boolean) -> Unit) {
visibleChangedListeners.add(listener)
}
/**
* Initialize this MediaObject and create a host view.
* All state should already be set on this host before calling this method in order to avoid
@@ -116,7 +121,9 @@ class MediaHost @Inject constructor(
val newVisibility = if (visible) View.VISIBLE else View.GONE
if (newVisibility != hostView.visibility) {
hostView.visibility = newVisibility
visibleChangedListener?.invoke(visible)
visibleChangedListeners.forEach {
it.invoke(visible)
}
}
}

View File

@@ -160,7 +160,7 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
mMediaTotalBottomMargin = getResources().getDimensionPixelSize(
R.dimen.quick_settings_bottom_margin_media);
mMediaHost = mediaHost;
mMediaHost.setVisibleChangedListener((visible) -> {
mMediaHost.addVisibilityChangeListener((visible) -> {
onMediaVisibilityChanged(visible);
return null;
});

View File

@@ -27,6 +27,7 @@ import com.android.systemui.statusbar.StatusBarState
import com.android.systemui.statusbar.SysuiStatusBarStateController
import com.android.systemui.statusbar.notification.stack.MediaHeaderView
import com.android.systemui.statusbar.phone.KeyguardBypassController
import com.android.systemui.util.mockito.capture
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@@ -94,7 +95,7 @@ class KeyguardMediaControllerTest : SysuiTestCase() {
private fun triggerVisibilityListener() {
keyguardMediaController.attach(mediaHeaderView)
verify(mediaHost).visibleChangedListener = visibilityListener.capture()
verify(mediaHost).addVisibilityChangeListener(capture(visibilityListener))
visibilityListener.value.invoke(true)
}
}