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

Commit b664991f authored by Patrick Williams's avatar Patrick Williams
Browse files

Fix layer leak in a11y magnifier

Bug: 407989942
Flag: com.android.window.flags.scvh_surface_control_lifetime_fix
Test: manually verified the layer disappears when the magnifier is removed
Change-Id: Ifd3b5c01437ee8a9917a17ed34a5def178ea1341
parent 63e8deb6
Loading
Loading
Loading
Loading
+20 −12
Original line number Original line Diff line number Diff line
@@ -169,6 +169,11 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold
     */
     */
    private SurfaceControlViewHost mSurfaceControlViewHost;
    private SurfaceControlViewHost mSurfaceControlViewHost;


    /**
     * The SurfaceControl provided by SurfaceControlViewHost.
     */
    private SurfaceControl mMirrorViewLeash;

    // The root of the mirrored content
    // The root of the mirrored content
    private SurfaceControl mMirrorSurface;
    private SurfaceControl mMirrorSurface;


@@ -469,6 +474,12 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold
            mSurfaceControlViewHost = null;
            mSurfaceControlViewHost = null;
        }
        }


        if (mMirrorViewLeash != null) {
            mTransaction.reparent(mMirrorViewLeash, null).apply();
            mMirrorViewLeash.release();
            mMirrorViewLeash = null;
        }

        mMirrorViewBounds.setEmpty();
        mMirrorViewBounds.setEmpty();
        mSourceBounds.setEmpty();
        mSourceBounds.setEmpty();
        updateSystemUIStateIfNeeded();
        updateSystemUIStateIfNeeded();
@@ -659,23 +670,22 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold


        mSurfaceControlViewHost = mScvhSupplier.get();
        mSurfaceControlViewHost = mScvhSupplier.get();
        mSurfaceControlViewHost.setView(mMirrorView, params);
        mSurfaceControlViewHost.setView(mMirrorView, params);
        SurfaceControl surfaceControl = mSurfaceControlViewHost
        mMirrorViewLeash = mSurfaceControlViewHost.getSurfacePackage().getSurfaceControl();
                .getSurfacePackage().getSurfaceControl();


        int x = mMagnificationFrame.left - mMirrorSurfaceMargin;
        int x = mMagnificationFrame.left - mMirrorSurfaceMargin;
        int y = mMagnificationFrame.top - mMirrorSurfaceMargin;
        int y = mMagnificationFrame.top - mMirrorSurfaceMargin;
        mTransaction
        mTransaction
                .setCrop(surfaceControl, new Rect(0, 0, windowWidth, windowHeight))
                .setCrop(mMirrorViewLeash, new Rect(0, 0, windowWidth, windowHeight))
                .setPosition(surfaceControl, x, y)
                .setPosition(mMirrorViewLeash, x, y)
                .setLayer(surfaceControl, Integer.MAX_VALUE)
                .setLayer(mMirrorViewLeash, Integer.MAX_VALUE)
                .show(surfaceControl)
                .show(mMirrorViewLeash)
                .apply();
                .apply();


        mMirrorViewBounds.set(x, y, x + windowWidth, y + windowHeight);
        mMirrorViewBounds.set(x, y, x + windowWidth, y + windowHeight);


        AccessibilityManager accessibilityManager = mContext
        AccessibilityManager accessibilityManager = mContext
                .getSystemService(AccessibilityManager.class);
                .getSystemService(AccessibilityManager.class);
        accessibilityManager.attachAccessibilityOverlayToDisplay(mDisplayId, surfaceControl);
        accessibilityManager.attachAccessibilityOverlayToDisplay(mDisplayId, mMirrorViewLeash);


        SurfaceHolder holder = mMirrorSurfaceView.getHolder();
        SurfaceHolder holder = mMirrorSurfaceView.getHolder();
        holder.addCallback(this);
        holder.addCallback(this);
@@ -964,13 +974,11 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold
            params.width = width;
            params.width = width;
            params.height = height;
            params.height = height;
            mSurfaceControlViewHost.relayout(params);
            mSurfaceControlViewHost.relayout(params);
            mTransaction.setCrop(mSurfaceControlViewHost.getSurfacePackage().getSurfaceControl(),
            mTransaction.setCrop(mMirrorViewLeash, new Rect(0, 0, width, height));
                    new Rect(0, 0, width, height));
        }
        }


        mMirrorViewBounds.set(x, y, x + width, y + height);
        mMirrorViewBounds.set(x, y, x + width, y + height);
        mTransaction.setPosition(
        mTransaction.setPosition(mMirrorViewLeash, x, y);
                mSurfaceControlViewHost.getSurfacePackage().getSurfaceControl(), x, y);
        if (computeWindowSize) {
        if (computeWindowSize) {
            mSurfaceControlViewHost.getRootSurfaceControl().applyTransactionOnDraw(mTransaction);
            mSurfaceControlViewHost.getRootSurfaceControl().applyTransactionOnDraw(mTransaction);
        } else {
        } else {
+5 −0
Original line number Original line Diff line number Diff line
@@ -69,6 +69,7 @@ import static com.android.internal.util.function.pooled.PooledLambda.obtainMessa
import static com.android.server.accessibility.AccessibilityUserState.doesShortcutTargetsStringContain;
import static com.android.server.accessibility.AccessibilityUserState.doesShortcutTargetsStringContain;
import static com.android.server.pm.UserManagerService.enforceCurrentUserIfVisibleBackgroundEnabled;
import static com.android.server.pm.UserManagerService.enforceCurrentUserIfVisibleBackgroundEnabled;
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import static com.android.window.flags.Flags.scvhSurfaceControlLifetimeFix;


import android.accessibilityservice.AccessibilityGestureEvent;
import android.accessibilityservice.AccessibilityGestureEvent;
import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.AccessibilityService;
@@ -6774,6 +6775,10 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
            result = AccessibilityService.OVERLAY_RESULT_SUCCESS;
            result = AccessibilityService.OVERLAY_RESULT_SUCCESS;
        }
        }


        if (scvhSurfaceControlLifetimeFix()) {
            sc.release();
        }

        if (callback != null) {
        if (callback != null) {
            // Send the result back to the service.
            // Send the result back to the service.
            try {
            try {