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

Commit 91fc447f authored by Candice Lo's avatar Candice Lo Committed by Android (Google) Code Review
Browse files

Merge "Fix layer leak in a11y magnifier" into main

parents fe76d80f b664991f
Loading
Loading
Loading
Loading
+20 −12
Original line number Diff line number Diff line
@@ -169,6 +169,11 @@ class WindowMagnificationController implements View.OnTouchListener, SurfaceHold
     */
    private SurfaceControlViewHost mSurfaceControlViewHost;

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

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

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

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

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

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

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

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

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

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

        mMirrorViewBounds.set(x, y, x + width, y + height);
        mTransaction.setPosition(
                mSurfaceControlViewHost.getSurfacePackage().getSurfaceControl(), x, y);
        mTransaction.setPosition(mMirrorViewLeash, x, y);
        if (computeWindowSize) {
            mSurfaceControlViewHost.getRootSurfaceControl().applyTransactionOnDraw(mTransaction);
        } else {
+5 −0
Original line number 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.pm.UserManagerService.enforceCurrentUserIfVisibleBackgroundEnabled;
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import static com.android.window.flags.Flags.scvhSurfaceControlLifetimeFix;

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

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

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