|
@@ -0,0 +1,172 @@
|
|
1
|
+package com.kuxuan.autoclick.service;
|
|
2
|
+
|
|
3
|
+import android.graphics.Rect;
|
|
4
|
+import android.os.SystemClock;
|
|
5
|
+import android.text.TextUtils;
|
|
6
|
+import android.view.accessibility.AccessibilityNodeInfo;
|
|
7
|
+import android.view.accessibility.AccessibilityWindowInfo;
|
|
8
|
+
|
|
9
|
+import com.kuxuan.autoclick.model.Constant;
|
|
10
|
+import com.kuxuan.autoclick.model.TaskBean;
|
|
11
|
+import com.kuxuan.autoclick.utils.AccessibilityUtil;
|
|
12
|
+import com.kuxuan.autoclick.utils.LogUtil;
|
|
13
|
+import com.kuxuan.autoclick.utils.NumberUtils;
|
|
14
|
+import com.kuxuan.autoclick.utils.ScreenUtil;
|
|
15
|
+import com.kuxuan.autoclick.utils.Views;
|
|
16
|
+
|
|
17
|
+import java.text.SimpleDateFormat;
|
|
18
|
+import java.util.ArrayList;
|
|
19
|
+
|
|
20
|
+import static com.kuxuan.autoclick.service.GlobalMethodKt.getRootCopy;
|
|
21
|
+
|
|
22
|
+/**
|
|
23
|
+ * @author lkj
|
|
24
|
+ * @date 2024/4/24 18:21
|
|
25
|
+ * @desc
|
|
26
|
+ */
|
|
27
|
+public class GlobalMethodJava {
|
|
28
|
+ private static GlobalMethodJava globalMethodJava;
|
|
29
|
+
|
|
30
|
+ public static GlobalMethodJava getInstance() {
|
|
31
|
+ if (globalMethodJava == null) {
|
|
32
|
+ synchronized (GlobalMethodJava.class) {
|
|
33
|
+ if (globalMethodJava == null) {
|
|
34
|
+ globalMethodJava = new GlobalMethodJava();
|
|
35
|
+ }
|
|
36
|
+ }
|
|
37
|
+ }
|
|
38
|
+ return globalMethodJava;
|
|
39
|
+ }
|
|
40
|
+
|
|
41
|
+ /**
|
|
42
|
+ * @author lkj
|
|
43
|
+ * @date 2024/4/24 18:31
|
|
44
|
+ * @desc 须等待前台为企业微信 true 直接返回当前前台窗口
|
|
45
|
+ */
|
|
46
|
+ public AccessibilityNodeInfo getRoot(boolean ignoreCheck) {
|
|
47
|
+ while (true) {
|
|
48
|
+ SystemClock.sleep(NumberUtils.getRandom1000());
|
|
49
|
+ AccessibilityNodeInfo nodeInfo = null;
|
|
50
|
+ for (AccessibilityWindowInfo window : WeworkController.INSTANCE.getWeworkService().getWindows()) {
|
|
51
|
+ if (window.getRoot() != null) {
|
|
52
|
+ nodeInfo = window.getRoot();
|
|
53
|
+ } else {
|
|
54
|
+ LogUtil.e("根节点检测: 检测为空");
|
|
55
|
+ }
|
|
56
|
+ }
|
|
57
|
+ if (nodeInfo != null) {
|
|
58
|
+ LogUtil.e("获取 weworkService.rootInActiveWindow 不为空");
|
|
59
|
+ if (nodeInfo.getPackageName() == Constant.PACKAGE_NAMES) {
|
|
60
|
+ return nodeInfo;
|
|
61
|
+ } else {
|
|
62
|
+ LogUtil.e("当前不在企业微信: ${root.packageName}");
|
|
63
|
+ // }
|
|
64
|
+ if (ignoreCheck) {
|
|
65
|
+ return nodeInfo;
|
|
66
|
+ }
|
|
67
|
+ }
|
|
68
|
+ } else {
|
|
69
|
+ LogUtil.e("获取 weworkService.rootInActiveWindow 为空了");
|
|
70
|
+ }
|
|
71
|
+ }
|
|
72
|
+ }
|
|
73
|
+
|
|
74
|
+ /**
|
|
75
|
+ * @author lkj
|
|
76
|
+ * @date 2024/4/24 18:27
|
|
77
|
+ * @desc 当前是否在首页
|
|
78
|
+ */
|
|
79
|
+ public boolean isAtHome(TaskBean taskBean) {
|
|
80
|
+ LogUtil.e("判断 当前是否在首页");
|
|
81
|
+ ArrayList<AccessibilityNodeInfo> allByClazz = AccessibilityUtil.INSTANCE.findAllByClazz(getRootCopy(taskBean), new String[]{Views.TextView});
|
|
82
|
+ for (AccessibilityNodeInfo byClazz : allByClazz) {
|
|
83
|
+ if (!TextUtils.isEmpty(byClazz.getText())) {
|
|
84
|
+ String string = byClazz.getText().toString();
|
|
85
|
+ if (string.equals("已阅读并同意 软件许可及服务协议 和 隐私政策")) {
|
|
86
|
+ return true;
|
|
87
|
+ }
|
|
88
|
+ }
|
|
89
|
+ }
|
|
90
|
+ return false;
|
|
91
|
+ }
|
|
92
|
+
|
|
93
|
+ public AccessibilityNodeInfo getRootCopy(TaskBean taskBean) {
|
|
94
|
+ long timeFlag = System.currentTimeMillis();
|
|
95
|
+ int loopGoOn = 0;
|
|
96
|
+ while (loopGoOn < 50) {
|
|
97
|
+ loopGoOn++;
|
|
98
|
+ if (!taskBean.isLive()) {
|
|
99
|
+ SimpleDateFormat dafor = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
100
|
+ LogUtil.e("任务已取消:" + dafor.format(taskBean.getId()));
|
|
101
|
+ WeworkController.weworkService.taskList.remove(taskBean);
|
|
102
|
+ return null;
|
|
103
|
+ }
|
|
104
|
+ long currTime = System.currentTimeMillis();
|
|
105
|
+ if (currTime - timeFlag > 1000 * 60) {
|
|
106
|
+ LogUtil.e("已经执行一分钟了 都找不到企微图标!!");
|
|
107
|
+ }
|
|
108
|
+ try {
|
|
109
|
+ SystemClock.sleep(1000);
|
|
110
|
+ } catch (Exception e) {
|
|
111
|
+ LogUtil.e("延时2秒报错:${e.printStackTrace()}");
|
|
112
|
+ e.printStackTrace();
|
|
113
|
+ }
|
|
114
|
+ if (!ScreenUtil.isScreenOn(WeworkController.weworkService)) {
|
|
115
|
+ LogUtil.e("判断当前屏幕是黑屏状态,重新唤醒一下");
|
|
116
|
+ ScreenUtil.wakeAndUnlock(WeworkController.weworkService, true);
|
|
117
|
+ }
|
|
118
|
+ for (AccessibilityWindowInfo window : WeworkController.weworkService.getWindows()) {
|
|
119
|
+ AccessibilityNodeInfo root = window.getRoot();
|
|
120
|
+ if (root != null && TextUtils.isEmpty(root.getPackageName())) {
|
|
121
|
+ if (root.getPackageName().equals(Constant.PACKAGE_NAMES)) {
|
|
122
|
+
|
|
123
|
+ }
|
|
124
|
+ } else {
|
|
125
|
+
|
|
126
|
+ }
|
|
127
|
+ }
|
|
128
|
+ }
|
|
129
|
+ return null;
|
|
130
|
+ }
|
|
131
|
+
|
|
132
|
+ /**
|
|
133
|
+ * @author lkj
|
|
134
|
+ * @date 2024/4/25 10:11
|
|
135
|
+ * @desc 选择一个身份进入到主界面
|
|
136
|
+ */
|
|
137
|
+ public void toStatus(TaskBean taskBean) {
|
|
138
|
+ //需要选择工作身份时 选择其中一个进入主界面
|
|
139
|
+ LogUtil.e("选择工作身份");
|
|
140
|
+ ArrayList<AccessibilityNodeInfo> nodeInfos = OutGroupCustomReturn.getInstance().getNodeList(taskBean, Views.TextView);
|
|
141
|
+ if (!nodeInfos.isEmpty() && nodeInfos.size() > 0) {
|
|
142
|
+ for (AccessibilityNodeInfo nodeInfo : nodeInfos) {
|
|
143
|
+ if (!TextUtils.isEmpty(nodeInfo.getText())) {
|
|
144
|
+ Rect rect = new Rect();
|
|
145
|
+ nodeInfo.getBoundsInScreen(rect);
|
|
146
|
+ LogUtil.e("找的所有的TextView:" + rect.left + " " + nodeInfo.getText().toString());
|
|
147
|
+ if (rect.left == 32 && !nodeInfo.getText().toString().equals("选择身份进入")) {
|
|
148
|
+ AccessibilityUtil.INSTANCE.performClick(nodeInfo, true);
|
|
149
|
+ LogUtil.e("点击一个身份进入: " + nodeInfo.getText().toString());
|
|
150
|
+ SystemClock.sleep(NumberUtils.getRandom1000() - 1000);
|
|
151
|
+ boolean into = OutGroupCustomReturn.getInstance().clickButtonText(taskBean, "进入", null);
|
|
152
|
+ break;
|
|
153
|
+ }
|
|
154
|
+ }
|
|
155
|
+ }
|
|
156
|
+ } else {
|
|
157
|
+ LogUtil.e("textViews 为空了");
|
|
158
|
+ LogUtil.e("任务标识 全部设置 false");
|
|
159
|
+ GroupSendImplKt.setFalse();
|
|
160
|
+ }
|
|
161
|
+ }
|
|
162
|
+
|
|
163
|
+ /**
|
|
164
|
+ * @author lkj
|
|
165
|
+ * @date 2024/4/25 9:52
|
|
166
|
+ * @desc 上滑挂断电话的手势
|
|
167
|
+ */
|
|
168
|
+ public void hangUpCall() {
|
|
169
|
+ AccessibilityUtil.INSTANCE.scrollByXY(WeworkController.weworkService, 360, 250, 0, 0);
|
|
170
|
+ AccessibilityUtil.INSTANCE.scrollByXY_sec(WeworkController.weworkService, 360, 250, 0, -250);
|
|
171
|
+ }
|
|
172
|
+}
|