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
This commit is contained in:
ryanlwlin
2022-04-14 23:15:50 +08:00
parent 5c554e289b
commit 4339880c1e
4 changed files with 23 additions and 3 deletions

View File

@@ -1661,7 +1661,7 @@ public class AccessibilityWindowManager {
if (traceWMEnabled()) {
logTraceWM("getFocusedWindowToken", "");
}
final IBinder token = mWindowManagerInternal.getFocusedWindowToken();
final IBinder token = mWindowManagerInternal.getFocusedWindowTokenFromWindowStates();
synchronized (mLock) {
return findWindowIdLocked(userId, token);
}

View File

@@ -432,6 +432,14 @@ public abstract class WindowManagerInternal {
*/
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.
*/

View File

@@ -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
public boolean isKeyguardLocked() {
return WindowManagerService.this.isKeyguardLocked();

View File

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