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

Commit 680aabce authored by Michael Mikhail's avatar Michael Mikhail
Browse files

Update media frame size along with media carousel

Flag: com.android.systemui.media_frame_dimensions_fix
Fixes: 432154750
Bug: 428735024
Bug: 417204970
Test: Checked UI, multiple device rotations to move media controls on various locations with different size in very short period of time.
Test: Playing media in landscape then press power button to show media in lockscreen three times.
Test: Showing two media controls on QQS then rotate to show collapsed version. Then back to portrait mode and scroll to QS and try to move through the two media players.
Change-Id: Ie096df7b4d98d815d5576702ac8e0e21aa46ed17
parent cc6b323b
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -1289,6 +1289,16 @@ flag {
    }
}

flag {
    name:"media_frame_dimensions_fix"
    namespace: "systemui"
    description: "measure and layout media frame when the desired location of media carousel changes"
    bug: "417204970"
    metadata {
      purpose: PURPOSE_BUGFIX
    }
}

flag {
  namespace: "systemui"
  name: "enable_view_capture_tracing"
+30 −2
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import com.android.keyguard.KeyguardUpdateMonitorCallback
import com.android.systemui.Dumpable
import com.android.systemui.Flags
import com.android.systemui.Flags.enableSuggestedDeviceUi
import com.android.systemui.Flags.mediaFrameDimensionsFix
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
@@ -1261,13 +1262,40 @@ constructor(
            // Let's remeasure the carousel
            val widthSpec = desiredHostState?.measurementInput?.widthMeasureSpec ?: 0
            val heightSpec = desiredHostState?.measurementInput?.heightMeasureSpec ?: 0
            mediaCarousel.measure(widthSpec, heightSpec)
            mediaCarousel.layout(0, 0, width, mediaCarousel.measuredHeight)
            mediaCarousel.measureAndLayout(
                widthSpec,
                heightSpec,
                width,
                mediaCarousel.measuredHeight,
            )
            if (mediaFrameDimensionsFix()) {
                debugLogger.logMediaCarouselDimensions(
                    reason = "update carousel size",
                    mediaCarousel.boundsOnScreen,
                    desiredLocation,
                )
                mediaFrame.measureAndLayout(
                    widthSpec,
                    heightSpec,
                    width,
                    mediaCarousel.measuredHeight,
                )
            }
            // Update the padding after layout; view widths are used in RTL to calculate scrollX
            mediaCarouselScrollHandler.playerWidthPlusPadding = playerWidthPlusPadding
        }
    }

    private fun ViewGroup.measureAndLayout(
        widthSpec: Int,
        heightSpec: Int,
        width: Int,
        height: Int,
    ) {
        measure(widthSpec, heightSpec)
        layout(0, 0, width, height)
    }

    fun onCarouselVisibleToUser() {
        if (
            !enableSuggestedDeviceUi() ||
+14 −0
Original line number Diff line number Diff line
@@ -95,6 +95,20 @@ constructor(@MediaCarouselControllerLog private val buffer: LogBuffer) {
            { "media frame($str1), width: $int1 height: $int2, location:$long1" },
        )
    }

    fun logMediaCarouselDimensions(reason: String, rect: Rect, location: Int) {
        buffer.log(
            TAG,
            LogLevel.DEBUG,
            {
                str1 = reason
                int1 = rect.width()
                int2 = rect.height()
                long1 = location.toLong()
            },
            { "media carousel($str1), width: $int1 height: $int2, location:$long1" },
        )
    }
}

private const val TAG = "MediaCarouselCtlrLog"
+19 −16
Original line number Diff line number Diff line
@@ -1446,13 +1446,15 @@ private fun ContentScope.MediaObject(
                },
                update = { view ->
                    view.update()
                    if (!Flags.mediaFrameDimensionsFix()) {
                        // Update layout params if host view bounds are higher than its child.
                        val height = mediaHost.hostView.height
                        val width = mediaHost.hostView.width
                        var measure = false
                        mediaHost.hostView.children.forEach { child ->
                            if (
                            child is FrameLayout && (height > child.height || width > child.width)
                                child is FrameLayout &&
                                    (height > child.height || width > child.width)
                            ) {
                                measure = true
                                child.layoutParams = FrameLayout.LayoutParams(width, height)
@@ -1464,6 +1466,7 @@ private fun ContentScope.MediaObject(
                            )
                            mediaLogger.logMediaSize("update size in compose", width, height)
                        }
                    }
                },
                onReset = {},
            )
+7 −4
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import com.android.systemui.Flags
import com.android.systemui.res.R

/**
@@ -52,11 +53,13 @@ class UniqueObjectHostView(context: Context) : FrameLayout(context) {
        if (isCurrentHost()) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec)
            getChildAt(0)?.let { mediaFrame ->
                if (!Flags.mediaFrameDimensionsFix()) {
                    // Media host dimensions are correct. Its child cannot show larger dimensions.
                    // We also need to ensure that dimensions are not less than expected.
                    if (cachedWidth > mediaFrame.width || cachedHeight > mediaFrame.height) {
                        mediaFrame.layoutParams = LayoutParams(cachedWidth, cachedHeight)
                    }
                }
                mediaFrame.requiresRemeasuring = false
            }
        }