|
@@ -12,8 +12,6 @@ import android.content.ClipboardManager;
|
|
|
import android.content.Context;
|
|
|
import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
-import android.os.Handler;
|
|
|
-import android.os.Looper;
|
|
|
import android.os.Parcel;
|
|
|
import android.util.Log;
|
|
|
import android.view.accessibility.AccessibilityEvent;
|
|
@@ -37,16 +35,21 @@ import java.util.Locale;
|
|
|
* @since 1.0.a
|
|
|
*/
|
|
|
public class USSDService extends AccessibilityService {
|
|
|
-
|
|
|
- private static final String TAG = "USSDServiceUSSD";
|
|
|
-
|
|
|
public static AccessibilityEvent event;
|
|
|
|
|
|
@RequiresApi(api = Build.VERSION_CODES.P)
|
|
|
@Override
|
|
|
public void onAccessibilityEvent(AccessibilityEvent event) {
|
|
|
+ if (USSDService.event != null) {
|
|
|
+ USSDService.event.recycle();
|
|
|
+ }
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
|
- USSDService.event = new AccessibilityEvent(event);
|
|
|
+ try {
|
|
|
+ USSDService.event = new AccessibilityEvent(event);
|
|
|
+ } catch (Exception e) {
|
|
|
+ XLog.e("USSDService Error : 复制Ussd event 失败", e);
|
|
|
+ }
|
|
|
+
|
|
|
} else {
|
|
|
Parcel parcel = Parcel.obtain();
|
|
|
event.writeToParcel(parcel, 0);
|
|
@@ -55,7 +58,21 @@ public class USSDService extends AccessibilityService {
|
|
|
parcel.recycle();
|
|
|
USSDService.event = newEvent;
|
|
|
}
|
|
|
- XLog.i(String.format("USSDService onAccessibilityEvent: [type] %s [class] %s [package] %s [time] %s [text] %s [ContentChangeTypes] %s [WindowChanges] %s",
|
|
|
+
|
|
|
+ if (USSDController.instance == null || !USSDController.instance.isRunning) {
|
|
|
+ XLog.e("USSDService Error : USSDController.instance 是否为空? -> " + (USSDController.instance == null));
|
|
|
+ XLog.e("USSDService Error : USSDController.instance.isRunning? -> " + (USSDController.instance.isRunning));
|
|
|
+ }
|
|
|
+
|
|
|
+ String data = String.format("Ussd服务基本参数 -> " +
|
|
|
+ "onAccessibilityEvent: " +
|
|
|
+ "[type] %s " +
|
|
|
+ "[class] %s " +
|
|
|
+ "[package] %s " +
|
|
|
+ "[time] %s " +
|
|
|
+ "[text] %s " +
|
|
|
+ "[ContentChangeTypes] %s " +
|
|
|
+ "[WindowChanges] %s",
|
|
|
event.getEventType(),
|
|
|
event.getClassName(),
|
|
|
event.getPackageName(),
|
|
@@ -63,76 +80,51 @@ public class USSDService extends AccessibilityService {
|
|
|
event.getText(),
|
|
|
event.getContentChangeTypes(),
|
|
|
event.getWindowChanges()
|
|
|
- ));
|
|
|
- new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
|
|
- Log.d("hzshkj", 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()
|
|
|
- ));
|
|
|
- XLog.i(String.format("USSDService onAccessibilityEvent:2秒后 [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;
|
|
|
- }
|
|
|
-
|
|
|
- String response = event.getText().toString();
|
|
|
- XLog.i("USSDService response = " + response);
|
|
|
- if (response.toLowerCase(Locale.US).contains("ussd code running")) {
|
|
|
- XLog.e("中断执行,监测到是 ---> " + response);
|
|
|
- return;
|
|
|
- }
|
|
|
- if (LoginView(event) && notInputText(event)) {
|
|
|
- XLog.i("USSDService: 1");
|
|
|
- clickOnButton(event, 0);
|
|
|
+ );
|
|
|
+ XLog.i(data);
|
|
|
+ Log.d("hzshkj", "[USSDService] onAccessibilityEvent: " + data);
|
|
|
+
|
|
|
+ String response = event.getText().toString();
|
|
|
+ XLog.i("USSDService response的内容为 -> " + response);
|
|
|
+ if (response.toLowerCase(Locale.US).contains("ussd code running")) {
|
|
|
+ XLog.e("停止执行,检测到窗口为 -> ussd code running, response内容为: -> " + response);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (LoginView(event) && notInputText(event)) {
|
|
|
+ XLog.i("USSDService: LoginView && notInputText");
|
|
|
+ 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: problemView && LoginView");
|
|
|
+ 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: isUSSDWidget");
|
|
|
+ if (notInputText(event)) {
|
|
|
+ XLog.i("USSDService: notInputText");
|
|
|
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);
|
|
|
+ } else {
|
|
|
+ XLog.i("USSDService: 不是notInputText");
|
|
|
if (USSDController.instance.send)
|
|
|
- USSDController.instance.callbackMessage.over(response);
|
|
|
+ USSDController.instance.callbackMessage.responseMessage(response);
|
|
|
else
|
|
|
- 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 : 未走进任何逻辑循环" + event.getText().toString());
|
|
|
+ USSDController.instance.callbackInvoke.responseInvoke(response);
|
|
|
}
|
|
|
- }, 2000); // 延迟 1 秒
|
|
|
+ } else {
|
|
|
+ XLog.e("USSDService Error : 未走进任何逻辑循环" + event.getText().toString());
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -167,7 +159,6 @@ public class USSDService extends AccessibilityService {
|
|
|
AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, data);
|
|
|
|
|
|
for (AccessibilityNodeInfo leaf : getLeaves(event)) {
|
|
|
-
|
|
|
if (leaf.getClassName().equals("android.widget.EditText")
|
|
|
&& !leaf.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, arguments)) {
|
|
|
ClipboardManager clipboardManager = ((ClipboardManager) ussdController.context
|
|
@@ -175,7 +166,6 @@ public class USSDService extends AccessibilityService {
|
|
|
if (clipboardManager != null) {
|
|
|
clipboardManager.setPrimaryClip(ClipData.newPlainText("text", data));
|
|
|
}
|
|
|
-
|
|
|
leaf.performAction(AccessibilityNodeInfo.ACTION_PASTE);
|
|
|
}
|
|
|
}
|
|
@@ -211,12 +201,14 @@ public class USSDService extends AccessibilityService {
|
|
|
String className = event.getClassName().toString();
|
|
|
return (className.equals("amigo.app.AmigoAlertDialog")
|
|
|
|| className.equals("android.app.AlertDialog")
|
|
|
+ || className.equals("androidx.appcompat.app.e")
|
|
|
|| className.equals("com.android.phone.oppo.settings.LocalAlertDialog")
|
|
|
|| className.equals("com.zte.mifavor.widget.AlertDialog")
|
|
|
|| className.equals("color.support.v7.app.AlertDialog")
|
|
|
|| className.equals("com.transsion.widgetslib.dialog.PromptDialog")
|
|
|
|| className.equals("miuix.appcompat.app.AlertDialog")
|
|
|
- || className.equals("androidx.appcompat.app.AlertDialog"));
|
|
|
+ || className.equals("androidx.appcompat.app.AlertDialog")
|
|
|
+ || className.equals("com.mediatek.phone.UssdAlertActivity"));
|
|
|
}
|
|
|
|
|
|
|
|
@@ -293,7 +285,7 @@ public class USSDService extends AccessibilityService {
|
|
|
*/
|
|
|
@Override
|
|
|
public void onInterrupt() {
|
|
|
- Log.d(TAG, "onInterrupt");
|
|
|
+ XLog.i("onInterrupt");
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -302,7 +294,7 @@ public class USSDService extends AccessibilityService {
|
|
|
@Override
|
|
|
protected void onServiceConnected() {
|
|
|
super.onServiceConnected();
|
|
|
- Log.d(TAG, "onServiceConnected");
|
|
|
+ XLog.i("onServiceConnected");
|
|
|
}
|
|
|
|
|
|
}
|