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

Commit abf8d7de authored by Yi Jiang's avatar Yi Jiang
Browse files

Mitigate layer leakage in Fullscreen Magnifier

AM#attachAccessibilityOverlayToDisplay() is an IPC. Calling it
multiple times for the same surface is redundant and can increase the
chance of race conditions which causes layer leakage.

This change adds a variable to check the attachment status to avoid
unnecessary attach calls.

Test: Quickly turned on/off the magnifier, the layer leakage is mitigated.
Bug: 407915377
Flag: com.android.window.flags.scvh_surface_control_lifetime_fix

Change-Id: I302c71a5899872b784173b68f899f4d1f98fbc81
parent 82a40c69
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.systemui.accessibility;

import static android.view.WindowManager.LayoutParams;

import static com.android.window.flags.Flags.scvhSurfaceControlLifetimeFix;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
@@ -106,6 +108,7 @@ public class FullscreenMagnificationController implements ComponentCallbacks {
    private final DisplayManager mDisplayManager;
    private final DisplayManager.DisplayListener mDisplayListener;
    private String mCurrentDisplayUniqueId;
    private boolean mShouldAttachOverlay = true;

    @Retention(RetentionPolicy.SOURCE)
    @IntDef({
@@ -309,6 +312,7 @@ public class FullscreenMagnificationController implements ComponentCallbacks {
                Log.w(TAG, "Failed to remove rotation watcher", e);
            }
        }
        mShouldAttachOverlay = true; // After cleanup, a new creation will need to attach.
        setState(DISABLED);
    }

@@ -356,6 +360,8 @@ public class FullscreenMagnificationController implements ComponentCallbacks {
            if (Flags.updateCornerRadiusOnDisplayChanged()) {
                applyCornerRadiusToBorder();
            }
            // A new SurfaceControl was created, so attachment is necessary.
            mShouldAttachOverlay = true;
        }

        mTransaction
@@ -373,8 +379,14 @@ public class FullscreenMagnificationController implements ComponentCallbacks {
                .show(mBorderSurfaceControl)
                .apply();

        mAccessibilityManager.attachAccessibilityOverlayToDisplay(
                mDisplayId, mBorderSurfaceControl);
        if (mShouldAttachOverlay) {
            // Only attach if deemed necessary
            mAccessibilityManager.attachAccessibilityOverlayToDisplay(mDisplayId,
                    mBorderSurfaceControl);
            if (scvhSurfaceControlLifetimeFix()) {
                mShouldAttachOverlay = false;
            }
        }
        if (Flags.updateCornerRadiusOnDisplayChanged()) {
            mDisplayManager.registerDisplayListener(mDisplayListener, mHandler);
        }