random click and gesture for android 7.0+!!!
This commit is contained in:
@@ -14,6 +14,8 @@ import java.util.Set;
|
||||
|
||||
public interface AccessibilityDelegate {
|
||||
|
||||
Set<Integer> ALL_EVENT_TYPES = null;
|
||||
|
||||
boolean onAccessibilityEvent(AccessibilityService service, AccessibilityEvent event);
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,41 +30,40 @@ public class AccessibilityInfoProvider implements AccessibilityDelegate {
|
||||
mPackageManager = packageManager;
|
||||
}
|
||||
|
||||
public synchronized String getLatestPackage() {
|
||||
public String getLatestPackage() {
|
||||
return mLatestPackage;
|
||||
}
|
||||
|
||||
public synchronized String getLatestActivity() {
|
||||
public String getLatestActivity() {
|
||||
return mLatestActivity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onAccessibilityEvent(AccessibilityService service, AccessibilityEvent event) {
|
||||
AccessibilityNodeInfo root = service.getRootInActiveWindow();
|
||||
if (root != null)
|
||||
setLatestComponent(root.getPackageName(), event.getClassName());
|
||||
else
|
||||
if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
|
||||
setLatestComponent(event.getPackageName(), event.getClassName());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Integer> getEventTypes() {
|
||||
return null;
|
||||
return ALL_EVENT_TYPES;
|
||||
}
|
||||
|
||||
private synchronized void setLatestComponent(CharSequence latestPackage, CharSequence latestClass) {
|
||||
if (latestPackage == null)
|
||||
private void setLatestComponent(CharSequence latestPackage, CharSequence latestClass) {
|
||||
if (latestPackage == null || latestClass == null)
|
||||
return;
|
||||
mLatestPackage = latestPackage.toString();
|
||||
if (latestClass == null)
|
||||
String latestPackageStr = latestPackage.toString();
|
||||
String latestClassStr = latestClass.toString();
|
||||
if (latestClassStr.startsWith("android.view.") || latestClassStr.startsWith("android.widget."))
|
||||
return;
|
||||
try {
|
||||
ComponentName componentName = new ComponentName(latestPackage.toString(), latestClass.toString());
|
||||
ActivityInfo activityInfo = mPackageManager.getActivityInfo(componentName, 0);
|
||||
mLatestActivity = activityInfo.name;
|
||||
ComponentName componentName = new ComponentName(latestPackageStr, latestClassStr);
|
||||
mLatestActivity = mPackageManager.getActivityInfo(componentName, 0).name;
|
||||
} catch (PackageManager.NameNotFoundException ignored) {
|
||||
|
||||
return;
|
||||
}
|
||||
mLatestPackage = latestPackage.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,23 @@ package com.stardust.view.accessibility;
|
||||
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/5/2.
|
||||
*/
|
||||
|
||||
public abstract class AccessibilityService extends android.accessibilityservice.AccessibilityService {
|
||||
|
||||
public interface NotificationCallback {
|
||||
void onNotification();
|
||||
}
|
||||
|
||||
private CopyOnWriteArrayList<NotificationCallback> mNotificationCallbacks = new CopyOnWriteArrayList<>();
|
||||
|
||||
@Override
|
||||
|
||||
public AccessibilityNodeInfo getRootInActiveWindow() {
|
||||
try {
|
||||
return super.getRootInActiveWindow();
|
||||
@@ -16,4 +26,5 @@ public abstract class AccessibilityService extends android.accessibilityservice.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user