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

Commit 4339880c authored by ryanlwlin's avatar ryanlwlin
Browse files

Fix invalid active window if accessibility framework doesn't track

windows

If accessibility framework doesn't track windows, the active window
is updated when receving window_state_changed event. ViewRootImpl
sends this event when performing traversal first time, however the
focused window token is not updated yet from InputManagerService.
To fix the regression issue, we fallback to the legacy approach for
short term solution.

Test: atest android.accessibilityservice.cts
Bug: 228442331
Change-Id: I032a73b9f4cf408a5dd6cae8a87bd26131ebdbfa
parent 5c554e28
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -1661,7 +1661,7 @@ public class AccessibilityWindowManager {
        if (traceWMEnabled()) {
        if (traceWMEnabled()) {
            logTraceWM("getFocusedWindowToken", "");
            logTraceWM("getFocusedWindowToken", "");
        }
        }
        final IBinder token = mWindowManagerInternal.getFocusedWindowToken();
        final IBinder token = mWindowManagerInternal.getFocusedWindowTokenFromWindowStates();
        synchronized (mLock) {
        synchronized (mLock) {
            return findWindowIdLocked(userId, token);
            return findWindowIdLocked(userId, token);
        }
        }
+8 −0
Original line number Original line Diff line number Diff line
@@ -432,6 +432,14 @@ public abstract class WindowManagerInternal {
     */
     */
    public abstract IBinder getFocusedWindowToken();
    public abstract IBinder getFocusedWindowToken();


    /**
     * Gets the token of the window that has input focus. It is from the focused
     * {@link WindowState}.
     *
     * @return The token.
     */
    public abstract IBinder getFocusedWindowTokenFromWindowStates();

    /**
    /**
     * @return Whether the keyguard is engaged.
     * @return Whether the keyguard is engaged.
     */
     */
+12 −0
Original line number Original line Diff line number Diff line
@@ -7681,6 +7681,18 @@ public class WindowManagerService extends IWindowManager.Stub
            }
            }
        }
        }


        // TODO (b/229837707): Delete this method after changing the solution.
        @Override
        public IBinder getFocusedWindowTokenFromWindowStates() {
            synchronized (mGlobalLock) {
                final WindowState windowState = getFocusedWindowLocked();
                if (windowState != null) {
                    return windowState.mClient.asBinder();
                }
                return null;
            }
        }

        @Override
        @Override
        public boolean isKeyguardLocked() {
        public boolean isKeyguardLocked() {
            return WindowManagerService.this.isKeyguardLocked();
            return WindowManagerService.this.isKeyguardLocked();
+2 −2
Original line number Original line Diff line number Diff line
@@ -543,7 +543,7 @@ public class AccessibilityWindowManagerTest {
                mWindowInfos.get(Display.DEFAULT_DISPLAY).get(DEFAULT_FOCUSED_INDEX + 1).token;
                mWindowInfos.get(Display.DEFAULT_DISPLAY).get(DEFAULT_FOCUSED_INDEX + 1).token;
        final int eventWindowId = mA11yWindowManager.findWindowIdLocked(
        final int eventWindowId = mA11yWindowManager.findWindowIdLocked(
                USER_SYSTEM_ID, eventWindowToken);
                USER_SYSTEM_ID, eventWindowToken);
        when(mMockWindowManagerInternal.getFocusedWindowToken())
        when(mMockWindowManagerInternal.getFocusedWindowTokenFromWindowStates())
                .thenReturn(eventWindowToken);
                .thenReturn(eventWindowToken);


        final int noUse = 0;
        final int noUse = 0;
@@ -679,7 +679,7 @@ public class AccessibilityWindowManagerTest {
                mWindowInfos.get(Display.DEFAULT_DISPLAY).get(DEFAULT_FOCUSED_INDEX).token;
                mWindowInfos.get(Display.DEFAULT_DISPLAY).get(DEFAULT_FOCUSED_INDEX).token;
        final int defaultFocusWindowId = mA11yWindowManager.findWindowIdLocked(
        final int defaultFocusWindowId = mA11yWindowManager.findWindowIdLocked(
                USER_SYSTEM_ID, defaultFocusWinToken);
                USER_SYSTEM_ID, defaultFocusWinToken);
        when(mMockWindowManagerInternal.getFocusedWindowToken())
        when(mMockWindowManagerInternal.getFocusedWindowTokenFromWindowStates())
                .thenReturn(defaultFocusWinToken);
                .thenReturn(defaultFocusWinToken);
        final int newFocusWindowId = getWindowIdFromWindowInfosForDisplay(Display.DEFAULT_DISPLAY,
        final int newFocusWindowId = getWindowIdFromWindowInfosForDisplay(Display.DEFAULT_DISPLAY,
                DEFAULT_FOCUSED_INDEX + 1);
                DEFAULT_FOCUSED_INDEX + 1);