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

Commit 6f585e15 authored by Jorge Gil's avatar Jorge Gil
Browse files

Fix inset rect calculation

The rect's |bottom| was mistakenly set to the height of the caption, but
it also needs to be offset from the rect's height, otherwise it could
end up with a bottom value lower than top, which results in a negative
height that is used to report insets.

Flag: com.android.window.flags.enable_window_decoration_refactor
Bug: 409648813
Test: check app content is offset to account for caption insets
Change-Id: I5ee787ebb66f776e5258bf76f2a09e111ba9e5e0
parent 325d92db
Loading
Loading
Loading
Loading
+38 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.Context
import android.graphics.PixelFormat
import android.graphics.Rect
import android.graphics.Region
import android.graphics.RegionIterator
import android.os.Binder
import android.os.Trace
import android.view.Display
@@ -30,6 +31,8 @@ import android.view.WindowManager
import android.window.DesktopModeFlags
import android.window.WindowContainerTransaction
import com.android.app.tracing.traceSection
import com.android.internal.protolog.ProtoLog
import com.android.wm.shell.protolog.ShellProtoLogGroup
import com.android.wm.shell.windowdecor.HandleMenuController
import com.android.wm.shell.windowdecor.ManageWindowsMenuController
import com.android.wm.shell.windowdecor.MaximizeMenuController
@@ -146,6 +149,17 @@ abstract class CaptionController<T>(
        )
        val customizableCaptionRegion =
            updateCaptionInsets(params, decorWindowContext, wct, captionHeight, taskBounds)
        logD(
            "relayout with taskBounds=%s captionSize=%dx%d captionTopPadding=%d " +
                    "captionX=%d captionY=%d customCaptionRegion=%s",
            taskBounds,
            captionHeight,
            captionWidth,
            captionTopPadding,
            captionX,
            captionY,
            customizableCaptionRegion.toReadableString(),
        )

        traceSection(
            traceTag = Trace.TRACE_TAG_WINDOW_MANAGER,
@@ -367,7 +381,7 @@ abstract class CaptionController<T>(
        // positioned at the top of the task bounds, also in absolute coordinates.
        // So just reuse the task bounds and adjust the bottom coordinate.
        val captionInsetsRect = Rect(taskBounds)
        captionInsetsRect.bottom = captionHeight
        captionInsetsRect.bottom = captionInsetsRect.top + captionHeight

        // Caption bounding rectangles: these are optional, and are used to present finer
        // insets than traditional |Insets| to apps about where their content is occluded.
@@ -507,6 +521,27 @@ abstract class CaptionController<T>(
        return viewHost
    }

    private fun logD(msg: String, vararg arguments: Any?) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_WINDOW_DECORATION, "%s: $msg", TAG, *arguments)
    }

    private fun Region.toReadableString(): String {
        val iterator = RegionIterator(this)
        val rect = Rect()
        val sb = StringBuilder()
        sb.append("Region[")
        var first = true
        while (iterator.next(rect)) {
            if (!first) {
                sb.append(", ")
            }
            sb.append(rect.toShortString())
            first = false
        }
        sb.append("]")
        return sb.toString()
    }

    /** Caption data calculated during [relayout]. */
    data class CaptionRelayoutResult(
        // The caption height with caption padding included
@@ -524,6 +559,8 @@ abstract class CaptionController<T>(
    }

    companion object {
        private const val TAG = "CaptionController"

        /**
         * The Z-order of the caption surface.
         *