Skip to content

Commit 195b088

Browse files
committed
代码备份
1 parent 04c7148 commit 195b088

File tree

4 files changed

+173
-6
lines changed

4 files changed

+173
-6
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ android {
44
compileSdkVersion 26
55
defaultConfig {
66
applicationId "com.coderpig.wechathelper"
7-
minSdkVersion 15
7+
minSdkVersion 19
88
targetSdkVersion 26
99
versionCode 1
1010
versionName "1.0"

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
<action android:name="android.accessibilityservice.AccessibilityService" />
2727
</intent-filter>
2828

29-
29+
<meta-data
30+
android:name="android.accessibilityservice"
31+
android:resource="@xml/accessibility_service_config" />
3032

3133
</service>
3234

Lines changed: 161 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,182 @@
11
package com.coderpig.wechathelper;
22

33
import android.accessibilityservice.AccessibilityService;
4+
import android.app.Notification;
5+
import android.app.PendingIntent;
6+
import android.os.Handler;
7+
import android.util.Log;
48
import android.view.accessibility.AccessibilityEvent;
9+
import android.view.accessibility.AccessibilityNodeInfo;
10+
11+
import java.util.List;
512

613
/**
714
* 描述:
815
*
916
* @author CoderPig on 2018/04/04 13:46.
1017
*/
1118

12-
public class HelperService extends AccessibilityService{
19+
public class HelperService extends AccessibilityService {
20+
21+
private static final String TAG = "HelperService";
22+
private Handler handler = new Handler();
23+
private String userName = "呵呵呵";
24+
1325
@Override
1426
public void onAccessibilityEvent(AccessibilityEvent event) {
27+
int eventType = event.getEventType();
28+
CharSequence classNameChr = event.getClassName();
29+
String className = classNameChr.toString();
30+
Log.d(TAG, event.toString());
31+
switch (eventType) {
32+
case AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED:
33+
if (event.getParcelableData() != null && event.getParcelableData() instanceof Notification) {
34+
Notification notification = (Notification) event.getParcelableData();
35+
String content = notification.tickerText.toString();
36+
if (content.contains("请求添加你为朋友")) {
37+
PendingIntent pendingIntent = notification.contentIntent;
38+
try {
39+
pendingIntent.send();
40+
} catch (PendingIntent.CanceledException e) {
41+
e.printStackTrace();
42+
}
43+
}
44+
}
45+
break;
46+
case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
47+
Log.d(TAG, "TYPE_WINDOW_STATE_CHANGED");
48+
switch (className) {
49+
case "com.tencent.mm.plugin.subapp.ui.friend.FMessageConversationUI":
50+
addFriend();
51+
break;
52+
case "com.tencent.mm.plugin.profile.ui.SayHiWithSnsPermissionUI":
53+
verifyFriend();
54+
break;
55+
case "com.tencent.mm.plugin.profile.ui.ContactInfoUI":
56+
performBackClick();
57+
break;
58+
case "com.tencent.mm.ui.LauncherUI":
59+
if (!userName.equals("123")) {
60+
openGroup();
61+
}
62+
break;
63+
case "com.tencent.mm.ui.contact.ChatroomContactUI":
64+
inviteGroup();
65+
break;
66+
}
67+
break;
68+
case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED:
69+
70+
}
71+
}
1572

73+
private void addFriend() {
74+
AccessibilityNodeInfo nodeInfo = getRootInActiveWindow();
75+
if (nodeInfo != null) {
76+
List<AccessibilityNodeInfo> list = nodeInfo
77+
.findAccessibilityNodeInfosByText("接受");
78+
if (list != null && list.size() > 0) {
79+
for (AccessibilityNodeInfo n : list) {
80+
n.performAction(AccessibilityNodeInfo.ACTION_CLICK);
81+
}
82+
} else {
83+
performBackClick();
84+
}
85+
}
1686
}
1787

88+
private void verifyFriend() {
89+
AccessibilityNodeInfo nodeInfo = getRootInActiveWindow();
90+
//获得用户名
91+
if (nodeInfo != null) {
92+
userName = nodeInfo.findAccessibilityNodeInfosByViewId("com.tencent.mm:id/d0n").get(0).getText().toString();
93+
AccessibilityNodeInfo finishNode = nodeInfo.findAccessibilityNodeInfosByViewId("com.tencent.mm:id/hd").get(0);
94+
finishNode.performAction(AccessibilityNodeInfo.ACTION_CLICK);
95+
handler.postDelayed(new Runnable() {
96+
@Override
97+
public void run() {
98+
AccessibilityNodeInfo nodeInfo = getRootInActiveWindow();
99+
if (nodeInfo != null) {
100+
recycle(nodeInfo);
101+
}
102+
}
103+
}, 500L);
104+
}
105+
}
106+
107+
private void openGroup() {
108+
AccessibilityNodeInfo nodeInfo = getRootInActiveWindow();
109+
if (nodeInfo != null) {
110+
List<AccessibilityNodeInfo> nodes = nodeInfo.findAccessibilityNodeInfosByViewId("com.tencent.mm:id/ca5");
111+
for (AccessibilityNodeInfo info : nodes) {
112+
if (info.getText().toString().equals("通讯录")) {
113+
info.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
114+
handler.postDelayed(new Runnable() {
115+
@Override
116+
public void run() {
117+
AccessibilityNodeInfo nodeInfo = getRootInActiveWindow();
118+
if (nodeInfo != null) {
119+
List<AccessibilityNodeInfo> nodes = nodeInfo.findAccessibilityNodeInfosByViewId("com.tencent.mm:id/j5");
120+
for (AccessibilityNodeInfo info : nodes) {
121+
if (info.getText().toString().equals("群聊")) {
122+
info.getParent().getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
123+
break;
124+
}
125+
}
126+
}
127+
}
128+
}, 500L);
129+
}
130+
}
131+
}
132+
}
133+
134+
private void inviteGroup() {
135+
AccessibilityNodeInfo nodeInfo = getRootInActiveWindow();
136+
if (nodeInfo != null) {
137+
List<AccessibilityNodeInfo> nodes = nodeInfo.findAccessibilityNodeInfosByViewId("com.tencent.mm:id/a9v");
138+
for (AccessibilityNodeInfo info : nodes) {
139+
if(info.getText().toString().equals("小猪的Python学习交流群")) {
140+
Log.d(TAG, "inviteGroup: Test" + info.getParent().getParent().getClassName().toString());
141+
info.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
142+
break;
143+
}
144+
}
145+
}
146+
}
147+
148+
private void performBackClick() {
149+
handler.postDelayed(new Runnable() {
150+
@Override
151+
public void run() {
152+
performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);
153+
}
154+
}, 300L);
155+
}
156+
157+
158+
//遍历控件的方法
159+
public void recycle(AccessibilityNodeInfo info) {
160+
if (info.getChildCount() == 0) {
161+
Log.i(TAG, "child widget----------------------------" + info.getClassName().toString());
162+
Log.i(TAG, "showDialog:" + info.canOpenPopup());
163+
Log.i(TAG, "Text:" + info.getText());
164+
Log.i(TAG, "windowId:" + info.getWindowId());
165+
Log.i(TAG, "resId:" + info.getViewIdResourceName());
166+
} else {
167+
for (int i = 0; i < info.getChildCount(); i++) {
168+
if (info.getChild(i) != null) {
169+
recycle(info.getChild(i));
170+
}
171+
}
172+
}
173+
}
174+
175+
18176
@Override
19177
public void onInterrupt() {
20178

21179
}
180+
181+
22182
}
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
3-
4-
</PreferenceScreen>
2+
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:accessibilityEventTypes="typeNotificationStateChanged|typeWindowStateChanged|typeWindowContentChanged"
4+
android:accessibilityFeedbackType="feedbackGeneric"
5+
android:accessibilityFlags="flagDefault"
6+
android:canRetrieveWindowContent="true"
7+
android:notificationTimeout="100"
8+
android:packageNames="com.tencent.mm"
9+
android:settingsActivity="com.coderpig.wechathelper.MainActivity" />

0 commit comments

Comments
 (0)