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

Commit c8c4439b authored by Ameer Armaly's avatar Ameer Armaly
Browse files

Clean up a11y overlays after service exits or crashes.

Fix: 271490102
Test: atest AccessibilityOverlayTest
Change-Id: I1443d2c98c6ba4801a2e71b247fac7d662173bdf
parent e619e972
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();
    }
}