diff --git a/lib/devices/android/bootstrap/src/io/appium/android/bootstrap/handler/DumpWindowHierarchy.java b/lib/devices/android/bootstrap/src/io/appium/android/bootstrap/handler/DumpWindowHierarchy.java index 6ea4aa577..10726de0d 100644 --- a/lib/devices/android/bootstrap/src/io/appium/android/bootstrap/handler/DumpWindowHierarchy.java +++ b/lib/devices/android/bootstrap/src/io/appium/android/bootstrap/handler/DumpWindowHierarchy.java @@ -7,6 +7,7 @@ import io.appium.android.bootstrap.Logger; import java.io.File; +import android.os.Build; import android.os.Environment; import android.os.SystemClock; @@ -19,56 +20,54 @@ import com.android.uiautomator.core.UiDevice; * /library/core-src/com/android/uiautomator/core/UiDevice.java */ public class DumpWindowHierarchy extends CommandHandler { - public static DumpWindowHierarchy instance = null; + public static DumpWindowHierarchy instance = null; - // 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); - private static boolean compressed = false; + // 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); + private static boolean compressed = false; - public static boolean isCompressed() { - return compressed; - } - - public static void setCompressed(final boolean compress) { - compressed = compress; - } - - /* - * @param command The {@link AndroidCommand} used for this handler. - * - * @return {@link AndroidCommandResult} - * - * @throws JSONException - * - * @see io.appium.android.bootstrap.CommandHandler#execute(io.appium.android. - * bootstrap.AndroidCommand) - */ - @Override - public AndroidCommandResult execute(final AndroidCommand command) { - dumpFolder.mkdirs(); - - if (dumpFile.exists()) { - dumpFile.delete(); + public static boolean isCompressed() { + return compressed; } - Logger.debug("dumpWindowHierarchy. Compressed? " + compressed); - - UiDevice.getInstance().setCompressedLayoutHeirarchy(compressed); - UiDevice.getInstance().dumpWindowHierarchy(dumpFileName); - - if (!dumpFile.exists()) { - SystemClock.sleep(1000); - UiDevice.getInstance().dumpWindowHierarchy(dumpFileName); + public static void setCompressed(final boolean compress) { + compressed = compress; } - return getSuccessResult(dumpFile.exists()); - } + /* + * @param command The {@link AndroidCommand} used for this handler. + * + * @return {@link AndroidCommandResult} + * + * @throws JSONException + * + * @see io.appium.android.bootstrap.CommandHandler#execute(io.appium.android. + * bootstrap.AndroidCommand) + */ + @Override + public AndroidCommandResult execute(final AndroidCommand command) { + dumpFolder.mkdirs(); + + if (dumpFile.exists()) { + dumpFile.delete(); + } + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + Logger.debug("dumpWindowHierarchy. Compressed? " + compressed); + UiDevice.getInstance().setCompressedLayoutHeirarchy(compressed); + } + + UiDevice.getInstance().dumpWindowHierarchy(dumpFileName); + + if (!dumpFile.exists()) { + SystemClock.sleep(1000); + UiDevice.getInstance().dumpWindowHierarchy(dumpFileName); + } + + return getSuccessResult(dumpFile.exists()); + } } \ No newline at end of file