From 3f92ffc369c31c98620e22b66366adb93c60a5f8 Mon Sep 17 00:00:00 2001 From: Svetoslav Date: Thu, 25 Sep 2014 16:48:53 -0700 Subject: [PATCH] Invalid active window if temporary disabling accessibility for test tools. If accessibility is enabled and a test tool based on the accessibility APIs connects to the system we suspend the current accessibility services while the tool is running (to avoid inteference as the tool is such a service) and after the tool disconnects we restore the accessibility state. The issue is that when clearing the accessibility state we were also wrongly clearing the active window. We are now careful to not clear the active window in such a case. It is also possible that the active window was never initilaized before the tool is run so now it is lazily loaded such that if we do not know which one it is, we get the one the has input focus. The definition of an active window is the one that has input focus or the user is touching. bug:17663432 Change-Id: I8868866a5126c590d3bddad099ababb97978227a --- .../accessibility/AccessibilityManagerService.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java index 008830d1a375c..4c00b7e6e941d 100644 --- a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java +++ b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java @@ -759,7 +759,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { } int getActiveWindowId() { - return mSecurityPolicy.mActiveWindowId; + return mSecurityPolicy.getActiveWindowId(); } void onTouchInteractionStart() { @@ -2822,7 +2822,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { private int resolveAccessibilityWindowIdLocked(int accessibilityWindowId) { if (accessibilityWindowId == AccessibilityNodeInfo.ACTIVE_WINDOW_ID) { - return mSecurityPolicy.mActiveWindowId; + return mSecurityPolicy.getActiveWindowId(); } return accessibilityWindowId; } @@ -3283,7 +3283,9 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { public void clearWindowsLocked() { List windows = Collections.emptyList(); + final int activeWindowId = mActiveWindowId; updateWindowsLocked(windows); + mActiveWindowId = activeWindowId; mWindows = null; } @@ -3496,6 +3498,13 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { } } + public int getActiveWindowId() { + if (mActiveWindowId == INVALID_WINDOW_ID && !mTouchInteractionInProgress) { + mActiveWindowId = getFocusedWindowId(); + } + return mActiveWindowId; + } + private void setActiveWindowLocked(int windowId) { if (mActiveWindowId != windowId) { mActiveWindowId = windowId;