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

Commit fea3272c authored by Jorge Gil's avatar Jorge Gil
Browse files

Reset reusable SCVH on release

By removing its views and reseting to its initial state when the
reusable SCVH is about to (potentially) be returned to the pool.
Otherwise when re-acquired its old views may be shown for a couple of
frames especially if going from being used for a header to being used
for a handle, because the handle relayout is async.

This also prevents a caption view from being added to two different
SCVHs that resulted in an IllegalStateException.

Flag: com.android.window.flags.clear_reusable_scvh_on_release
Fix: 402974148
Fix: 432324168
Test: move desktop app to fullscreen - observe no caption flicker
(easier by adding a delay to the async relayout)
Test: verify these steps no longer cause a crash:
 (1) Have two users, clear all tasks/desks
 (2) Go to user B, open one app in desktop
 (3) Switch to user A, open two apps in desktop
 (4) (Optional, use when not reproducing) switch the order of the two
     apps of user A, so bring the bottom one to top before the next
     step
 (5) Switch to user B
 (6) Switch to user A (see crash or repeat 4-6 if unsuccessful)

Change-Id: I9c7351ff03e81f1902effa584127ef4aebeac184
parent 557c7cc2
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -84,6 +84,8 @@ public enum DesktopExperienceFlags {
    ENABLE_CAMERA_COMPAT_EXTERNAL_DISPLAY_ROTATION_BUGFIX(
    ENABLE_CAMERA_COMPAT_EXTERNAL_DISPLAY_ROTATION_BUGFIX(
            Flags::enableCameraCompatExternalDisplayRotationBugfix, false,
            Flags::enableCameraCompatExternalDisplayRotationBugfix, false,
            Flags.FLAG_ENABLE_CAMERA_COMPAT_EXTERNAL_DISPLAY_ROTATION_BUGFIX),
            Flags.FLAG_ENABLE_CAMERA_COMPAT_EXTERNAL_DISPLAY_ROTATION_BUGFIX),
    ENABLE_CLEAR_REUSABLE_SCVH_ON_RELEASE(Flags::clearReusableScvhOnRelease, false,
            Flags.FLAG_CLEAR_REUSABLE_SCVH_ON_RELEASE),
    ENABLE_CONNECTED_DISPLAYS_DND(Flags::enableConnectedDisplaysDnd, true,
    ENABLE_CONNECTED_DISPLAYS_DND(Flags::enableConnectedDisplaysDnd, true,
            Flags.FLAG_ENABLE_CONNECTED_DISPLAYS_DND),
            Flags.FLAG_ENABLE_CONNECTED_DISPLAYS_DND),
    ENABLE_CONNECTED_DISPLAYS_PIP(Flags::enableConnectedDisplaysPip, true,
    ENABLE_CONNECTED_DISPLAYS_PIP(Flags::enableConnectedDisplaysPip, true,
+10 −0
Original line number Original line Diff line number Diff line
@@ -12,6 +12,16 @@ flag {
    }
    }
}
}


flag {
    name: "clear_reusable_scvh_on_release"
    namespace: "lse_desktop_experience"
    description: "Resets the views of reusable SCVHs when released"
    bug: "432324168"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
flag {
    name: "close_task_keyboard_shortcut"
    name: "close_task_keyboard_shortcut"
    namespace: "lse_desktop_experience"
    namespace: "lse_desktop_experience"
+1 −1
Original line number Original line Diff line number Diff line
@@ -401,7 +401,7 @@ constructor(
        inSyncWithTransition: Boolean,
        inSyncWithTransition: Boolean,
    ): RelayoutParams {
    ): RelayoutParams {
        val captionType =
        val captionType =
            if (desktopUserRepositories.current.isActiveTask(taskInfo.taskId)) {
            if (taskInfo.isFreeform) {
                CaptionController.CaptionType.APP_HEADER
                CaptionController.CaptionType.APP_HEADER
            } else {
            } else {
                CaptionController.CaptionType.APP_HANDLE
                CaptionController.CaptionType.APP_HANDLE
+19 −3
Original line number Original line Diff line number Diff line
@@ -42,6 +42,7 @@ import com.android.wm.shell.windowdecor.WindowDecoration2.SurfaceControlViewHost
import com.android.wm.shell.windowdecor.WindowDecorationInsets
import com.android.wm.shell.windowdecor.WindowDecorationInsets
import com.android.wm.shell.windowdecor.common.viewhost.WindowDecorViewHost
import com.android.wm.shell.windowdecor.common.viewhost.WindowDecorViewHost
import com.android.wm.shell.windowdecor.common.viewhost.WindowDecorViewHostSupplier
import com.android.wm.shell.windowdecor.common.viewhost.WindowDecorViewHostSupplier
import com.android.wm.shell.windowdecor.extension.identityHashCode
import com.android.wm.shell.windowdecor.extension.isRtl
import com.android.wm.shell.windowdecor.extension.isRtl
import com.android.wm.shell.windowdecor.extension.isTransparentCaptionBarAppearance
import com.android.wm.shell.windowdecor.extension.isTransparentCaptionBarAppearance
import com.android.wm.shell.windowdecor.viewholder.WindowDecorationViewHolder
import com.android.wm.shell.windowdecor.viewholder.WindowDecorationViewHolder
@@ -213,6 +214,7 @@ abstract class CaptionController<T>(
    protected open fun getCaptionTopPadding(): Int = 0
    protected open fun getCaptionTopPadding(): Int = 0


    /** Updates the caption's view hierarchy. */
    /** Updates the caption's view hierarchy. */
    @OptIn(ExperimentalStdlibApi::class)
    private fun updateViewHierarchy(
    private fun updateViewHierarchy(
        params: RelayoutParams,
        params: RelayoutParams,
        viewHost: WindowDecorViewHost,
        viewHost: WindowDecorViewHost,
@@ -228,11 +230,15 @@ abstract class CaptionController<T>(
        ) {
        ) {
            val taskId = taskInfo.taskId
            val taskId = taskInfo.taskId
            logD(
            logD(
                "updateViewHierarchy of taskId=%d size=%dx%d touchableRegion=%s",
                "updateViewHierarchy of taskId=%d size=%dx%d touchableRegion=%s " +
                    "view=%s viewParent=%s viewHost=%s",
                taskId,
                taskId,
                captionWidth,
                captionWidth,
                captionHeight,
                captionHeight,
                touchableRegion,
                touchableRegion,
                view.identityHashCode.toHexString(),
                view.parent.identityHashCode.toHexString(),
                viewHost,
            )
            )
            val lp =
            val lp =
                WindowManager.LayoutParams(
                WindowManager.LayoutParams(
@@ -480,7 +486,12 @@ abstract class CaptionController<T>(
     * view holder.
     * view holder.
     */
     */
    private fun getOrCreateViewHolder(): WindowDecorationViewHolder<*> {
    private fun getOrCreateViewHolder(): WindowDecorationViewHolder<*> {
        val viewHolder = windowDecorationViewHolder ?: createCaptionView()
        val currentViewHolder = windowDecorationViewHolder
        if (currentViewHolder != null) {
            return currentViewHolder
        }
        val viewHolder = createCaptionView()
        logD("getOrCreateViewHolder() created new caption view: %s", viewHolder)
        windowDecorationViewHolder = viewHolder
        windowDecorationViewHolder = viewHolder
        return viewHolder
        return viewHolder
    }
    }
@@ -501,7 +512,12 @@ abstract class CaptionController<T>(
            traceTag = Trace.TRACE_TAG_WINDOW_MANAGER,
            traceTag = Trace.TRACE_TAG_WINDOW_MANAGER,
            name = "CaptionController#getOrCreateViewHost",
            name = "CaptionController#getOrCreateViewHost",
        ) {
        ) {
            val viewHost = captionViewHost ?: windowDecorViewHostSupplier.acquire(context, display)
            val currentViewHost = captionViewHost
            if (currentViewHost != null) {
                return currentViewHost
            }
            val viewHost = windowDecorViewHostSupplier.acquire(context, display)
            logD("getOrCreateViewHost() acquired viewHost: %s", viewHost)
            captionViewHost = viewHost
            captionViewHost = viewHost
            return viewHost
            return viewHost
        }
        }
+4 −0
Original line number Original line Diff line number Diff line
@@ -82,6 +82,10 @@ class DefaultWindowDecorViewHost(
        Trace.endSection()
        Trace.endSection()
    }
    }


    override fun reset() {
        // No-op.
    }

    override fun release(t: SurfaceControl.Transaction) {
    override fun release(t: SurfaceControl.Transaction) {
        clearCurrentUpdateJob()
        clearCurrentUpdateJob()
        viewHostAdapter.release(t)
        viewHostAdapter.release(t)
Loading