diff options
author | Guang Zhu <guangzhu@google.com> | 2012-12-04 09:44:19 -0800 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2012-12-04 09:44:20 -0800 |
commit | a039cb0661fd589c81ec8b3caccdb02d6f241994 (patch) | |
tree | b3b634269500021f8eea3d54bab2dbdeb037a4e6 | |
parent | 1aae4a6a725af198ccac5c9f7c1fdc132328c5b2 (diff) | |
parent | 290a7fc7bccada1cbf6628e131be55b1358a6968 (diff) | |
download | sdk-a039cb0661fd589c81ec8b3caccdb02d6f241994.zip sdk-a039cb0661fd589c81ec8b3caccdb02d6f241994.tar.gz sdk-a039cb0661fd589c81ec8b3caccdb02d6f241994.tar.bz2 |
Merge "UI Automator Viewer improvements"
4 files changed, 42 insertions, 4 deletions
diff --git a/uiautomatorviewer/src/com/android/uiautomator/UiAutomatorHelper.java b/uiautomatorviewer/src/com/android/uiautomator/UiAutomatorHelper.java index 6011fed..8ead9de 100644 --- a/uiautomatorviewer/src/com/android/uiautomator/UiAutomatorHelper.java +++ b/uiautomatorviewer/src/com/android/uiautomator/UiAutomatorHelper.java @@ -20,6 +20,8 @@ import com.android.ddmlib.CollectingOutputReceiver; import com.android.ddmlib.IDevice; import com.android.ddmlib.RawImage; import com.android.ddmlib.SyncService; +import com.android.uiautomator.tree.BasicTreeNode; +import com.android.uiautomator.tree.RootWindowNode; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; @@ -41,6 +43,7 @@ public class UiAutomatorHelper { private static final String UIAUTOMATOR = "/system/bin/uiautomator"; //$NON-NLS-1$ private static final String UIAUTOMATOR_DUMP_COMMAND = "dump"; //$NON-NLS-1$ private static final String UIDUMP_DEVICE_PATH = "/data/local/tmp/uidump.xml"; //$NON-NLS-1$ + private static final int XML_CAPTURE_TIMEOUT_SEC = 40; private static boolean supportsUiAutomator(IDevice device) { String apiLevelString = device.getProperty(IDevice.PROP_BUILD_API_LEVEL); @@ -78,9 +81,11 @@ public class UiAutomatorHelper { CountDownLatch commandCompleteLatch = new CountDownLatch(1); try { - device.executeShellCommand(command, - new CollectingOutputReceiver(commandCompleteLatch)); - commandCompleteLatch.await(40, TimeUnit.SECONDS); + device.executeShellCommand( + command, + new CollectingOutputReceiver(commandCompleteLatch), + XML_CAPTURE_TIMEOUT_SEC * 1000); + commandCompleteLatch.await(XML_CAPTURE_TIMEOUT_SEC, TimeUnit.SECONDS); monitor.subTask("Pull UI XML snapshot from device..."); device.getSyncService().pullFile(UIDUMP_DEVICE_PATH, @@ -149,6 +154,13 @@ public class UiAutomatorHelper { throw new UiAutomatorException(msg, e); } + // rotate the screen shot per device rotation + BasicTreeNode root = model.getXmlRootNode(); + if (root instanceof RootWindowNode) { + for (int i = 0; i < ((RootWindowNode)root).getRotation(); i++) { + rawImage = rawImage.getRotated(); + } + } PaletteData palette = new PaletteData( rawImage.getRedMask(), rawImage.getGreenMask(), diff --git a/uiautomatorviewer/src/com/android/uiautomator/actions/ImageHelper.java b/uiautomatorviewer/src/com/android/uiautomator/actions/ImageHelper.java index c22f1fd..603b226 100644 --- a/uiautomatorviewer/src/com/android/uiautomator/actions/ImageHelper.java +++ b/uiautomatorviewer/src/com/android/uiautomator/actions/ImageHelper.java @@ -21,6 +21,7 @@ import org.eclipse.swt.SWTException; import org.eclipse.swt.graphics.ImageData; import org.eclipse.swt.graphics.ImageLoader; +import java.io.IOException; import java.io.InputStream; public class ImageHelper { @@ -32,6 +33,11 @@ public class ImageHelper { try { data = new ImageLoader().load(is); } catch (SWTException e) { + } finally { + try { + is.close(); + } catch (IOException e) { + } } if (data != null && data.length > 0) { return ImageDescriptor.createFromImageData(data[0]); diff --git a/uiautomatorviewer/src/com/android/uiautomator/tree/RootWindowNode.java b/uiautomatorviewer/src/com/android/uiautomator/tree/RootWindowNode.java index 27a21e4..d0e27c9 100644 --- a/uiautomatorviewer/src/com/android/uiautomator/tree/RootWindowNode.java +++ b/uiautomatorviewer/src/com/android/uiautomator/tree/RootWindowNode.java @@ -22,9 +22,15 @@ public class RootWindowNode extends BasicTreeNode { private final String mWindowName; private Object[] mCachedAttributesArray; + private int mRotation; public RootWindowNode(String windowName) { + this(windowName, 0); + } + + public RootWindowNode(String windowName, int rotation) { mWindowName = windowName; + mRotation = rotation; } @Override @@ -39,4 +45,8 @@ public class RootWindowNode extends BasicTreeNode { } return mCachedAttributesArray; } + + public int getRotation() { + return mRotation; + } } diff --git a/uiautomatorviewer/src/com/android/uiautomator/tree/UiHierarchyXmlLoader.java b/uiautomatorviewer/src/com/android/uiautomator/tree/UiHierarchyXmlLoader.java index f2339d1..2e897d9 100644 --- a/uiautomatorviewer/src/com/android/uiautomator/tree/UiHierarchyXmlLoader.java +++ b/uiautomatorviewer/src/com/android/uiautomator/tree/UiHierarchyXmlLoader.java @@ -73,7 +73,17 @@ public class UiHierarchyXmlLoader { // will be the parent of the element that is being started here mParentNode = mWorkingNode; if ("hierarchy".equals(qName)) { - mWorkingNode = new RootWindowNode(attributes.getValue("windowName")); + int rotation = 0; + for (int i = 0; i < attributes.getLength(); i++) { + if ("rotation".equals(attributes.getQName(i))) { + try { + rotation = Integer.parseInt(attributes.getValue(i)); + } catch (NumberFormatException nfe) { + // do nothing + } + } + } + mWorkingNode = new RootWindowNode(attributes.getValue("windowName"), rotation); nodeCreated = true; } else if ("node".equals(qName)) { UiNode tmpNode = new UiNode(); |