Loading core/java/android/accessibilityservice/UiTestAutomationBridge.java +27 −1 Original line number Diff line number Diff line Loading @@ -63,6 +63,8 @@ public class UiTestAutomationBridge { private AccessibilityEvent mLastEvent; private AccessibilityEvent mLastWindowStateChangeEvent; private volatile boolean mWaitingForEventDelivery; private volatile boolean mUnprocessedEventAvailable; Loading Loading @@ -138,12 +140,22 @@ public class UiTestAutomationBridge { public void onAccessibilityEvent(AccessibilityEvent event) { synchronized (mLock) { while (true) { mLastEvent = AccessibilityEvent.obtain(event); final int eventType = event.getEventType(); if (eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED || eventType == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) { if (mLastWindowStateChangeEvent != null) { mLastWindowStateChangeEvent.recycle(); } mLastWindowStateChangeEvent = mLastEvent; } if (!mWaitingForEventDelivery) { break; } if (!mUnprocessedEventAvailable) { mUnprocessedEventAvailable = true; mLastEvent = AccessibilityEvent.obtain(event); mLock.notifyAll(); break; } Loading Loading @@ -409,6 +421,20 @@ public class UiTestAutomationBridge { accessibilityWindowId, accessibilityNodeId, action); } /** * Gets the root {@link AccessibilityNodeInfo} in the active window. * * @return The root info. */ public AccessibilityNodeInfo getRootAccessibilityNodeInfoInActiveWindow() { synchronized (mLock) { if (mLastWindowStateChangeEvent != null) { return mLastWindowStateChangeEvent.getSource(); } } return null; } private void ensureValidConnection(int connectionId) { if (connectionId == AccessibilityInteractionClient.NO_ID) { throw new IllegalStateException("UiAutomationService not connected." Loading core/tests/coretests/src/android/accessibilityservice/InterrogationActivityTest.java +31 −0 Original line number Diff line number Diff line Loading @@ -430,4 +430,35 @@ public class InterrogationActivityTest } } } @LargeTest public void testGetRootAccessibilityNodeInfoInActiveWindow() throws Exception { final long startTimeMillis = SystemClock.uptimeMillis(); try { // get the root via the designated API AccessibilityNodeInfo fetched = mUiTestAutomationBridge .getRootAccessibilityNodeInfoInActiveWindow(); assertNotNull(fetched); // get the root via traversal AccessibilityNodeInfo expected = mUiTestAutomationBridge .findAccessibilityNodeInfoByViewIdInActiveWindow(R.id.root); while (true) { AccessibilityNodeInfo parent = expected.getParent(); if (parent == null) { break; } expected = parent; } assertNotNull(expected); assertEquals("The node with id \"root\" should be the root.", expected, fetched); } finally { if (DEBUG) { final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis; Log.i(LOG_TAG, "testGetRootAccessibilityNodeInfoInActiveWindow: " + elapsedTimeMillis + "ms"); } } } } Loading
core/java/android/accessibilityservice/UiTestAutomationBridge.java +27 −1 Original line number Diff line number Diff line Loading @@ -63,6 +63,8 @@ public class UiTestAutomationBridge { private AccessibilityEvent mLastEvent; private AccessibilityEvent mLastWindowStateChangeEvent; private volatile boolean mWaitingForEventDelivery; private volatile boolean mUnprocessedEventAvailable; Loading Loading @@ -138,12 +140,22 @@ public class UiTestAutomationBridge { public void onAccessibilityEvent(AccessibilityEvent event) { synchronized (mLock) { while (true) { mLastEvent = AccessibilityEvent.obtain(event); final int eventType = event.getEventType(); if (eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED || eventType == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) { if (mLastWindowStateChangeEvent != null) { mLastWindowStateChangeEvent.recycle(); } mLastWindowStateChangeEvent = mLastEvent; } if (!mWaitingForEventDelivery) { break; } if (!mUnprocessedEventAvailable) { mUnprocessedEventAvailable = true; mLastEvent = AccessibilityEvent.obtain(event); mLock.notifyAll(); break; } Loading Loading @@ -409,6 +421,20 @@ public class UiTestAutomationBridge { accessibilityWindowId, accessibilityNodeId, action); } /** * Gets the root {@link AccessibilityNodeInfo} in the active window. * * @return The root info. */ public AccessibilityNodeInfo getRootAccessibilityNodeInfoInActiveWindow() { synchronized (mLock) { if (mLastWindowStateChangeEvent != null) { return mLastWindowStateChangeEvent.getSource(); } } return null; } private void ensureValidConnection(int connectionId) { if (connectionId == AccessibilityInteractionClient.NO_ID) { throw new IllegalStateException("UiAutomationService not connected." Loading
core/tests/coretests/src/android/accessibilityservice/InterrogationActivityTest.java +31 −0 Original line number Diff line number Diff line Loading @@ -430,4 +430,35 @@ public class InterrogationActivityTest } } } @LargeTest public void testGetRootAccessibilityNodeInfoInActiveWindow() throws Exception { final long startTimeMillis = SystemClock.uptimeMillis(); try { // get the root via the designated API AccessibilityNodeInfo fetched = mUiTestAutomationBridge .getRootAccessibilityNodeInfoInActiveWindow(); assertNotNull(fetched); // get the root via traversal AccessibilityNodeInfo expected = mUiTestAutomationBridge .findAccessibilityNodeInfoByViewIdInActiveWindow(R.id.root); while (true) { AccessibilityNodeInfo parent = expected.getParent(); if (parent == null) { break; } expected = parent; } assertNotNull(expected); assertEquals("The node with id \"root\" should be the root.", expected, fetched); } finally { if (DEBUG) { final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis; Log.i(LOG_TAG, "testGetRootAccessibilityNodeInfoInActiveWindow: " + elapsedTimeMillis + "ms"); } } } }