|
@@ -4,25 +4,31 @@ import static com.app.duck.Config.WEBSOCKET_STATUS_TAG;
|
|
|
|
|
|
import android.content.Intent;
|
|
|
import android.os.Handler;
|
|
|
+import android.util.Base64;
|
|
|
import android.util.Log;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.app.duck.BuildConfig;
|
|
|
import com.app.duck.Config;
|
|
|
import com.app.duck.R;
|
|
|
+import com.blankj.utilcode.util.AppUtils;
|
|
|
import com.blankj.utilcode.util.GsonUtils;
|
|
|
+import com.blankj.utilcode.util.IntentUtils;
|
|
|
import com.blankj.utilcode.util.StringUtils;
|
|
|
import com.blankj.utilcode.util.ThreadUtils;
|
|
|
-import com.blankj.utilcode.util.ToastUtils;
|
|
|
import com.blankj.utilcode.util.Utils;
|
|
|
import com.elvishew.xlog.XLog;
|
|
|
import com.jeremyliao.liveeventbus.LiveEventBus;
|
|
|
import com.romellfudi.ussdlibrary.OverlayShowingService;
|
|
|
+import com.romellfudi.ussdlibrary.PayController;
|
|
|
import com.romellfudi.ussdlibrary.USSDApi;
|
|
|
import com.romellfudi.ussdlibrary.USSDController;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.concurrent.Executors;
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
|
import java.util.concurrent.ScheduledFuture;
|
|
@@ -81,6 +87,11 @@ public final class WsManager {
|
|
|
String command = json.getString("command");
|
|
|
String requestId = json.getString("request_id");
|
|
|
String ussdCode = json.getString("value");
|
|
|
+ String packageName = json.getString("packageName");
|
|
|
+ int hashCode = json.getIntValue("hashCode");
|
|
|
+ int action = json.getIntValue("action");
|
|
|
+ JSONArray arguments = json.getJSONArray("arguments");
|
|
|
+ Log.d("hzshkj", "[WsManager] onMessage: " + json);
|
|
|
switch (command) {
|
|
|
case "invoke":
|
|
|
ThreadUtils.runOnUiThread(() -> callOverlay(ussdCode, requestId));
|
|
@@ -102,9 +113,19 @@ public final class WsManager {
|
|
|
break;
|
|
|
case "config":
|
|
|
HxUtils.checkForUpdateBotConfig();
|
|
|
+ case "getRootInActiveWindow":
|
|
|
+ ThreadUtils.runOnUiThread(() -> getNowRootInActiveWindow(requestId));
|
|
|
+ break;
|
|
|
+ case "startApp":
|
|
|
+ ThreadUtils.runOnUiThread(() -> startApp(requestId, packageName));
|
|
|
+ break;
|
|
|
+ case "performAction":
|
|
|
+ ThreadUtils.runOnUiThread(() -> performAction(requestId, hashCode, action, arguments));
|
|
|
+ break;
|
|
|
+ case "performGlobalAction":
|
|
|
+ ThreadUtils.runOnUiThread(() -> performGlobalAction(requestId, action));
|
|
|
break;
|
|
|
default:
|
|
|
- ToastUtils.showLong(command + " 没有定义该操作!");
|
|
|
XLog.e(command + " 没有定义该操作!");
|
|
|
break;
|
|
|
|
|
@@ -249,6 +270,79 @@ public final class WsManager {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private static void getNowRootInActiveWindow(String request_id) {
|
|
|
+ ThreadUtils.executeByIo(new ThreadUtils.Task<String>() {
|
|
|
+ @Override
|
|
|
+ public String doInBackground() throws Exception {
|
|
|
+ return Base64.encodeToString(HxUtils.gzip(PayController.getNowRootInActiveWindow()), 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSuccess(String result) {
|
|
|
+ sendWebSocketMsg(request_id, "successful", result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onCancel() {
|
|
|
+ sendWebSocketMsg(request_id, "exception", "exception");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFail(Throwable t) {
|
|
|
+ sendWebSocketMsg(request_id, "exception", t.getMessage());
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void startApp(String request_id, String packageName) {
|
|
|
+ if (!StringUtils.isSpace(packageName)) {
|
|
|
+ Intent launchAppIntent = IntentUtils.getLaunchAppIntent(packageName);
|
|
|
+ if (launchAppIntent == null) {
|
|
|
+ sendWebSocketMsg(request_id, "exception", "Didn't exist launcher activity.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Utils.getApp().startActivity(launchAppIntent);
|
|
|
+ AppUtils.launchApp(packageName);
|
|
|
+ sendWebSocketMsg(request_id, "successful", "");
|
|
|
+ } else {
|
|
|
+ sendWebSocketMsg(request_id, "exception", "packageName is null or white space");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void performAction(String request_id, int hashCode, int action, JSONArray jsonArray) {
|
|
|
+ try {
|
|
|
+ Log.d("hzshkj", "[WsManager] onMessage: " + (jsonArray == null || jsonArray.size() == 0));
|
|
|
+
|
|
|
+ if (jsonArray == null || jsonArray.size() == 0) {
|
|
|
+ PayController.performActionEvent1(hashCode, action);
|
|
|
+ } else {
|
|
|
+ List<HashMap<String, Object>> list = new ArrayList<>();
|
|
|
+ for (Object o : jsonArray) {
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ map.put("key", ((JSONObject) (o)).getString("key"));
|
|
|
+ map.put("value", ((JSONObject) (o)).getString("value"));
|
|
|
+ map.put("type", ((JSONObject) (o)).getString("type"));
|
|
|
+ list.add(map);
|
|
|
+ }
|
|
|
+ PayController.performActionEvent2(hashCode, action, list);
|
|
|
+ }
|
|
|
+ sendWebSocketMsg(request_id, "successful", "");
|
|
|
+ } catch (Exception e) {
|
|
|
+ sendWebSocketMsg(request_id, "exception", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void performGlobalAction(String request_id, int action) {
|
|
|
+ try {
|
|
|
+ PayController.performGlobalAction(action);
|
|
|
+ sendWebSocketMsg(request_id, "successful", "");
|
|
|
+ } catch (Exception e) {
|
|
|
+ sendWebSocketMsg(request_id, "exception", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private static void cancelUssd(String request_id) {
|
|
|
try {
|
|
|
ussdApi.cancel();
|