|
@@ -7,21 +7,20 @@
|
|
|
package com.romellfudi.ussdlibrary;
|
|
|
|
|
|
import android.accessibilityservice.AccessibilityService;
|
|
|
-import android.annotation.SuppressLint;
|
|
|
import android.content.ClipData;
|
|
|
import android.content.ClipboardManager;
|
|
|
import android.content.Context;
|
|
|
-import android.content.Intent;
|
|
|
import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
+import android.os.Handler;
|
|
|
+import android.os.Looper;
|
|
|
import android.os.Parcel;
|
|
|
-import android.telecom.PhoneAccountHandle;
|
|
|
-import android.telecom.TelecomManager;
|
|
|
-import android.telephony.TelephonyManager;
|
|
|
import android.util.Log;
|
|
|
import android.view.accessibility.AccessibilityEvent;
|
|
|
import android.view.accessibility.AccessibilityNodeInfo;
|
|
|
|
|
|
+import androidx.annotation.RequiresApi;
|
|
|
+
|
|
|
import com.elvishew.xlog.XLog;
|
|
|
import com.google.gson.Gson;
|
|
|
|
|
@@ -37,75 +36,81 @@ import java.util.List;
|
|
|
*/
|
|
|
public class USSDService extends AccessibilityService {
|
|
|
|
|
|
- private static String TAG = "USSDServiceUSSD";
|
|
|
+ private static final String TAG = "USSDServiceUSSD";
|
|
|
|
|
|
public static AccessibilityEvent event;
|
|
|
|
|
|
+ @RequiresApi(api = Build.VERSION_CODES.P)
|
|
|
@Override
|
|
|
public void onAccessibilityEvent(AccessibilityEvent event) {
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
|
- this.event = new AccessibilityEvent(event);
|
|
|
+ USSDService.event = new AccessibilityEvent(event);
|
|
|
} else {
|
|
|
Parcel parcel = Parcel.obtain();
|
|
|
event.writeToParcel(parcel, 0);
|
|
|
parcel.setDataPosition(0);
|
|
|
AccessibilityEvent newEvent = AccessibilityEvent.CREATOR.createFromParcel(parcel);
|
|
|
parcel.recycle();
|
|
|
- this.event = newEvent;
|
|
|
+ USSDService.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) {
|
|
|
- XLog.e("USSDService Error : USSDController.instance = " + (USSDController.instance == null));
|
|
|
- if (USSDController.instance != null) {
|
|
|
- XLog.e("USSDService Error : USSDController.instance.isRunning = " + (USSDController.instance.isRunning));
|
|
|
+ new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
|
|
+ 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) {
|
|
|
+ XLog.e("USSDService Error : USSDController == " + (USSDController.instance == null));
|
|
|
+ XLog.e("USSDService Error : USSDController.isRunning == " + (USSDController.instance.isRunning));
|
|
|
+// return;
|
|
|
}
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
- String response = event.getText().toString();
|
|
|
- if (LoginView(event) && notInputText(event)) {
|
|
|
- XLog.i("USSDService: 1");
|
|
|
- clickOnButton(event, 0);
|
|
|
- USSDController.instance.isRunning = false;
|
|
|
- if (USSDController.instance.send)
|
|
|
- USSDController.instance.callbackMessage.over(response);
|
|
|
- else
|
|
|
- USSDController.instance.callbackInvoke.over(response);
|
|
|
- } else if (problemView(event) || LoginView(event)) {
|
|
|
- XLog.i("USSDService: 2");
|
|
|
- clickOnButton(event, 1);
|
|
|
- if (USSDController.instance.send)
|
|
|
- USSDController.instance.callbackMessage.over(response);
|
|
|
- else
|
|
|
- USSDController.instance.callbackInvoke.over(response);
|
|
|
-
|
|
|
- } else if (isUSSDWidget(event)) {
|
|
|
- XLog.i("USSDService: 3");
|
|
|
- if (notInputText(event)) {
|
|
|
- XLog.i("USSDService: 4");
|
|
|
+ String response = event.getText().toString();
|
|
|
+ XLog.i("USSDService response = " + response);
|
|
|
+ if (LoginView(event) && notInputText(event)) {
|
|
|
+ XLog.i("USSDService: 1");
|
|
|
clickOnButton(event, 0);
|
|
|
USSDController.instance.isRunning = false;
|
|
|
if (USSDController.instance.send)
|
|
|
USSDController.instance.callbackMessage.over(response);
|
|
|
else
|
|
|
USSDController.instance.callbackInvoke.over(response);
|
|
|
- } else {
|
|
|
- XLog.i("USSDService: 5");
|
|
|
+ } else if (problemView(event) || LoginView(event)) {
|
|
|
+ XLog.i("USSDService: 2");
|
|
|
+ clickOnButton(event, 1);
|
|
|
if (USSDController.instance.send)
|
|
|
- USSDController.instance.callbackMessage.responseMessage(response);
|
|
|
+ USSDController.instance.callbackMessage.over(response);
|
|
|
else
|
|
|
- USSDController.instance.callbackInvoke.responseInvoke(response);
|
|
|
+ USSDController.instance.callbackInvoke.over(response);
|
|
|
+
|
|
|
+ } else if (isUSSDWidget(event)) {
|
|
|
+ XLog.i("USSDService: 3");
|
|
|
+ if (notInputText(event)) {
|
|
|
+ XLog.i("USSDService: 4");
|
|
|
+ clickOnButton(event, 0);
|
|
|
+ USSDController.instance.isRunning = false;
|
|
|
+ if (USSDController.instance.send)
|
|
|
+ USSDController.instance.callbackMessage.over(response);
|
|
|
+ else
|
|
|
+ USSDController.instance.callbackInvoke.over(response);
|
|
|
+ } else {
|
|
|
+ XLog.i("USSDService: 5");
|
|
|
+ if (USSDController.instance.send)
|
|
|
+ USSDController.instance.callbackMessage.responseMessage(response);
|
|
|
+ else
|
|
|
+ USSDController.instance.callbackInvoke.responseInvoke(response);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ XLog.e("USSDService Error : 未走进任何逻辑循环");
|
|
|
}
|
|
|
- } else {
|
|
|
- XLog.e("USSDService Error : 未走进任何逻辑循环");
|
|
|
- }
|
|
|
+ }, 2000); // 延迟 1 秒
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -161,8 +166,11 @@ public class USSDService extends AccessibilityService {
|
|
|
*/
|
|
|
protected static boolean notInputText(AccessibilityEvent event) {
|
|
|
boolean flag = true;
|
|
|
+ XLog.i("USSDService Event Json event.source = : " + event.getSource());
|
|
|
for (AccessibilityNodeInfo leaf : getLeaves(event)) {
|
|
|
- if (leaf.getClassName().equals("android.widget.EditText")) flag = false;
|
|
|
+ if (leaf.getClassName().equals("android.widget.EditText")) {
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
}
|
|
|
return flag;
|
|
|
}
|
|
@@ -270,6 +278,8 @@ public class USSDService extends AccessibilityService {
|
|
|
NodeInfoWrapper nodeInfoWrapper = traverseNode(node);
|
|
|
Gson gson = new Gson();
|
|
|
PageJson = gson.toJson(nodeInfoWrapper);
|
|
|
+ } else {
|
|
|
+ PageJson = PayController.getNowRootInActiveWindow();
|
|
|
}
|
|
|
return PageJson;
|
|
|
}
|
|
@@ -336,7 +346,9 @@ public class USSDService extends AccessibilityService {
|
|
|
nodeInfoWrapper.canOpenPopup = nodeInfo.canOpenPopup();
|
|
|
nodeInfoWrapper.visibleToUser = nodeInfo.isVisibleToUser();
|
|
|
nodeInfoWrapper.isEnabled = nodeInfo.isEnabled();
|
|
|
- nodeInfoWrapper.hintText = nodeInfo.getHintText() != null ? nodeInfo.getText().toString() : "";
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
+ nodeInfoWrapper.hintText = nodeInfo.getHintText() != null ? nodeInfo.getText().toString() : "";
|
|
|
+ }
|
|
|
nodeInfoWrapper.isClickable = nodeInfo.isClickable();
|
|
|
nodeInfoWrapper.isLongClickable = nodeInfo.isLongClickable();
|
|
|
nodeInfoWrapper.isEditable = nodeInfo.isEditable();
|
|
@@ -347,18 +359,30 @@ public class USSDService extends AccessibilityService {
|
|
|
nodeInfoWrapper.isSelected = nodeInfo.isSelected();
|
|
|
nodeInfoWrapper.isAccessibilityFocused = nodeInfo.isAccessibilityFocused();
|
|
|
nodeInfoWrapper.isContentInvalid = nodeInfo.isContentInvalid();
|
|
|
- nodeInfoWrapper.isContextClickable = nodeInfo.isContextClickable();
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
+ nodeInfoWrapper.isContextClickable = nodeInfo.isContextClickable();
|
|
|
+ }
|
|
|
nodeInfoWrapper.isDismissable = nodeInfo.isDismissable();
|
|
|
nodeInfoWrapper.isFocusable = nodeInfo.isFocusable();
|
|
|
nodeInfoWrapper.isFocused = nodeInfo.isFocused();
|
|
|
- nodeInfoWrapper.isHeading = nodeInfo.isHeading();
|
|
|
- nodeInfoWrapper.isImportantForAccessibility = nodeInfo.isImportantForAccessibility();
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
|
|
+ nodeInfoWrapper.isHeading = nodeInfo.isHeading();
|
|
|
+ }
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
|
+ nodeInfoWrapper.isImportantForAccessibility = nodeInfo.isImportantForAccessibility();
|
|
|
+ }
|
|
|
nodeInfoWrapper.isMultiLine = nodeInfo.isMultiLine();
|
|
|
nodeInfoWrapper.isPassword = nodeInfo.isPassword();
|
|
|
- nodeInfoWrapper.isScreenReaderFocusable = nodeInfo.isScreenReaderFocusable();
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
|
|
+ nodeInfoWrapper.isScreenReaderFocusable = nodeInfo.isScreenReaderFocusable();
|
|
|
+ }
|
|
|
nodeInfoWrapper.isScrollable = nodeInfo.isScrollable();
|
|
|
- nodeInfoWrapper.isShowingHintText = nodeInfo.isShowingHintText();
|
|
|
- nodeInfoWrapper.isTextEntryKey = nodeInfo.isTextEntryKey();
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
+ nodeInfoWrapper.isShowingHintText = nodeInfo.isShowingHintText();
|
|
|
+ }
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
|
+ nodeInfoWrapper.isTextEntryKey = nodeInfo.isTextEntryKey();
|
|
|
+ }
|
|
|
nodeInfoWrapper.isVisibleToUser = nodeInfo.isVisibleToUser();
|
|
|
|
|
|
|