├── .gitignore ├── .idea ├── codeStyles │ └── Project.xml ├── gradle.xml ├── misc.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── ansen │ │ └── accessibility │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── ansen │ │ │ └── accessibility │ │ │ ├── MainActivity.kt │ │ │ ├── MyApp.kt │ │ │ ├── WXAccessibilityService.kt │ │ │ └── WXHelpService.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ │ └── xml │ │ └── accessibility_config.xml │ └── test │ └── java │ └── com │ └── ansen │ └── accessibility │ └── ExampleUnitTest.java ├── autojs.apk ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AccessibilityDEV 2 | android无障碍服务开发(微信朋友圈自动点赞,抢红包,自动加好友) 3 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android-extensions' 3 | apply plugin: 'kotlin-android' 4 | 5 | android { 6 | compileSdkVersion 28 7 | defaultConfig { 8 | applicationId "com.ansen.accessibility" 9 | minSdkVersion 25 10 | targetSdkVersion 28 11 | versionCode 1 12 | versionName "1.0" 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | } 22 | 23 | dependencies { 24 | implementation fileTree(dir: 'libs', include: ['*.jar']) 25 | implementation 'com.android.support:appcompat-v7:28.0.0' 26 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 27 | implementation "com.orhanobut:hawk:2.0.1" 28 | testImplementation 'junit:junit:4.12' 29 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 30 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 31 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 32 | } 33 | repositories { 34 | mavenCentral() 35 | } 36 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/ansen/accessibility/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.ansen.accessibility; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.ansen.accessibility", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /app/src/main/java/com/ansen/accessibility/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.ansen.accessibility 2 | 3 | import android.content.Intent 4 | import android.support.v7.app.AppCompatActivity 5 | import android.os.Bundle 6 | import android.provider.Settings 7 | import android.view.View 8 | import com.orhanobut.hawk.Hawk 9 | import kotlinx.android.synthetic.main.activity_main.* 10 | 11 | class MainActivity : AppCompatActivity() { 12 | 13 | companion object { 14 | val ADD_FRIENDS = "add_friends" 15 | val FRIEND_SQUARE = "auto_zan" 16 | val RED_PACKET = "red_packet" 17 | } 18 | 19 | override fun onCreate(savedInstanceState: Bundle?) { 20 | super.onCreate(savedInstanceState) 21 | setContentView(R.layout.activity_main) 22 | 23 | add_friends.isChecked = Hawk.get(ADD_FRIENDS, true); 24 | auto_zan.isChecked = Hawk.get(FRIEND_SQUARE, true); 25 | 26 | add_friends.setOnCheckedChangeListener { _, isChecked -> 27 | if (isChecked) Hawk.put(ADD_FRIENDS, true) else Hawk.put(ADD_FRIENDS, false) 28 | } 29 | auto_zan.setOnCheckedChangeListener { _, isChecked -> 30 | if (isChecked) Hawk.put(FRIEND_SQUARE, true) else Hawk.put(FRIEND_SQUARE, false) 31 | } 32 | 33 | 34 | } 35 | 36 | fun open(view: View) { 37 | startActivity(Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/java/com/ansen/accessibility/MyApp.kt: -------------------------------------------------------------------------------- 1 | package com.ansen.accessibility 2 | 3 | import android.app.Application 4 | import com.orhanobut.hawk.Hawk 5 | import kotlin.properties.Delegates 6 | 7 | /** 8 | * 描述: 9 | * 10 | * @author CoderPig on 2018/04/12 11:43. 11 | */ 12 | class MyApp : Application() { 13 | companion object { 14 | var instance by Delegates.notNull() 15 | } 16 | 17 | override fun onCreate() { 18 | super.onCreate() 19 | instance = this 20 | Hawk.init(this).build() 21 | } 22 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ansen/accessibility/WXAccessibilityService.kt: -------------------------------------------------------------------------------- 1 | package com.ansen.accessibility 2 | 3 | import android.accessibilityservice.AccessibilityService 4 | import android.app.KeyguardManager 5 | import android.app.Notification 6 | import android.app.PendingIntent 7 | import android.content.Context 8 | import android.os.PowerManager 9 | import android.util.Log 10 | import android.view.accessibility.AccessibilityEvent 11 | import android.view.accessibility.AccessibilityNodeInfo 12 | 13 | 14 | import java.util.ArrayList 15 | 16 | /** 17 | * Created by Ansen on 2016/5/7 10:31. 18 | * 19 | * @E-mail: tomorrow_p@163.com 20 | * @Blog: http://blog.csdn.net/qq_25804863 21 | * @Github: https://github.com/ansen360 22 | * @PROJECT_NAME: CodeRepository 23 | * @PACKAGE_NAME: com.ansen.service 24 | * @Description: AccessibilityService可以获取当前页面的信息(view的节点), 并且可以模拟点击事件 25 | */ 26 | class WXAccessibilityService : AccessibilityService() { 27 | private var mKeyguardManager: KeyguardManager? = null 28 | private var mKeyguardLock: KeyguardManager.KeyguardLock? = null 29 | //唤醒屏幕相关 30 | private var mPowerManager: PowerManager? = null 31 | private var mWakeLock: PowerManager.WakeLock? = null 32 | private var mNodeInfos: MutableList? = null 33 | private var lastCount: Int = 0 34 | private var isChatUI = false 35 | private var isNotifyEnter = false 36 | 37 | 38 | override fun onServiceConnected() { 39 | super.onServiceConnected() 40 | mNodeInfos = ArrayList() 41 | } 42 | 43 | override fun onAccessibilityEvent(event: AccessibilityEvent) { 44 | val eventType = event.eventType 45 | val className = event.className.toString() 46 | when (eventType) { 47 | 2048 //监听视图变化事件 48 | -> { 49 | if (isChatUI && "android.widget.TextView" == className) { 50 | getIncreasePacket() 51 | Log.i(TAG, "来消息") 52 | } 53 | 54 | Log.d("2048", "2048 " + event.className.toString()) 55 | } 56 | // 监听有通知栏消息的事件 57 | AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED -> { 58 | val texts = event.text 59 | if (!texts.isEmpty()) { 60 | for (text in texts) { 61 | val content = text.toString() 62 | Log.d(TAG, "content: $content") 63 | if (content.contains("[微信红包]")) { 64 | //打开通知栏消息 65 | if (event.parcelableData != null && event.parcelableData is Notification) { 66 | val notification = event.parcelableData as Notification 67 | val pendingIntent = notification.contentIntent 68 | try { 69 | pendingIntent.send() 70 | isNotifyEnter = true 71 | } catch (e: PendingIntent.CanceledException) { 72 | e.printStackTrace() 73 | } 74 | 75 | } 76 | } 77 | } 78 | } 79 | } 80 | 81 | // 监听窗口发生变化的事件(判断是否进入微信红包消息界面) 82 | AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED -> { 83 | Log.i(TAG, "className: $className") 84 | if ("com.tencent.mm.ui.LauncherUI" == className) { //聊天页面 85 | if (isNotifyEnter) { 86 | getLastPacket() 87 | Log.i(TAG, "通知栏: 开") 88 | } 89 | isNotifyEnter = false 90 | isChatUI = true 91 | } else if ("com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyReceiveUI" == className) { //红包页面 92 | isChatUI = false 93 | //拆红包 94 | executeClick("com.tencent.mm:id/bg7") 95 | // executeClick("com.tencent.mm:id/bga"); //返回 96 | Log.i(TAG, "拆") 97 | } else if ("com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyDetailUI" == className) { //红包已打开页面 98 | isChatUI = false 99 | executeClick("com.tencent.mm:id/ge") //返回 100 | Log.i(TAG, "关") 101 | } else { 102 | isChatUI = false 103 | } 104 | } 105 | } 106 | 107 | 108 | } 109 | 110 | private fun getIncreasePacket() { 111 | val rootNode = rootInActiveWindow 112 | recycle(rootNode) 113 | if (mNodeInfos!!.size > 0) { 114 | if (lastCount < mNodeInfos!!.size) { //有新消息 115 | mNodeInfos!![mNodeInfos!!.size - 1].performAction(AccessibilityNodeInfo.ACTION_CLICK) 116 | Log.i(TAG, "新红包") 117 | } 118 | lastCount = mNodeInfos!!.size 119 | } 120 | mNodeInfos!!.clear() 121 | } 122 | 123 | private fun getLastPacket() { 124 | val rootNode = rootInActiveWindow 125 | recycle(rootNode) 126 | if (mNodeInfos!!.size > 0) { 127 | mNodeInfos!![mNodeInfos!!.size - 1].performAction(AccessibilityNodeInfo.ACTION_CLICK) 128 | lastCount = mNodeInfos!!.size 129 | mNodeInfos!!.clear() 130 | } 131 | } 132 | 133 | 134 | /** 135 | * 打印一个节点的结构 136 | */ 137 | fun recycle(info: AccessibilityNodeInfo) { 138 | if (info.childCount == 0) { 139 | if (info.text != null) { 140 | if ("领取红包" == info.text.toString()) { 141 | //找到一个可以点击的View,模拟点击指定事件 142 | info.performAction(AccessibilityNodeInfo.ACTION_CLICK) 143 | var parent: AccessibilityNodeInfo? = info.parent 144 | while (parent != null) { 145 | if (parent.isClickable) { 146 | mNodeInfos!!.add(parent) 147 | break 148 | } 149 | parent = parent.parent 150 | } 151 | 152 | } 153 | } 154 | 155 | } else { 156 | for (i in 0 until info.childCount) { 157 | if (info.getChild(i) != null) { 158 | recycle(info.getChild(i)) 159 | } 160 | } 161 | } 162 | } 163 | 164 | 165 | /** 166 | * 查找对应控件,模拟点击事件 167 | */ 168 | private fun executeClick(id: String) { 169 | val nodeInfo = rootInActiveWindow 170 | if (nodeInfo != null) { 171 | // 通过节点View的Text内容来查找 172 | // List list = nodeInfo.findAccessibilityNodeInfosByText("开"); 173 | // 通过节点View在xml布局中的id名称 174 | val list = nodeInfo.findAccessibilityNodeInfosByViewId(id) 175 | for (n in list) { 176 | n.performAction(AccessibilityNodeInfo.ACTION_CLICK) 177 | } 178 | } 179 | 180 | } 181 | 182 | private fun wakeUp(b: Boolean) { 183 | if (b) { 184 | //获取电源管理器对象 185 | mPowerManager = getSystemService(Context.POWER_SERVICE) as PowerManager 186 | 187 | //获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是调试用的Tag 188 | mWakeLock = mPowerManager!!.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP or PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright") 189 | 190 | //点亮屏幕 191 | mWakeLock!!.acquire() 192 | 193 | //得到键盘锁管理器对象 194 | mKeyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager 195 | mKeyguardLock = mKeyguardManager!!.newKeyguardLock("unLock") 196 | 197 | //解锁 198 | mKeyguardLock!!.disableKeyguard() 199 | } else { 200 | //锁屏 201 | mKeyguardLock!!.reenableKeyguard() 202 | 203 | //释放wakeLock,关灯 204 | mWakeLock!!.release() 205 | } 206 | 207 | } 208 | 209 | override fun onInterrupt() { 210 | 211 | } 212 | 213 | companion object { 214 | 215 | private val TAG = "ansen" 216 | } 217 | } 218 | -------------------------------------------------------------------------------- /app/src/main/java/com/ansen/accessibility/WXHelpService.kt: -------------------------------------------------------------------------------- 1 | package com.ansen.accessibility 2 | 3 | import android.accessibilityservice.AccessibilityService 4 | import android.app.Notification 5 | import android.app.PendingIntent 6 | import android.os.Handler 7 | import android.os.SystemClock 8 | import android.util.Log 9 | import android.view.accessibility.AccessibilityEvent 10 | import android.view.accessibility.AccessibilityNodeInfo 11 | import com.orhanobut.hawk.Hawk 12 | 13 | /** 14 | * 微信自动加好友服务类 15 | */ 16 | 17 | class WXHelpService : AccessibilityService() { 18 | 19 | private var isAdd = false 20 | private var index = 0 21 | private val handler = Handler() 22 | 23 | override fun onAccessibilityEvent(event: AccessibilityEvent) { 24 | val eventType = event.eventType 25 | val classNameChr = event.className 26 | val className = classNameChr.toString() 27 | Log.d("ansen", event.toString()) 28 | when (eventType) { 29 | AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED -> if (event.parcelableData != null && event.parcelableData is Notification) { 30 | // val notification = event.parcelableData as Notification 31 | // val content = notification.tickerText.toString() 32 | // if (content.contains("请求添加你为朋友")) { 33 | // val pendingIntent = notification.contentIntent 34 | // try { 35 | // pendingIntent.send() 36 | // } catch (e: PendingIntent.CanceledException) { 37 | // e.printStackTrace() 38 | // } 39 | // 40 | // } 41 | } 42 | AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED -> { 43 | Log.d(TAG, className) 44 | if (Hawk.get(MainActivity.ADD_FRIENDS, true)) { 45 | when (className) { 46 | "com.tencent.mm.ui.widget.a.c" -> { 47 | Log.d(TAG, "隐私提示: widget.a.c ") 48 | val az_ = rootInActiveWindow.findAccessibilityNodeInfosByViewId("com.tencent.mm:id/az_") 49 | if (az_ != null && az_.size > 0) { 50 | az_[0].performAction(AccessibilityNodeInfo.ACTION_CLICK) 51 | SystemClock.sleep(500) 52 | performBackClick() 53 | } 54 | } 55 | "com.tencent.mm.ui.base.p" -> Log.d(TAG, "隐私提示: .ui.base.p") 56 | "com.tencent.mm.chatroom.ui.ChatroomInfoUI" // 聊天信息 57 | , "com.tencent.mm.plugin.chatroom.ui.ChatroomInfoUI" -> { 58 | Log.d(TAG, "聊天信息 页面") 59 | 60 | val nodeInfo = rootInActiveWindow // 获取当前整个活动窗口的根节点 返回值记录View的状态信息 61 | // 查找 查看全部群成员 按鈕 62 | val listNodes = nodeInfo.findAccessibilityNodeInfosByViewId("android:id/title") 63 | if (listNodes != null && listNodes.size == 0) { 64 | Log.d(TAG, "沒找到 查看全部群成员 按鈕") 65 | 66 | val listNodes1 = nodeInfo.findAccessibilityNodeInfosByViewId("android:id/list") 67 | if (listNodes1 != null && listNodes1.size > 0) { 68 | 69 | listNodes1[0].performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD) 70 | Log.d(TAG, "滑动后继续查找") 71 | SystemClock.sleep(1000) 72 | // 查找 73 | val listNodes2 = rootInActiveWindow.findAccessibilityNodeInfosByViewId("android:id/title") 74 | if (listNodes2 != null && listNodes2.size > 0) { 75 | listNodes2[0].parent.performAction(AccessibilityNodeInfo.ACTION_CLICK) 76 | Log.d(TAG, "点击: " + listNodes2[0].text) 77 | } 78 | } 79 | } else { 80 | listNodes!![0].parent.performAction(AccessibilityNodeInfo.ACTION_CLICK) 81 | Log.d(TAG, "点击: " + listNodes[0].text) 82 | } 83 | index = 0 84 | SystemClock.sleep(1000) 85 | } 86 | "com.tencent.mm.plugin.chatroom.ui.SeeRoomMemberUI", "com.tencent.mm.chatroom.ui.SeeRoomMemberUI" -> { 87 | Log.d(TAG, "聊天成员") 88 | SystemClock.sleep(3000) 89 | isAdd = false 90 | if (rootInActiveWindow == null) { 91 | return 92 | } 93 | val nodeInfos = rootInActiveWindow.findAccessibilityNodeInfosByViewId("com.tencent.mm:id/e4_") 94 | if (nodeInfos != null && nodeInfos.size > 0) { 95 | if (index < nodeInfos[0].childCount) { 96 | nodeInfos[0].getChild(index).performAction(AccessibilityNodeInfo.ACTION_CLICK) 97 | SystemClock.sleep(1000) 98 | index++ 99 | } else { 100 | val b = nodeInfos[0].performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD) 101 | SystemClock.sleep(2000) 102 | Log.d(TAG, "翻页: $b") 103 | if (b) { 104 | val nodeInfo1 = rootInActiveWindow.findAccessibilityNodeInfosByViewId("com.tencent.mm:id/e4_") 105 | if (nodeInfo1 != null && nodeInfo1.size > 0) { 106 | val childCount = nodeInfo1[0].childCount 107 | if (childCount > 0) { 108 | index = 0 109 | } 110 | if (index < childCount) { 111 | nodeInfo1[0].getChild(index).performAction(AccessibilityNodeInfo.ACTION_CLICK) 112 | } 113 | } 114 | } 115 | } 116 | } 117 | } 118 | "com.tencent.mm.plugin.profile.ui.ContactInfoUI" -> { 119 | SystemClock.sleep(500) 120 | if (isAdd) { 121 | performBackClick() 122 | Log.d(TAG, "添加成功") 123 | } else { 124 | Log.d(TAG, "添加联系页面") 125 | val icon = rootInActiveWindow.findAccessibilityNodeInfosByViewId("com.tencent.mm:id/iq") 126 | if (icon.size > 0) { 127 | performBackClick() 128 | Log.d(TAG, "已经添加 直接返回") 129 | } else { 130 | val adds = rootInActiveWindow.findAccessibilityNodeInfosByViewId("com.tencent.mm:id/cs") 131 | if (adds != null && adds.size > 0) { 132 | adds[0].parent.performAction(AccessibilityNodeInfo.ACTION_CLICK) 133 | Log.d(TAG, "点击添加") 134 | } else { 135 | performBackClick() 136 | } 137 | SystemClock.sleep(1000) 138 | } 139 | } 140 | } 141 | "com.tencent.mm.plugin.profile.ui.SayHiWithSnsPermissionUI" -> { 142 | Log.d(TAG, "验证申请") 143 | 144 | val sends = rootInActiveWindow.findAccessibilityNodeInfosByViewId("com.tencent.mm:id/jx") 145 | if (sends != null && sends.size > 0) { 146 | sends[0].performAction(AccessibilityNodeInfo.ACTION_CLICK) 147 | Log.d(TAG, "发送") 148 | } 149 | SystemClock.sleep(800) 150 | isAdd = true 151 | } 152 | } 153 | } 154 | if (Hawk.get(MainActivity.FRIEND_SQUARE, true)) { 155 | when (className) { 156 | "com.tencent.mm.plugin.sns.ui.SnsTimeLineUI" -> { 157 | Log.d(TAG, "自动点赞") 158 | autoZan() 159 | } 160 | } 161 | } 162 | 163 | if (Hawk.get(MainActivity.RED_PACKET, false)) { 164 | when (className) { 165 | "com.tencent.mm.ui.LauncherUI" -> openRedPacket() 166 | "com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyReceiveUI" -> clickRedPacket() 167 | "com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyDetailUI" -> performBackClick() 168 | } 169 | } 170 | } 171 | } 172 | } 173 | 174 | private fun performBackClick() { 175 | handler.postDelayed({ performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK) }, 300L) 176 | } 177 | 178 | //自动点赞 179 | private fun autoZan() { 180 | val nodeInfo = rootInActiveWindow 181 | if (nodeInfo != null) { 182 | while (true) { 183 | val rootNode = rootInActiveWindow 184 | if (rootNode != null) { 185 | val listNodes = rootNode.findAccessibilityNodeInfosByViewId("com.tencent.mm:id/eii") // ListView 186 | if (listNodes != null && listNodes.size > 0) { 187 | val listNode = listNodes[0] 188 | val zanNodes = listNode.findAccessibilityNodeInfosByViewId("com.tencent.mm:id/eho") // 点击ImageView 189 | for (zan in zanNodes) { 190 | zan.performAction(AccessibilityNodeInfo.ACTION_CLICK) 191 | Thread.sleep(300) 192 | val zsNodes = rootInActiveWindow.findAccessibilityNodeInfosByViewId("com.tencent.mm:id/eh_") // 对话框容器 193 | Thread.sleep(300) 194 | if (zsNodes != null && zsNodes.size > 0) { 195 | if (zsNodes[0].findAccessibilityNodeInfosByText("赞").size > 0) { 196 | zsNodes[0].performAction(AccessibilityNodeInfo.ACTION_CLICK) 197 | } 198 | } 199 | Thread.sleep(500) 200 | } 201 | listNode.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD) 202 | } 203 | } else { 204 | break 205 | } 206 | } 207 | } 208 | } 209 | 210 | // 遍历控件方法 211 | fun recycle(info: AccessibilityNodeInfo) { 212 | if (info.childCount == 0) { 213 | Log.i(TAG, "child widget----------------------------" + info.className.toString()) 214 | Log.i(TAG, "showDialog:" + info.canOpenPopup()) 215 | Log.i(TAG, "Text:" + info.text) 216 | Log.i(TAG, "windowId:" + info.windowId) 217 | Log.i(TAG, "desc:" + info.contentDescription) 218 | } else { 219 | for (i in 0 until info.childCount) { 220 | if (info.getChild(i) != null) { 221 | recycle(info.getChild(i)) 222 | } 223 | } 224 | } 225 | } 226 | 227 | //对话框自动点击 228 | private fun dialogClick() { 229 | val inviteNode = rootInActiveWindow.findAccessibilityNodeInfosByViewId("com.tencent.mm:id/az_")[0] 230 | inviteNode.performAction(AccessibilityNodeInfo.ACTION_CLICK) 231 | } 232 | 233 | //遍历获得未打开红包 234 | private fun openRedPacket() { 235 | val rootNode = rootInActiveWindow 236 | if (rootNode != null) { 237 | val listNode = rootNode.findAccessibilityNodeInfosByViewId("com.tencent.mm:id/cpj") 238 | if (listNode != null && listNode.size > 0) { 239 | val msgNodes = listNode[0].findAccessibilityNodeInfosByViewId("com.tencent.mm:id/azn") 240 | if (msgNodes != null && msgNodes.size > 0) { 241 | for (rpNode in msgNodes) { 242 | val rpStatusNode = rpNode.findAccessibilityNodeInfosByText("领取红包") 243 | if (rpStatusNode != null && rpStatusNode.size > 0) { 244 | rpNode.performAction(AccessibilityNodeInfo.ACTION_CLICK) 245 | break 246 | } 247 | } 248 | } 249 | } 250 | 251 | 252 | } 253 | } 254 | 255 | //打开红包 256 | private fun clickRedPacket() { 257 | val nodeInfo = rootInActiveWindow 258 | val clickNode = nodeInfo.findAccessibilityNodeInfosByViewId("com.tencent.mm:id/cnu") 259 | if (clickNode != null && clickNode.size > 0) { 260 | clickNode[0].performAction(AccessibilityNodeInfo.ACTION_CLICK) 261 | } else { 262 | performBackClick() 263 | } 264 | } 265 | 266 | override fun onInterrupt() { 267 | 268 | } 269 | 270 | companion object { 271 | 272 | private val TAG = "WXHelpService" 273 | } 274 | 275 | } 276 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 24 | 25 | 39 | 40 |