|
@@ -12,10 +12,14 @@ import android.content.ClipboardManager;
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
import android.os.Build;
|
|
import android.os.Build;
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
|
|
+import android.os.Parcel;
|
|
import android.util.Log;
|
|
import android.util.Log;
|
|
import android.view.accessibility.AccessibilityEvent;
|
|
import android.view.accessibility.AccessibilityEvent;
|
|
import android.view.accessibility.AccessibilityNodeInfo;
|
|
import android.view.accessibility.AccessibilityNodeInfo;
|
|
|
|
|
|
|
|
+import com.elvishew.xlog.XLog;
|
|
|
|
+import com.google.gson.Gson;
|
|
|
|
+
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
@@ -37,18 +41,32 @@ public class USSDService extends AccessibilityService {
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
this.event = new AccessibilityEvent(event);
|
|
this.event = new AccessibilityEvent(event);
|
|
} else {
|
|
} else {
|
|
- this.event = event;
|
|
|
|
|
|
+ Parcel parcel = Parcel.obtain();
|
|
|
|
+ event.writeToParcel(parcel, 0);
|
|
|
|
+ parcel.setDataPosition(0);
|
|
|
|
+ AccessibilityEvent newEvent = AccessibilityEvent.CREATOR.createFromParcel(parcel);
|
|
|
|
+ parcel.recycle();
|
|
|
|
+ this.event = newEvent;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ XLog.i("USSDService Event Json : " + getEventNowRootInActiveWindow(event));
|
|
|
|
+ XLog.i(String.format("USSDService onAccessibilityEvent: [type] %s [class] %s [package] %s [time] %s [text] %s" +
|
|
|
|
+ " [ContentChangeTypes] %s [WindowChanges] %s",
|
|
|
|
+ event.getEventType(), event.getClassName(), event.getPackageName(),
|
|
|
|
+ event.getEventTime(), event.getText(), event.getContentChangeTypes(),event.getWindowChanges()));
|
|
|
|
|
|
if (USSDController.instance == null || !USSDController.instance.isRunning) {
|
|
if (USSDController.instance == null || !USSDController.instance.isRunning) {
|
|
|
|
+ XLog.e("USSDService Error : USSDController.instance = " + (USSDController.instance == null));
|
|
|
|
+ if (USSDController.instance != null) {
|
|
|
|
+ XLog.e("USSDService Error : USSDController.instance.isRunning = " + (USSDController.instance.isRunning));
|
|
|
|
+ }
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
String response = event.getText().toString();
|
|
String response = event.getText().toString();
|
|
if (LoginView(event) && notInputText(event)) {
|
|
if (LoginView(event) && notInputText(event)) {
|
|
- // first view or logView, do nothing, pass / FIRST MESSAGE
|
|
|
|
|
|
+ XLog.i("USSDService: 1");
|
|
clickOnButton(event, 0);
|
|
clickOnButton(event, 0);
|
|
USSDController.instance.isRunning = false;
|
|
USSDController.instance.isRunning = false;
|
|
if (USSDController.instance.send)
|
|
if (USSDController.instance.send)
|
|
@@ -56,7 +74,7 @@ public class USSDService extends AccessibilityService {
|
|
else
|
|
else
|
|
USSDController.instance.callbackInvoke.over(response);
|
|
USSDController.instance.callbackInvoke.over(response);
|
|
} else if (problemView(event) || LoginView(event)) {
|
|
} else if (problemView(event) || LoginView(event)) {
|
|
- // deal down
|
|
|
|
|
|
+ XLog.i("USSDService: 2");
|
|
clickOnButton(event, 1);
|
|
clickOnButton(event, 1);
|
|
if (USSDController.instance.send)
|
|
if (USSDController.instance.send)
|
|
USSDController.instance.callbackMessage.over(response);
|
|
USSDController.instance.callbackMessage.over(response);
|
|
@@ -64,13 +82,9 @@ public class USSDService extends AccessibilityService {
|
|
USSDController.instance.callbackInvoke.over(response);
|
|
USSDController.instance.callbackInvoke.over(response);
|
|
|
|
|
|
} else if (isUSSDWidget(event)) {
|
|
} else if (isUSSDWidget(event)) {
|
|
- // ready for work
|
|
|
|
-// if (response.contains("\n")) {
|
|
|
|
-// response = response.substring(response.indexOf('\n') + 1);
|
|
|
|
-// }
|
|
|
|
|
|
+ XLog.i("USSDService: 3");
|
|
if (notInputText(event)) {
|
|
if (notInputText(event)) {
|
|
- // not more input panels / LAST MESSAGE
|
|
|
|
- // sent 'OK' button
|
|
|
|
|
|
+ XLog.i("USSDService: 4");
|
|
clickOnButton(event, 0);
|
|
clickOnButton(event, 0);
|
|
USSDController.instance.isRunning = false;
|
|
USSDController.instance.isRunning = false;
|
|
if (USSDController.instance.send)
|
|
if (USSDController.instance.send)
|
|
@@ -78,14 +92,14 @@ public class USSDService extends AccessibilityService {
|
|
else
|
|
else
|
|
USSDController.instance.callbackInvoke.over(response);
|
|
USSDController.instance.callbackInvoke.over(response);
|
|
} else {
|
|
} else {
|
|
- // sent option 1
|
|
|
|
- // USSDController.instance.callbackInvoke = null;
|
|
|
|
- // USSDController.instance.callbackMessage = null;
|
|
|
|
|
|
+ XLog.i("USSDService: 5");
|
|
if (USSDController.instance.send)
|
|
if (USSDController.instance.send)
|
|
USSDController.instance.callbackMessage.responseMessage(response);
|
|
USSDController.instance.callbackMessage.responseMessage(response);
|
|
else
|
|
else
|
|
USSDController.instance.callbackInvoke.responseInvoke(response);
|
|
USSDController.instance.callbackInvoke.responseInvoke(response);
|
|
}
|
|
}
|
|
|
|
+ } else {
|
|
|
|
+ XLog.e("USSDService Error : 未走进任何逻辑循环");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -162,7 +176,8 @@ public class USSDService extends AccessibilityService {
|
|
|| event.getClassName().equals("com.zte.mifavor.widget.AlertDialog")
|
|
|| event.getClassName().equals("com.zte.mifavor.widget.AlertDialog")
|
|
|| event.getClassName().equals("color.support.v7.app.AlertDialog")
|
|
|| event.getClassName().equals("color.support.v7.app.AlertDialog")
|
|
|| event.getClassName().equals("com.transsion.widgetslib.dialog.PromptDialog")
|
|
|| event.getClassName().equals("com.transsion.widgetslib.dialog.PromptDialog")
|
|
- || event.getClassName().equals("miuix.appcompat.app.AlertDialog"));
|
|
|
|
|
|
+ || event.getClassName().equals("miuix.appcompat.app.AlertDialog")
|
|
|
|
+ || event.getClassName().equals("androidx.appcompat.app.AlertDialog"));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -244,5 +259,115 @@ public class USSDService extends AccessibilityService {
|
|
Log.d(TAG, "onServiceConnected");
|
|
Log.d(TAG, "onServiceConnected");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static String getEventNowRootInActiveWindow(AccessibilityEvent event) {
|
|
|
|
+ String PageJson = "{}";
|
|
|
|
+ AccessibilityNodeInfo node = event.getSource();
|
|
|
|
+ if (node != null) {
|
|
|
|
+ NodeInfoWrapper nodeInfoWrapper = traverseNode(node);
|
|
|
|
+ Gson gson = new Gson();
|
|
|
|
+ PageJson = gson.toJson(nodeInfoWrapper);
|
|
|
|
+ }
|
|
|
|
+ return PageJson;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static class NodeInfoWrapper {
|
|
|
|
+ public String txt;
|
|
|
|
+ public String vId;
|
|
|
|
+ public String cName;
|
|
|
|
+ public String pName;
|
|
|
|
+ public int hashcode;
|
|
|
|
+ public int childCount;
|
|
|
|
+ //用于判断节点是否可以打开弹出窗口(popup)canOpenPopup()方法用于判断给定的节点是否具有打开弹出窗口的能力
|
|
|
|
+ public boolean canOpenPopup;
|
|
|
|
+ //判断节点是否对用户可见
|
|
|
|
+ public boolean visibleToUser;
|
|
|
|
+ //判断节点是否启用
|
|
|
|
+ public boolean isEnabled;
|
|
|
|
+ public String hintText;
|
|
|
|
+ //判断节点是否可点击
|
|
|
|
+ public boolean isClickable;
|
|
|
|
+ //判断节点是否可长按
|
|
|
|
+ public boolean isLongClickable;
|
|
|
|
+ //判断节点是否可编辑
|
|
|
|
+ public boolean isEditable;
|
|
|
|
+ //判断节点是否可选择
|
|
|
|
+ public boolean isCheckable;
|
|
|
|
+ //判断节点的选择状态
|
|
|
|
+ public boolean isChecked;
|
|
|
|
+ //判断节点是否具有焦点
|
|
|
|
+ public boolean focused;
|
|
|
|
+ //判断节点是否可滚动
|
|
|
|
+ public boolean scrollable;
|
|
|
|
+
|
|
|
|
+ public boolean isSelected;
|
|
|
|
+
|
|
|
|
+ public boolean isAccessibilityFocused;
|
|
|
|
+ public boolean isContentInvalid;
|
|
|
|
+ public boolean isContextClickable;
|
|
|
|
+ public boolean isDismissable;
|
|
|
|
+ public boolean isFocusable;
|
|
|
|
+ public boolean isFocused;
|
|
|
|
+ public boolean isHeading;
|
|
|
|
+ public boolean isImportantForAccessibility;
|
|
|
|
+ public boolean isMultiLine;
|
|
|
|
+ public boolean isPassword;
|
|
|
|
+ public boolean isScreenReaderFocusable;
|
|
|
|
+ public boolean isScrollable;
|
|
|
|
+ public boolean isShowingHintText;
|
|
|
|
+ public boolean isTextEntryKey;
|
|
|
|
+ public boolean isTextSelectable;
|
|
|
|
+ public boolean isVisibleToUser;
|
|
|
|
+ public List<NodeInfoWrapper> childNodes;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private static NodeInfoWrapper traverseNode(AccessibilityNodeInfo nodeInfo) {
|
|
|
|
+ NodeInfoWrapper nodeInfoWrapper = new NodeInfoWrapper();
|
|
|
|
+ nodeInfoWrapper.txt = nodeInfo.getText() != null ? nodeInfo.getText().toString() : "";
|
|
|
|
+ nodeInfoWrapper.vId = nodeInfo.getViewIdResourceName();
|
|
|
|
+ nodeInfoWrapper.cName = nodeInfo.getClassName().toString();
|
|
|
|
+ nodeInfoWrapper.pName = nodeInfo.getPackageName().toString();
|
|
|
|
+ nodeInfoWrapper.hashcode = nodeInfo.hashCode();
|
|
|
|
+ nodeInfoWrapper.childCount = nodeInfo.getChildCount();
|
|
|
|
+ nodeInfoWrapper.canOpenPopup = nodeInfo.canOpenPopup();
|
|
|
|
+ nodeInfoWrapper.visibleToUser = nodeInfo.isVisibleToUser();
|
|
|
|
+ nodeInfoWrapper.isEnabled = nodeInfo.isEnabled();
|
|
|
|
+ nodeInfoWrapper.hintText = nodeInfo.getHintText() != null ? nodeInfo.getText().toString() : "";
|
|
|
|
+ nodeInfoWrapper.isClickable = nodeInfo.isClickable();
|
|
|
|
+ nodeInfoWrapper.isLongClickable = nodeInfo.isLongClickable();
|
|
|
|
+ nodeInfoWrapper.isEditable = nodeInfo.isEditable();
|
|
|
|
+ nodeInfoWrapper.isCheckable = nodeInfo.isCheckable();
|
|
|
|
+ nodeInfoWrapper.isChecked = nodeInfo.isChecked();
|
|
|
|
+ nodeInfoWrapper.focused = nodeInfo.isFocused();
|
|
|
|
+ nodeInfoWrapper.scrollable = nodeInfo.isScrollable();
|
|
|
|
+ nodeInfoWrapper.isSelected = nodeInfo.isSelected();
|
|
|
|
+ nodeInfoWrapper.isAccessibilityFocused = nodeInfo.isAccessibilityFocused();
|
|
|
|
+ nodeInfoWrapper.isContentInvalid = nodeInfo.isContentInvalid();
|
|
|
|
+ nodeInfoWrapper.isContextClickable = nodeInfo.isContextClickable();
|
|
|
|
+ nodeInfoWrapper.isDismissable = nodeInfo.isDismissable();
|
|
|
|
+ nodeInfoWrapper.isFocusable = nodeInfo.isFocusable();
|
|
|
|
+ nodeInfoWrapper.isFocused = nodeInfo.isFocused();
|
|
|
|
+ nodeInfoWrapper.isHeading = nodeInfo.isHeading();
|
|
|
|
+ nodeInfoWrapper.isImportantForAccessibility = nodeInfo.isImportantForAccessibility();
|
|
|
|
+ nodeInfoWrapper.isMultiLine = nodeInfo.isMultiLine();
|
|
|
|
+ nodeInfoWrapper.isPassword = nodeInfo.isPassword();
|
|
|
|
+ nodeInfoWrapper.isScreenReaderFocusable = nodeInfo.isScreenReaderFocusable();
|
|
|
|
+ nodeInfoWrapper.isScrollable = nodeInfo.isScrollable();
|
|
|
|
+ nodeInfoWrapper.isShowingHintText = nodeInfo.isShowingHintText();
|
|
|
|
+ nodeInfoWrapper.isTextEntryKey = nodeInfo.isTextEntryKey();
|
|
|
|
+ nodeInfoWrapper.isVisibleToUser = nodeInfo.isVisibleToUser();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ List<NodeInfoWrapper> childNodes = new ArrayList<>();
|
|
|
|
+ for (int i = 0; i < nodeInfo.getChildCount(); i++) {
|
|
|
|
+ AccessibilityNodeInfo childNode = nodeInfo.getChild(i);
|
|
|
|
+ if (childNode != null) {
|
|
|
|
+ NodeInfoWrapper childNodeWrapper = traverseNode(childNode);
|
|
|
|
+ childNodes.add(childNodeWrapper);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ nodeInfoWrapper.childNodes = childNodes;
|
|
|
|
|
|
|
|
+ return nodeInfoWrapper;
|
|
|
|
+ }
|
|
}
|
|
}
|