diff options
author | Allen Hair <allenhair@google.com> | 2013-10-03 15:36:17 -0700 |
---|---|---|
committer | Allen Hair <allenhair@google.com> | 2013-10-04 14:15:32 -0700 |
commit | 5fe6e7f321f02b08224fad72374ed041f459b411 (patch) | |
tree | 0fea3d827611728a5ce72348eb7333d88c14a151 | |
parent | 96f60dfd679b82b47fe3c1a1637a762ee87205a8 (diff) | |
download | uiautomator-5fe6e7f321f02b08224fad72374ed041f459b411.tar.gz |
Fixed UiDevice.dumpWindowHierarchy(..) to work under instrumentation
Filenames are now relative to the application's private internal storage
directory. The previous location /data/local/tmp is not writable when
running under instrumentation.
Also changed the function to support absolute paths.
Bug: 10788452
Change-Id: I2b797f3f6b820354b231b03395782f3e8e776519
3 files changed, 16 insertions, 29 deletions
diff --git a/core/com/android/uiautomator/core/AccessibilityNodeInfoDumper.java b/core/com/android/uiautomator/core/AccessibilityNodeInfoDumper.java index 63c51e8..1884e06 100644 --- a/core/com/android/uiautomator/core/AccessibilityNodeInfoDumper.java +++ b/core/com/android/uiautomator/core/AccessibilityNodeInfoDumper.java @@ -43,28 +43,6 @@ public class AccessibilityNodeInfoDumper { /** * Using {@link AccessibilityNodeInfo} this method will walk the layout hierarchy - * and generates an xml dump into the /data/local/window_dump.xml - * @param root The root accessibility node. - * @param rotation The rotaion of current display - * @param width The pixel width of current display - * @param height The pixel height of current display - */ - public static void dumpWindowToFile(AccessibilityNodeInfo root, int rotation, - int width, int height) { - File baseDir = new File(Environment.getDataDirectory(), "local"); - if (!baseDir.exists()) { - baseDir.mkdir(); - baseDir.setExecutable(true, false); - baseDir.setWritable(true, false); - baseDir.setReadable(true, false); - } - dumpWindowToFile(root, - new File(new File(Environment.getDataDirectory(), "local"), "window_dump.xml"), - rotation, width, height); - } - - /** - * Using {@link AccessibilityNodeInfo} this method will walk the layout hierarchy * and generates an xml dump to the location specified by <code>dumpFile</code> * @param root The root accessibility node. * @param dumpFile The file to dump to. diff --git a/core/com/android/uiautomator/core/UiDevice.java b/core/com/android/uiautomator/core/UiDevice.java index a930eb4..2a51109 100644 --- a/core/com/android/uiautomator/core/UiDevice.java +++ b/core/com/android/uiautomator/core/UiDevice.java @@ -58,7 +58,7 @@ public class UiDevice { private boolean mInWatcherContext = false; // provides access the {@link QueryController} and {@link InteractionController} - private UiAutomatorBridge mUiAutomationBridge; + private InstrumentationUiAutomatorBridge mUiAutomationBridge; // reference to self private static UiDevice sDevice; @@ -70,7 +70,7 @@ public class UiDevice { /** * @hide */ - public void initialize(UiAutomatorBridge uiAutomatorBridge) { + public void initialize(InstrumentationUiAutomatorBridge uiAutomatorBridge) { mUiAutomationBridge = uiAutomatorBridge; } @@ -82,7 +82,7 @@ public class UiDevice { * Provides access the {@link QueryController} and {@link InteractionController} * @return {@link ShellUiAutomatorBridge} */ - UiAutomatorBridge getAutomatorBridge() { + InstrumentationUiAutomatorBridge getAutomatorBridge() { if (mUiAutomationBridge == null) { throw new RuntimeException("UiDevice not initialized"); } @@ -752,7 +752,7 @@ public class UiDevice { /** * Helper method used for debugging to dump the current window's layout hierarchy. - * The file root location is /data/local/tmp + * Relative file paths are stored the application's internal private storage location. * * @param fileName * @since API Level 16 @@ -765,9 +765,14 @@ public class UiDevice { Display display = getAutomatorBridge().getDefaultDisplay(); Point size = new Point(); display.getSize(size); - AccessibilityNodeInfoDumper.dumpWindowToFile(root, - new File(new File(Environment.getDataDirectory(), "local/tmp"), fileName), - display.getRotation(), size.x, size.y); + File dumpFile = new File(fileName); + if (!dumpFile.isAbsolute()) { + dumpFile = getAutomatorBridge().getContext().getFileStreamPath(fileName); + } + AccessibilityNodeInfoDumper.dumpWindowToFile(root, dumpFile, display.getRotation(), + size.x, size.y); + Log.d(LOG_TAG, String.format("Saved window hierarchy to %s", + dumpFile.getAbsolutePath())); } } diff --git a/testrunner/com/android/uiautomator/core/InstrumentationUiAutomatorBridge.java b/testrunner/com/android/uiautomator/core/InstrumentationUiAutomatorBridge.java index 1d4fb93..34e6d23 100644 --- a/testrunner/com/android/uiautomator/core/InstrumentationUiAutomatorBridge.java +++ b/testrunner/com/android/uiautomator/core/InstrumentationUiAutomatorBridge.java @@ -57,4 +57,8 @@ public class InstrumentationUiAutomatorBridge extends UiAutomatorBridge { public long getSystemLongPressTime() { return ViewConfiguration.getLongPressTimeout(); } + + Context getContext() { + return mContext; + } } |