Skip to content

Commit

Permalink
sync watched, to prevent watchers.remove error
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Jun 26, 2018
1 parent babc434 commit 6cc0b28
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import android.support.test.uiautomator.UiDevice;
import android.view.accessibility.AccessibilityEvent;

import java.util.HashSet;

/**
* Used to skip apk auto install && permission popups
* Called in method: setPermissionPatterns
Expand All @@ -19,16 +21,19 @@ public class AccessibilityEventListener implements UiAutomation.OnAccessibilityE
public Boolean triggerWatchers = false;
public long toastTime;

private HashSet<String> watchers;
private static AccessibilityEventListener instance;
private UiDevice device;

public AccessibilityEventListener(UiDevice device) {
public AccessibilityEventListener(UiDevice device, HashSet<String> watchers) {
this.device = device;
this.watchers = watchers;
AccessibilityEventListener.instance = this;
}

public static AccessibilityEventListener getInstance() {
if (instance == null) {
instance = new AccessibilityEventListener(UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()));
throw new RuntimeException(); // Must be init first.
}
return instance;
}
Expand All @@ -40,7 +45,9 @@ public void onAccessibilityEvent(final AccessibilityEvent event) {
}
if ((event.getEventType() & (AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED | AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED)) != 0) {
if (triggerWatchers) {
device.runWatchers();
synchronized (watchers) {
device.runWatchers();
}
}
} else if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
Parcelable parcelable = event.getParcelableData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public AutomatorServiceImpl() {

// default uiAutomation serviceInfo.eventTypes is -1
// I guess this might be watch all eventTypes
uiAutomation.setOnAccessibilityEventListener(AccessibilityEventListener.getInstance());
uiAutomation.setOnAccessibilityEventListener(new AccessibilityEventListener(device, watchers));
}

/**
Expand Down

0 comments on commit 6cc0b28

Please sign in to comment.