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

Commit a16a3521 authored by Ibrahim Yilmaz's avatar Ibrahim Yilmaz
Browse files

MediaContainerView: Log invalid visibility change

MediaContainerView's visibility is changed to VISIBLE when it should be gone. This CL logs this invalid state to find the culprit candidate.

Bug: 298213983
Test: presubmit
Flag: NONE
Change-Id: Id6d59546ffe0d028e2a4332d9983ef3b0660aa90
parent 9fb2aa65
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -300,10 +300,17 @@ constructor(
    private fun setVisibility(view: ViewGroup?, newVisibility: Int) {
        val currentMediaContainer = view ?: return

        val isVisible = newVisibility == View.VISIBLE

        if (currentMediaContainer is MediaContainerView) {
            val previousVisibility = currentMediaContainer.visibility

            currentMediaContainer.setKeyguardVisibility(isVisible)
            if (previousVisibility != newVisibility) {
                visibilityChangedListener?.invoke(isVisible)
            }
        } else {
            currentMediaContainer.visibility = newVisibility
        if (previousVisibility != newVisibility && currentMediaContainer is MediaContainerView) {
            visibilityChangedListener?.invoke(newVisibility == View.VISIBLE)
        }
    }

+44 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.graphics.Canvas
import android.graphics.Path
import android.graphics.RectF
import android.util.AttributeSet
import android.util.Log
import com.android.systemui.res.R
import com.android.systemui.statusbar.notification.row.ExpandableView

@@ -87,4 +88,47 @@ class MediaContainerView(context: Context, attrs: AttributeSet?) : ExpandableVie
    ) {
        // No animation, it doesn't need it, this would be local
    }

    override fun setVisibility(visibility: Int) {
        super.setVisibility(visibility)
        assertMediaContainerVisibility(visibility)
    }

    /**
     * b/298213983
     * MediaContainerView's visibility is changed to VISIBLE when it should be GONE.
     * This method check this state and logs.
     */
    private fun assertMediaContainerVisibility(visibility: Int) {
        val currentViewState = viewState

        if (currentViewState is MediaContainerViewState) {
            if (!currentViewState.shouldBeVisible && visibility == VISIBLE) {
                Log.wtf("MediaContainerView", "MediaContainerView should be GONE " +
                        "but its visibility changed to VISIBLE")
            }
        }
    }

    fun setKeyguardVisibility(isVisible: Boolean) {
        val currentViewState = viewState
        if (currentViewState is MediaContainerViewState) {
            currentViewState.shouldBeVisible = isVisible
        }

        visibility = if (isVisible) VISIBLE else GONE
    }

    override fun createExpandableViewState(): ExpandableViewState = MediaContainerViewState()

    class MediaContainerViewState : ExpandableViewState() {
        var shouldBeVisible: Boolean = false

        override fun copyFrom(viewState: ViewState) {
            super.copyFrom(viewState)
            if (viewState is MediaContainerViewState) {
                shouldBeVisible = viewState.shouldBeVisible
            }
        }
    }
}