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

Commit 2c7bc5ff authored by Winson Chung's avatar Winson Chung
Browse files

Reduce surface size when allocating intercept layer

- Specify the smallest surface size while still declaring a large enough
  touchable region to receive touches for the whole display. We don't
  use w/h of 0,0 or MATCH_PARENT as those technically result in an
  unbounded touch region, but that may be fixed in a future change.

Bug: 433055104
Flag: EXEMPT bugfix
Test: Manual
Change-Id: I4ee7700c4c4cff1fc812ee04aa607299bfac9858
parent fd0997af
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -18,12 +18,16 @@ package com.android.wm.shell.common.split
import android.app.TaskInfo
import android.content.Context
import android.graphics.PixelFormat
import android.graphics.Rect
import android.graphics.Region
import android.os.Binder
import android.view.SurfaceControl
import android.view.SurfaceControlViewHost
import android.view.View
import android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION
import android.view.WindowManager
import android.view.WindowlessWindowManager
import java.lang.Integer.MAX_VALUE

/**
 * Manages a touchable surface that is intended to intercept touches.
@@ -44,14 +48,12 @@ class TouchInterceptLayer(
    ) {
        rootView = View(context.createConfigurationContext(rootTaskInfo.configuration))

        // Set WM flags, tokens, and sizing on the touchable view. It will be the same size as its
        // parent
        // TODO (b/349828130): It's a bit wasteful to have the touch zone cover the whole app
        //  surface, even extending offscreen (keeps buffer active in memory), so can trim it down
        //  to the visible onscreen area in a future patch.
        // Set WM flags, tokens, and sizing on the touchable view. Create the smallest sized surface
        // possible for performance reasons. We don't use MATCH_PARENT here because there isn't
        // actually a parent (like in normal windows) to resolve a size from, and can result in
        // an empty input region in the future.
        val lp = WindowManager.LayoutParams(
            rootTaskInfo.configuration.windowConfiguration.bounds.width(),
            rootTaskInfo.configuration.windowConfiguration.bounds.height(),
            1, 1,
            WindowManager.LayoutParams.TYPE_INPUT_CONSUMER,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
            PixelFormat.TRANSPARENT
@@ -84,6 +86,13 @@ class TouchInterceptLayer(
        rootView?.setWillNotDraw(true)
        rootView?.parent?.requestTransparentRegion(rootView)

        // Workaround for ensuring that we receive touches outside the bounds of the surface (input
        // currently uses the touchable region to determine if the window should receive events).
        // TODO(b/433258252): We can revert to using the full root bounds when there is a way to
        //                    declare that we don't want a buffer
        wwm.setInsets(viewHost!!.windowToken, TOUCHABLE_INSETS_REGION, Rect(), Rect(),
            Region(-MAX_VALUE / 2, -MAX_VALUE / 2, MAX_VALUE / 2, MAX_VALUE / 2))

        // Create a transaction so that we can activate and reposition our surface.
        val t = SurfaceControl.Transaction()
        // Set layer to maximum. We want this surface to be above the app layer, or else touches