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

Commit d2ddae2f authored by Ameer Armaly's avatar Ameer Armaly Committed by Android (Google) Code Review
Browse files

Merge "Clean up a11y overlays after service exits or crashes." into main

parents 4a5c38d8 c8c4439b
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -9,6 +9,13 @@ flag {
    bug: "297972548"
}

flag {
    name: "cleanup_a11y_overlays"
    namespace: "accessibility"
    description: "Removes all attached accessibility overlays when a service is removed."
    bug: "271490102"
}

flag {
    name: "deprecate_package_list_observer"
    namespace: "accessibility"
+20 −0
Original line number Diff line number Diff line
@@ -224,6 +224,9 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ

    final SparseArray<IBinder> mOverlayWindowTokens = new SparseArray();

    // All the embedded accessibility overlays that have been added by this service.
    private List<SurfaceControl> mOverlays = new ArrayList<>();

    /** The timestamp of requesting to take screenshot in milliseconds */
    private long mRequestTakeScreenshotTimestampMs;
    /**
@@ -1554,6 +1557,9 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
            final int displayId = displays[i].getDisplayId();
            onDisplayRemoved(displayId);
        }
        if (Flags.cleanupA11yOverlays()) {
            detachAllOverlays();
        }
    }

    /**
@@ -2677,6 +2683,7 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
        try {
            mSystemSupport.attachAccessibilityOverlayToDisplay(
                    interactionId, displayId, sc, callback);
            mOverlays.add(sc);
        } finally {
            Binder.restoreCallingIdentity(identity);
        }
@@ -2707,10 +2714,23 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
                connection
                        .getRemote()
                        .attachAccessibilityOverlayToWindow(sc, interactionId, callback);
                mOverlays.add(sc);
            }

        } finally {
            Binder.restoreCallingIdentity(identity);
        }
    }

    protected void detachAllOverlays() {
        SurfaceControl.Transaction t = new SurfaceControl.Transaction();
        for (SurfaceControl sc : mOverlays) {
            if (sc.isValid()) {
                t.reparent(sc, null);
            }
        }
        t.apply();
        t.close();
        mOverlays.clear();
    }
}