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

Commit f65dc8fd authored by Hiroki Sato's avatar Hiroki Sato
Browse files

Refactor embedded window handling in AccessibilityWindowManager

Embedded windows are maintained globally, not per display.
This moves isEmbeddedHierarchyWindowsLocked method from
DisplayWindowManager to A11yWindowManager.

Bug: 322444245
Test: CtsAccessibilityServiceTestCases, AccessibilityWindowManagerTest
Change-Id: I5e4f1684439dc12035672c4ae8a328a8113b600c
parent 984306a8
Loading
Loading
Loading
Loading
+20 −18
Original line number Diff line number Diff line
@@ -818,7 +818,7 @@ public class AccessibilityWindowManager {
            }

            // Don't need to add the embedded hierarchy windows into the accessibility windows list.
            if (mHostEmbeddedMap.size() > 0 && isEmbeddedHierarchyWindowsLocked(windowId)) {
            if (isEmbeddedHierarchyWindowsLocked(windowId)) {
                return null;
            }
            final AccessibilityWindowInfo reportedWindow = AccessibilityWindowInfo.obtain();
@@ -866,21 +866,6 @@ public class AccessibilityWindowManager {
            return reportedWindow;
        }

        private boolean isEmbeddedHierarchyWindowsLocked(int windowId) {
            final IBinder leashToken = mWindowIdMap.get(windowId);
            if (leashToken == null) {
                return false;
            }

            for (int i = 0; i < mHostEmbeddedMap.size(); i++) {
                if (mHostEmbeddedMap.keyAt(i).equals(leashToken)) {
                    return true;
                }
            }

            return false;
        }

        private int getTypeForWindowManagerWindowType(int windowType) {
            switch (windowType) {
                case WindowManager.LayoutParams.TYPE_APPLICATION:
@@ -1490,7 +1475,7 @@ public class AccessibilityWindowManager {
     * @return The windowId of the parent window, or self if no parent exists
     */
    public int resolveParentWindowIdLocked(int windowId) {
        final IBinder token = getTokenLocked(windowId);
        final IBinder token = getLeashTokenLocked(windowId);
        if (token == null) {
            return windowId;
        }
@@ -2095,7 +2080,7 @@ public class AccessibilityWindowManager {
     * @param windowId The windowID.
     * @return The token, or {@code NULL} if this windowID doesn't exist
     */
    IBinder getTokenLocked(int windowId) {
    IBinder getLeashTokenLocked(int windowId) {
        return mWindowIdMap.get(windowId);
    }

@@ -2123,6 +2108,23 @@ public class AccessibilityWindowManager {
        return mHostEmbeddedMap.get(token);
    }

    /**
     * Checks if the window is embedded into another window so that the window should be excluded
     * from the exposed accessibility windows, and the node tree should be embedded in the host.
     */
    boolean isEmbeddedHierarchyWindowsLocked(int windowId) {
        if (mHostEmbeddedMap.size() == 0) {
            return false;
        }

        final IBinder leashToken = getLeashTokenLocked(windowId);
        if (leashToken == null) {
            return false;
        }

        return mHostEmbeddedMap.containsKey(leashToken);
    }

    /**
     * Checks if the window belongs to a proxy display and if so clears the focused window id.
     * @param focusClearedWindowId the cleared window id.
+2 −2
Original line number Diff line number Diff line
@@ -893,13 +893,13 @@ public class AccessibilityWindowManagerTest {

    @Test
    public void getTokenLocked_windowIsRegistered_shouldReturnToken() {
        final IBinder token = mA11yWindowManager.getTokenLocked(HOST_WINDOW_ID);
        final IBinder token = mA11yWindowManager.getLeashTokenLocked(HOST_WINDOW_ID);
        assertEquals(token, mMockHostToken);
    }

    @Test
    public void getTokenLocked_windowIsNotRegistered_shouldReturnNull() {
        final IBinder token = mA11yWindowManager.getTokenLocked(OTHER_WINDOW_ID);
        final IBinder token = mA11yWindowManager.getLeashTokenLocked(OTHER_WINDOW_ID);
        assertNull(token);
    }