-
Notifications
You must be signed in to change notification settings - Fork 133
/
AccessibilityEventListener.java
57 lines (49 loc) · 1.94 KB
/
AccessibilityEventListener.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.github.uiautomator.stub;
import android.app.Notification;
import android.app.UiAutomation;
import android.os.Parcelable;
import androidx.test.InstrumentationRegistry;
import androidx.test.uiautomator.UiDevice;
import android.view.accessibility.AccessibilityEvent;
import java.util.HashSet;
/**
* Used to skip apk auto install && permission popups
* Called in method: setPermissionPatterns
* <p>
* Created by hzsunshx on 2018/3/7.
*/
public class AccessibilityEventListener implements UiAutomation.OnAccessibilityEventListener {
public String toastMessage;
public Boolean triggerWatchers = false;
public long toastTime;
private HashSet<String> watchers;
private static AccessibilityEventListener instance;
private 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) {
throw new RuntimeException(); // Must be init first.
}
return instance;
}
@Override
public void onAccessibilityEvent(final AccessibilityEvent event) {
if (event.getPackageName() == null) {
return;
} else if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
Parcelable parcelable = event.getParcelableData();
if (!(parcelable instanceof Notification)) { // without Notification is Toast
String packageName = event.getPackageName().toString();
if (event.getText().size() > 0) {
this.toastTime = System.currentTimeMillis();
this.toastMessage = "" + event.getText().get(0);
Log.d("Toast:" + toastMessage + " Pkg:" + packageName + " Time:" + toastTime);
}
}
}
}
}