summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllen Hair <allenhair@google.com>2015-04-13 16:25:42 -0700
committerAllen Hair <allenhair@google.com>2015-04-13 16:25:42 -0700
commitdba7bfd2343688ccff39cbedcd5997e3ae63138d (patch)
tree335d08b81cbc746a5e5b7d33dd4a2767a0366ae4
parentf5864b4551313517a3ef5d0c790b3bbecf1573fe (diff)
downloaduiautomator-dba7bfd2343688ccff39cbedcd5997e3ae63138d.tar.gz
Revert "Enable multi-window on devices with API level 21+."
This reverts commit f5864b4551313517a3ef5d0c790b3bbecf1573fe.
-rw-r--r--src/main/java/android/support/test/uiautomator/AccessibilityNodeInfoDumper.java5
-rw-r--r--src/main/java/android/support/test/uiautomator/ByMatcher.java44
-rw-r--r--src/main/java/android/support/test/uiautomator/UiDevice.java53
-rw-r--r--src/main/java/android/support/test/uiautomator/UiObject2.java7
-rw-r--r--tests/src/androidTest/java/android/support/test/uiautomator/tests/MultiWindowTests.java67
5 files changed, 35 insertions, 141 deletions
diff --git a/src/main/java/android/support/test/uiautomator/AccessibilityNodeInfoDumper.java b/src/main/java/android/support/test/uiautomator/AccessibilityNodeInfoDumper.java
index 7cc777d..589a780 100644
--- a/src/main/java/android/support/test/uiautomator/AccessibilityNodeInfoDumper.java
+++ b/src/main/java/android/support/test/uiautomator/AccessibilityNodeInfoDumper.java
@@ -46,9 +46,8 @@ class AccessibilityNodeInfoDumper {
serializer.startTag("", "hierarchy"); // TODO(allenhair): Should we use a namespace?
serializer.attribute("", "rotation", Integer.toString(device.getDisplayRotation()));
- for (AccessibilityNodeInfo root : device.getWindowRoots()) {
- dumpNodeRec(root, serializer, 0, device.getDisplayWidth(), device.getDisplayHeight());
- }
+ dumpNodeRec(device.getActiveWindowRoot(), serializer, 0, device.getDisplayWidth(),
+ device.getDisplayHeight());
serializer.endTag("", "hierarchy");
serializer.endDocument();
diff --git a/src/main/java/android/support/test/uiautomator/ByMatcher.java b/src/main/java/android/support/test/uiautomator/ByMatcher.java
index 62e9c47..3726f1a 100644
--- a/src/main/java/android/support/test/uiautomator/ByMatcher.java
+++ b/src/main/java/android/support/test/uiautomator/ByMatcher.java
@@ -16,7 +16,6 @@
package android.support.test.uiautomator;
-import android.os.SystemClock;
import android.util.Log;
import android.view.accessibility.AccessibilityNodeInfo;
@@ -41,7 +40,7 @@ class ByMatcher {
/**
* Constructs a new {@link ByMatcher} instance. Used by
- * {@link ByMatcher#findMatch(UiDevice, BySelector, AccessibilityNodeInfo...)} to store state information
+ * {@link ByMatcher#findMatch(AccessibilityNodeInfo, BySelector)} to store state information
* that does not change during recursive calls.
*
* @param selector The criteria used to determine if a {@link AccessibilityNodeInfo} is a match.
@@ -54,48 +53,37 @@ class ByMatcher {
}
/**
- * Traverses the {@link AccessibilityNodeInfo} hierarchy starting at each {@code root} and
- * returns the first node to match the {@code selector} criteria. <br />
- * <strong>Note:</strong> The caller must release the {@link AccessibilityNodeInfo} instance by
- * calling {@link AccessibilityNodeInfo#recycle()} to avoid leaking resources.
+ * Traverses the {@link AccessibilityNodeInfo} hierarchy starting at {@code root}, and returns
+ * the first node to match the {@code selector} criteria. <br />
+ * <strong>Note:</strong> The caller must release the {@link AccessibilityNodeInfo} instance
+ * by calling {@link AccessibilityNodeInfo#recycle()} to avoid leaking resources.
*
- * @param device A reference to the {@link UiDevice}.
+ * @param root The root {@link AccessibilityNodeInfo} from which to start the search.
* @param selector The {@link BySelector} criteria used to determine if a node is a match.
* @return The first {@link AccessibilityNodeInfo} which matched the search criteria.
*/
- static AccessibilityNodeInfo findMatch(UiDevice device, BySelector selector,
- AccessibilityNodeInfo... roots) {
+ static AccessibilityNodeInfo findMatch(UiDevice device, AccessibilityNodeInfo root,
+ BySelector selector) {
// TODO: Don't short-circuit when debugging, and warn if more than one match.
ByMatcher matcher = new ByMatcher(device, selector, true);
- for (AccessibilityNodeInfo root : roots) {
- List<AccessibilityNodeInfo> matches = matcher.findMatches(root);
- if (!matches.isEmpty()) {
- return matches.get(0);
- }
- }
- return null;
+ List<AccessibilityNodeInfo> matches = matcher.findMatches(root);
+ return matches.isEmpty() ? null : matches.get(0);
}
/**
- * Traverses the {@link AccessibilityNodeInfo} hierarchy starting at each {@code root} and
- * returns a list of nodes which match the {@code selector} criteria. <br />
+ * Traverses the {@link AccessibilityNodeInfo} hierarchy starting at {@code root}, and returns
+ * a list of nodes which match the {@code selector} criteria. <br />
* <strong>Note:</strong> The caller must release each {@link AccessibilityNodeInfo} instance
* by calling {@link AccessibilityNodeInfo#recycle()} to avoid leaking resources.
*
- * @param device A reference to the {@link UiDevice}.
+ * @param root The root {@link AccessibilityNodeInfo} from which to start the search.
* @param selector The {@link BySelector} criteria used to determine if a node is a match.
* @return A list containing all of the nodes which matched the search criteria.
*/
- static List<AccessibilityNodeInfo> findMatches(UiDevice device, BySelector selector,
- AccessibilityNodeInfo... roots) {
-
- List<AccessibilityNodeInfo> ret = new ArrayList<AccessibilityNodeInfo>();
- ByMatcher matcher = new ByMatcher(device, selector, false);
- for (AccessibilityNodeInfo root : roots) {
- ret.addAll(matcher.findMatches(root));
- }
- return ret;
+ static List<AccessibilityNodeInfo> findMatches(UiDevice device, AccessibilityNodeInfo root,
+ BySelector selector) {
+ return new ByMatcher(device, selector, false).findMatches(root);
}
/**
diff --git a/src/main/java/android/support/test/uiautomator/UiDevice.java b/src/main/java/android/support/test/uiautomator/UiDevice.java
index 6ec41e7..15996a6 100644
--- a/src/main/java/android/support/test/uiautomator/UiDevice.java
+++ b/src/main/java/android/support/test/uiautomator/UiDevice.java
@@ -16,7 +16,6 @@
package android.support.test.uiautomator;
-import android.accessibilityservice.AccessibilityServiceInfo;
import android.app.Instrumentation;
import android.app.UiAutomation;
import android.app.UiAutomation.AccessibilityEventFilter;
@@ -36,7 +35,6 @@ import android.view.KeyEvent;
import android.view.Surface;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
-import android.view.accessibility.AccessibilityWindowInfo;
import java.io.BufferedOutputStream;
import java.io.File;
@@ -94,25 +92,17 @@ public class UiDevice implements Searchable {
+ ("REL".equals(Build.VERSION.CODENAME) ? 0 : 1);
/**
- * @deprecated Should use {@link UiDevice#UiDevice(Instrumentation)} instead.
+ * @deprecated Should use {@link UiDevice#UiDevice(InstrumentationUiAutomatorBridge)} instead.
*/
@Deprecated
private UiDevice() {}
- /** Private constructor. Clients should use {@link UiDevice#getInstance(Instrumentation)}. */
+ /** Private constructor. Clients should use {@link UiDevice#getInstance(Context)}. */
private UiDevice(Instrumentation instrumentation) {
mInstrumentation = instrumentation;
- UiAutomation uiAutomation = instrumentation.getUiAutomation();
mUiAutomationBridge = new InstrumentationUiAutomatorBridge(
- instrumentation.getContext(), uiAutomation);
-
- // Enable multi-window support for API level 21 and up
- if (UiDevice.API_LEVEL_ACTUAL >= Build.VERSION_CODES.LOLLIPOP) {
- // Subscribe to window information
- AccessibilityServiceInfo info = uiAutomation.getServiceInfo();
- info.flags |= AccessibilityServiceInfo.FLAG_RETRIEVE_INTERACTIVE_WINDOWS;
- uiAutomation.setServiceInfo(info);
- }
+ instrumentation.getContext(),
+ instrumentation.getUiAutomation());
}
/**
@@ -151,7 +141,8 @@ public class UiDevice implements Searchable {
/** Returns whether there is a match for the given {@code selector} criteria. */
public boolean hasObject(BySelector selector) {
- AccessibilityNodeInfo node = ByMatcher.findMatch(this, selector, getWindowRoots());
+ QueryController qc = getAutomatorBridge().getQueryController();
+ AccessibilityNodeInfo node = ByMatcher.findMatch(this, qc.getRootNode(), selector);
if (node != null) {
node.recycle();
return true;
@@ -161,14 +152,17 @@ public class UiDevice implements Searchable {
/** Returns the first object to match the {@code selector} criteria. */
public UiObject2 findObject(BySelector selector) {
- AccessibilityNodeInfo node = ByMatcher.findMatch(this, selector, getWindowRoots());
+ QueryController qc = getAutomatorBridge().getQueryController();
+ AccessibilityNodeInfo node = ByMatcher.findMatch(this, qc.getRootNode(), selector);
return node != null ? new UiObject2(this, selector, node) : null;
}
/** Returns all objects that match the {@code selector} criteria. */
public List<UiObject2> findObjects(BySelector selector) {
List<UiObject2> ret = new ArrayList<UiObject2>();
- for (AccessibilityNodeInfo node : ByMatcher.findMatches(this, selector, getWindowRoots())) {
+
+ QueryController qc = getAutomatorBridge().getQueryController();
+ for (AccessibilityNodeInfo node : ByMatcher.findMatches(this, qc.getRootNode(), selector)) {
ret.add(new UiObject2(this, selector, node));
}
@@ -1067,27 +1061,8 @@ public class UiDevice implements Searchable {
return stdout.toString();
}
- /** Returns a list containing the root {@link AccessibilityNodeInfo}s for each active window */
- AccessibilityNodeInfo[] getWindowRoots() {
- waitForIdle();
-
- ArrayList<AccessibilityNodeInfo> ret = new ArrayList<AccessibilityNodeInfo>();
- // Support multi-window searches for API level 21 and up
- if (UiDevice.API_LEVEL_ACTUAL >= Build.VERSION_CODES.LOLLIPOP) {
- for (AccessibilityWindowInfo window : mInstrumentation.getUiAutomation().getWindows()) {
- AccessibilityNodeInfo root = window.getRoot();
-
- if (root == null) {
- Log.w(LOG_TAG, String.format("Skipping null root node for window: %s",
- window.toString()));
- continue;
- }
- ret.add(root);
- }
- // Prior to API level 21 we can only access the active window
- } else {
- ret.add(mInstrumentation.getUiAutomation().getRootInActiveWindow());
- }
- return ret.toArray(new AccessibilityNodeInfo[ret.size()]);
+ AccessibilityNodeInfo getActiveWindowRoot() {
+ QueryController qc = getAutomatorBridge().getQueryController();
+ return qc.getRootNode();
}
}
diff --git a/src/main/java/android/support/test/uiautomator/UiObject2.java b/src/main/java/android/support/test/uiautomator/UiObject2.java
index 027dbcc..9f135be 100644
--- a/src/main/java/android/support/test/uiautomator/UiObject2.java
+++ b/src/main/java/android/support/test/uiautomator/UiObject2.java
@@ -173,7 +173,7 @@ public class UiObject2 implements Searchable {
/** Returns whether there is a match for the given criteria under this object. */
public boolean hasObject(BySelector selector) {
AccessibilityNodeInfo node =
- ByMatcher.findMatch(mDevice, selector, getAccessibilityNodeInfo());
+ ByMatcher.findMatch(mDevice, getAccessibilityNodeInfo(), selector);
if (node != null) {
node.recycle();
return true;
@@ -186,7 +186,7 @@ public class UiObject2 implements Searchable {
*/
public UiObject2 findObject(BySelector selector) {
AccessibilityNodeInfo node =
- ByMatcher.findMatch(mDevice, selector, getAccessibilityNodeInfo());
+ ByMatcher.findMatch(mDevice, getAccessibilityNodeInfo(), selector);
return node != null ? new UiObject2(mDevice, selector, node) : null;
}
@@ -194,7 +194,7 @@ public class UiObject2 implements Searchable {
public List<UiObject2> findObjects(BySelector selector) {
List<UiObject2> ret = new ArrayList<UiObject2>();
for (AccessibilityNodeInfo node :
- ByMatcher.findMatches(mDevice, selector, getAccessibilityNodeInfo())) {
+ ByMatcher.findMatches(mDevice, getAccessibilityNodeInfo(), selector)) {
ret.add(new UiObject2(mDevice, selector, node));
}
@@ -616,7 +616,6 @@ public class UiObject2 implements Searchable {
throw new IllegalStateException("This object has already been recycled");
}
- mDevice.waitForIdle();
if (!mCachedNode.refresh()) {
mDevice.runWatchers();
diff --git a/tests/src/androidTest/java/android/support/test/uiautomator/tests/MultiWindowTests.java b/tests/src/androidTest/java/android/support/test/uiautomator/tests/MultiWindowTests.java
deleted file mode 100644
index abc4867..0000000
--- a/tests/src/androidTest/java/android/support/test/uiautomator/tests/MultiWindowTests.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.support.test.uiautomator.tests;
-
-import android.support.test.InstrumentationRegistry;
-import android.support.test.filters.SdkSuppress;
-import android.support.test.runner.AndroidJUnit4;
-import android.support.test.uiautomator.By;
-import android.support.test.uiautomator.UiDevice;
-
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith(AndroidJUnit4.class)
-public class MultiWindowTests {
-
- private UiDevice mDevice;
- private static final String TEST_APP = "android.support.test.uiautomator.testapp";
-
- @Before
- public void setUp() {
- mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
-
- mDevice.pressHome();
- mDevice.waitForIdle();
- }
-
- @Test
- @SdkSuppress(minSdkVersion=21)
- public void testHasBackButton() {
- Assert.assertTrue(mDevice.hasObject(By.res("com.android.systemui", "back")));
- }
-
- @Test
- @SdkSuppress(minSdkVersion=21)
- public void testHasHomeButton() {
- Assert.assertTrue(mDevice.hasObject(By.res("com.android.systemui", "home")));
- }
-
- @Test
- @SdkSuppress(minSdkVersion=21)
- public void testHasRecentsButton() {
- Assert.assertTrue(mDevice.hasObject(By.res("com.android.systemui", "recent_apps")));
- }
-
- @Test
- @SdkSuppress(minSdkVersion=21)
- public void testHasStatusBar() {
- Assert.assertTrue(mDevice.hasObject(By.res("com.android.systemui", "status_bar")));
- }
-} \ No newline at end of file