Merge pull request #2561 from bootstraponline/toggle

Try toggle discard again
This commit is contained in:
bootstraponline
2014-05-13 09:51:02 -07:00
4 changed files with 31 additions and 18 deletions
@@ -44,7 +44,6 @@ class SocketServer {
* @throws SocketServerException
*/
public SocketServer(final int port) throws SocketServerException {
NotImportantViews.discard(true); // must be set for API 18+
keepListening = true;
executor = new AndroidCommandExecutor();
try {
@@ -3,6 +3,7 @@ package io.appium.android.bootstrap.handler;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.CommandHandler;
import io.appium.android.bootstrap.utils.NotImportantViews;
import java.io.File;
@@ -21,22 +22,11 @@ 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);
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.
*
* @return {@link AndroidCommandResult}
*
* @throws JSONException
*
* @see io.appium.android.bootstrap.CommandHandler#execute(io.appium.android.
* bootstrap.AndroidCommand)
*/
@Override
public AndroidCommandResult execute(final AndroidCommand command) {
public static boolean dump() {
dumpFolder.mkdirs();
if (dumpFile.exists()) {
@@ -56,6 +46,22 @@ public class DumpWindowHierarchy extends CommandHandler {
}
}
return getSuccessResult(dumpFile.exists());
return 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) {
NotImportantViews.discard(true);
return getSuccessResult(dump());
}
}
@@ -15,6 +15,7 @@ import io.appium.android.bootstrap.exceptions.InvalidStrategyException;
import io.appium.android.bootstrap.exceptions.UiSelectorSyntaxException;
import io.appium.android.bootstrap.exceptions.UnallowedTagNameException;
import io.appium.android.bootstrap.selector.Strategy;
import io.appium.android.bootstrap.utils.NotImportantViews;
import io.appium.android.bootstrap.utils.UiSelectorParser;
import java.util.ArrayList;
@@ -187,7 +188,10 @@ public class Find extends CommandHandler {
+ " with the contextId: " + contextId);
if (strategy == Strategy.INDEX_PATHS) {
NotImportantViews.discard(true);
return findElementsByIndexPaths(text, multiple);
} else {
NotImportantViews.discard(false);
}
try {
@@ -8,10 +8,14 @@ public abstract class NotImportantViews {
// setCompressedLayoutHeirarchy doesn't exist on API <= 17
// http://developer.android.com/reference/android/accessibilityservice/AccessibilityServiceInfo.html#FLAG_INCLUDE_NOT_IMPORTANT_VIEWS
private static boolean canDiscard = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2;
private static boolean lastDiscard = false;
public static void discard(boolean discard) {
if (canDiscard) {
UiDevice.getInstance().setCompressedLayoutHeirarchy(discard);
if (discard != lastDiscard) {
UiDevice.getInstance().setCompressedLayoutHeirarchy(discard);
lastDiscard = discard;
}
}
}
}