diff options
author | Svetoslav <svetoslavganov@google.com> | 2014-08-25 18:35:57 -0700 |
---|---|---|
committer | Svetoslav <svetoslavganov@google.com> | 2014-08-26 10:06:22 -0700 |
commit | 04cab1bcc46b05cbb72632c53ad83943f705b494 (patch) | |
tree | d061e238253fdf9f6b4e6cbcecb7e7459da6f4be /services/accessibility | |
parent | 4b4d7efe522b01237b842c23a1d92559fe412a6e (diff) | |
download | frameworks_base-04cab1bcc46b05cbb72632c53ad83943f705b494.zip frameworks_base-04cab1bcc46b05cbb72632c53ad83943f705b494.tar.gz frameworks_base-04cab1bcc46b05cbb72632c53ad83943f705b494.tar.bz2 |
Fix accessiblity CTS tests (framework).
1. An external contribution changed the ordering of views for
accessibility. While it attempted to fix a platform issue
for a comparator breaking transitivity, it changed the way
we order views and results in very unnatural accessibility
traversal order. It also broke CTS tets. This change tweaks
the comparator which fixes the tests and improves traversal
order.
2. If there is at least one accessibility service which cares
about windows we register a callback in the window manager
for window change notifications. We are updating the window
list on this callback. There was a case where if the service
requests window updates and immediately asks for the windows
it gets none as we have not received a callback from the
window manager yet. Now this call returns after we get the
callback in a timed fashion. This is consistent with how the
other introspection APIs work.
3. Window info objects are cached in the accessibility service
process. When putting them in the cache a cloning call was
missing resulting in some cases of clobbering windows given
to the client. For example, we get some windows, cache them,
and return these windows to the client. Now a call to clear
the cache arrives while the user processes the windows and
the client windows get clobbered.
4. Added API for checking if a window has accessiblity focus
to be consistent to the API we have to check whether this
window has input focus.
5. Removed some obsolete code.
bug:16402352
Change-Id: Ided6da4a82cc0fc703008c58a2dff0119a3ff317
Diffstat (limited to 'services/accessibility')
-rw-r--r-- | services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java | 134 |
1 files changed, 96 insertions, 38 deletions
diff --git a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java index b1f1954..4e2f52c 100644 --- a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java +++ b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java @@ -124,6 +124,8 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { // when that accessibility services are bound. private static final int WAIT_FOR_USER_STATE_FULLY_INITIALIZED_MILLIS = 3000; + private static final int WAIT_WINDOWS_TIMEOUT_MILLIS = 5000; + private static final String FUNCTION_REGISTER_UI_TEST_AUTOMATION_SERVICE = "registerUiTestAutomationService"; @@ -1367,6 +1369,8 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { if (mWindowsForAccessibilityCallback != null) { mWindowsForAccessibilityCallback = null; mWindowManagerService.setWindowsForAccessibilityCallback(null); + // Drop all windows we know about. + mSecurityPolicy.clearWindowsLocked(); } } @@ -1631,16 +1635,18 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { pw.println("}]"); pw.println(); } - final int windowCount = mSecurityPolicy.mWindows.size(); - for (int j = 0; j < windowCount; j++) { - if (j > 0) { - pw.append(','); - pw.println(); + if (mSecurityPolicy.mWindows != null) { + final int windowCount = mSecurityPolicy.mWindows.size(); + for (int j = 0; j < windowCount; j++) { + if (j > 0) { + pw.append(','); + pw.println(); + } + pw.append("Window["); + AccessibilityWindowInfo window = mSecurityPolicy.mWindows.get(j); + pw.append(window.toString()); + pw.append(']'); } - pw.append("Window["); - AccessibilityWindowInfo window = mSecurityPolicy.mWindows.get(j); - pw.append(window.toString()); - pw.append(']'); } } } @@ -1821,6 +1827,39 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { return -1; } + private void ensureWindowsAvailableTimed() { + synchronized (mLock) { + if (mSecurityPolicy.mWindows != null) { + return; + } + // If we have no registered callback, update the state we + // we may have to register one but it didn't happen yet. + if (mWindowsForAccessibilityCallback == null) { + UserState userState = getCurrentUserStateLocked(); + onUserStateChangedLocked(userState); + } + // We have no windows but do not care about them, done. + if (mWindowsForAccessibilityCallback == null) { + return; + } + + // Wait for the windows with a timeout. + final long startMillis = SystemClock.uptimeMillis(); + while (mSecurityPolicy.mWindows == null) { + final long elapsedMillis = SystemClock.uptimeMillis() - startMillis; + final long remainMillis = WAIT_WINDOWS_TIMEOUT_MILLIS - elapsedMillis; + if (remainMillis <= 0) { + return; + } + try { + mLock.wait(remainMillis); + } catch (InterruptedException ie) { + /* ignore */ + } + } + } + } + /** * This class represents an accessibility service. It stores all per service * data required for the service management, provides API for starting/stopping the @@ -1876,9 +1915,6 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { final KeyEventDispatcher mKeyEventDispatcher = new KeyEventDispatcher(); - final SparseArray<AccessibilityWindowInfo> mIntrospectedWindows = - new SparseArray<>(); - boolean mWasConnectedAndDied; // Handler only for dispatching accessibility events since we use event @@ -1946,10 +1982,6 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { & AccessibilityServiceInfo.FLAG_REQUEST_FILTER_KEY_EVENTS) != 0; mRetrieveInteractiveWindows = (info.flags & AccessibilityServiceInfo.FLAG_RETRIEVE_INTERACTIVE_WINDOWS) != 0; - - if (!mRetrieveInteractiveWindows) { - clearIntrospectedWindows(); - } } /** @@ -2065,6 +2097,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { @Override public List<AccessibilityWindowInfo> getWindows() { + ensureWindowsAvailableTimed(); synchronized (mLock) { // We treat calls from a profile as if made by its perent as profiles // share the accessibility state of the parent. The call below @@ -2087,7 +2120,6 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { AccessibilityWindowInfo windowClone = AccessibilityWindowInfo.obtain(window); windowClone.setConnectionId(mId); - mIntrospectedWindows.put(window.getId(), windowClone); windows.add(windowClone); } return windows; @@ -2096,6 +2128,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { @Override public AccessibilityWindowInfo getWindow(int windowId) { + ensureWindowsAvailableTimed(); synchronized (mLock) { // We treat calls from a profile as if made by its parent as profiles // share the accessibility state of the parent. The call below @@ -2115,7 +2148,6 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { if (window != null) { AccessibilityWindowInfo windowClone = AccessibilityWindowInfo.obtain(window); windowClone.setConnectionId(mId); - mIntrospectedWindows.put(windowId, windowClone); return windowClone; } return null; @@ -2607,19 +2639,10 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { } public void notifyClearAccessibilityNodeInfoCache() { - clearIntrospectedWindows(); mInvocationHandler.sendEmptyMessage( InvocationHandler.MSG_CLEAR_ACCESSIBILITY_CACHE); } - private void clearIntrospectedWindows() { - final int windowCount = mIntrospectedWindows.size(); - for (int i = windowCount - 1; i >= 0; i--) { - mIntrospectedWindows.valueAt(i).recycle(); - mIntrospectedWindows.removeAt(i); - } - } - private void notifyGestureInternal(int gestureId) { final IAccessibilityServiceClient listener; synchronized (mLock) { @@ -2955,6 +2978,9 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { // Let the policy update the focused and active windows. mSecurityPolicy.updateWindowsLocked(reportedWindows); + + // Someone may be waiting for the windows - advertise it. + mLock.notifyAll(); } } @@ -3130,7 +3156,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { | AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED | AccessibilityEvent.TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY; - public final List<AccessibilityWindowInfo> mWindows = new ArrayList<>(); + public List<AccessibilityWindowInfo> mWindows; public int mActiveWindowId = INVALID_WINDOW_ID; public int mFocusedWindowId = INVALID_WINDOW_ID; @@ -3185,7 +3211,17 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { } } + public void clearWindowsLocked() { + List<AccessibilityWindowInfo> windows = Collections.emptyList(); + updateWindowsLocked(windows); + mWindows = null; + } + public void updateWindowsLocked(List<AccessibilityWindowInfo> windows) { + if (mWindows == null) { + mWindows = new ArrayList<>(); + } + final int oldWindowCount = mWindows.size(); for (int i = oldWindowCount - 1; i >= 0; i--) { mWindows.remove(i).recycle(); @@ -3231,6 +3267,9 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { if (window.getId() == mActiveWindowId) { window.setActive(true); } + if (window.getId() == mAccessibilityFocusedWindowId) { + window.setAccessibilityFocused(true); + } } } @@ -3298,7 +3337,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { if (mAccessibilityFocusedWindowId != windowId) { mMainHandler.obtainMessage(MainHandler.MSG_CLEAR_ACCESSIBILITY_FOCUS, mAccessibilityFocusedWindowId, 0).sendToTarget(); - mAccessibilityFocusedWindowId = windowId; + mSecurityPolicy.setAccessibilityFocusedWindowLocked(windowId); mAccessibilityFocusNodeId = nodeId; } } @@ -3354,11 +3393,28 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { private void setActiveWindowLocked(int windowId) { if (mActiveWindowId != windowId) { mActiveWindowId = windowId; - final int windowCount = mWindows.size(); - for (int i = 0; i < windowCount; i++) { - AccessibilityWindowInfo window = mWindows.get(i); - window.setActive(window.getId() == windowId); + if (mWindows != null) { + final int windowCount = mWindows.size(); + for (int i = 0; i < windowCount; i++) { + AccessibilityWindowInfo window = mWindows.get(i); + window.setActive(window.getId() == windowId); + } + } + notifyWindowsChanged(); + } + } + + private void setAccessibilityFocusedWindowLocked(int windowId) { + if (mAccessibilityFocusedWindowId != windowId) { + mAccessibilityFocusedWindowId = windowId; + if (mWindows != null) { + final int windowCount = mWindows.size(); + for (int i = 0; i < windowCount; i++) { + AccessibilityWindowInfo window = mWindows.get(i); + window.setAccessibilityFocused(window.getId() == windowId); + } } + notifyWindowsChanged(); } } @@ -3444,11 +3500,13 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { } private AccessibilityWindowInfo findWindowById(int windowId) { - final int windowCount = mWindows.size(); - for (int i = 0; i < windowCount; i++) { - AccessibilityWindowInfo window = mWindows.get(i); - if (window.getId() == windowId) { - return window; + if (mWindows != null) { + final int windowCount = mWindows.size(); + for (int i = 0; i < windowCount; i++) { + AccessibilityWindowInfo window = mWindows.get(i); + if (window.getId() == windowId) { + return window; + } } } return null; |