Skip to content

Commit

Permalink
Improve DumpWindowHierarchy.java
Browse files Browse the repository at this point in the history
  • Loading branch information
bootstraponline authored and jlipps committed Apr 28, 2014
1 parent 4775ccc commit 567ffa2
Showing 1 changed file with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.File;

import android.os.Environment;
import android.os.SystemClock;

import com.android.uiautomator.core.UiDevice;

Expand All @@ -17,6 +18,14 @@
* /library/core-src/com/android/uiautomator/core/UiDevice.java
*/
public class DumpWindowHierarchy extends CommandHandler {
// Note that
// "new File(new File(Environment.getDataDirectory(), "local/tmp"), fileName)"
// is directly from the UiDevice.java source code.
private static final File dumpFolder = new File(
Environment.getDataDirectory(),
"local/tmp");
private static final String dumpFileName = "dump.xml";
private static final File dumpFile = new File(dumpFolder, dumpFileName);

/*
* @param command The {@link AndroidCommand} used for this handler.
Expand All @@ -30,17 +39,19 @@ public class DumpWindowHierarchy extends CommandHandler {
*/
@Override
public AndroidCommandResult execute(final AndroidCommand command) {
dumpFolder.mkdirs();

final String dumpXml = "dump.xml";
final File dump = new File(new File(Environment.getDataDirectory(),
"local/tmp"), dumpXml);
dump.mkdirs();
if (dumpFile.exists()) {
dumpFile.delete();
}

UiDevice.getInstance().dumpWindowHierarchy(dumpFileName);

if (dump.exists()) {
dump.delete();
if (!dumpFile.exists()) {
SystemClock.sleep(1000);
UiDevice.getInstance().dumpWindowHierarchy(dumpFileName);
}

UiDevice.getInstance().dumpWindowHierarchy(dumpXml);
return getSuccessResult(true);
return getSuccessResult(dumpFile.exists());
}
}

0 comments on commit 567ffa2

Please sign in to comment.