mirror of
https://github.com/TonyJiangWJ/Auto.js.git
synced 2026-06-21 21:01:43 +08:00
fix fucking accessibility service
This commit is contained in:
parent
fcf46c49de
commit
73773faedc
@ -9,8 +9,8 @@ android {
|
||||
applicationId "com.stardust.scriptdroid"
|
||||
minSdkVersion 17
|
||||
targetSdkVersion 23
|
||||
versionCode 147
|
||||
versionName "2.0.14 Beta"
|
||||
versionCode 148
|
||||
versionName "2.0.14 Alpha"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
multiDexEnabled true
|
||||
ndk {
|
||||
|
||||
@ -3,27 +3,30 @@
|
||||
var 好友验证信息 = "AutoJs自动添加群好友";
|
||||
var 延迟 = 500;
|
||||
|
||||
toast("请打开群成员列表");
|
||||
launchApp("QQ");
|
||||
toast("请打开要加的群");
|
||||
sleep(500);
|
||||
if(currentActivity() != "com.tencent.mobileqq.activity.TroopMemberListActivity"){
|
||||
openGroupMemberList();
|
||||
}
|
||||
|
||||
var added = {};
|
||||
while(true){
|
||||
var list = className("AbsListView").findOne();
|
||||
list.children().each(function(child){
|
||||
if(child.className() != "android.widget.FrameLayout"){
|
||||
return;
|
||||
}
|
||||
if(!isGroupMember(child)){
|
||||
return;
|
||||
}
|
||||
if(isMyself(child)){
|
||||
return;
|
||||
}
|
||||
child.child(0).click();
|
||||
sleep(500);
|
||||
addAsFriend();
|
||||
sleep(延迟);
|
||||
});
|
||||
className("AbsListView").findOne().scrollForward();
|
||||
var list = className("AbsListView").findOne();
|
||||
var count = list.childCount();
|
||||
for(var i = 0; i < count; i++){
|
||||
var child = list.child(i);
|
||||
if(!child || child.className() != "android.widget.FrameLayout"){
|
||||
continue;
|
||||
}
|
||||
if(!isGroupMember(child) || isMyself(child)){
|
||||
continue;
|
||||
}
|
||||
child.child(0).click();
|
||||
sleep(500);
|
||||
addAsFriend();
|
||||
sleep(延迟);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -31,6 +34,9 @@ function isGroupMember(child){
|
||||
if(child.childCount() != 1){
|
||||
return false;
|
||||
}
|
||||
if(!child.findByText("Baby Q").isEmpty()){
|
||||
return false;
|
||||
}
|
||||
return child.child(0) && child.child(0).className() == "android.widget.FrameLayout";
|
||||
}
|
||||
|
||||
@ -41,6 +47,7 @@ function isMyself(child){
|
||||
|
||||
function addAsFriend(){
|
||||
var qq = getQQ();
|
||||
toast(qq);
|
||||
if(added[qq]){
|
||||
while(!click("返回"));
|
||||
return;
|
||||
@ -63,4 +70,12 @@ function addAsFriend(){
|
||||
function getQQ(){
|
||||
var qq = textMatches("\\d{5,12}").findOne().text();
|
||||
return qq;
|
||||
}
|
||||
|
||||
function openGroupMemberList(){
|
||||
desc("群资料卡").click();
|
||||
var groupMemberCountView = textEndsWith("名成员").findOne();
|
||||
var groupMemberCount = parseInt(/\d+/.exec(groupMemberCountView.text())[0]);
|
||||
groupMemberCountView.parent().click();
|
||||
sleep(groupMemberCount * 4);
|
||||
}
|
||||
@ -24,11 +24,13 @@ sleep(100);
|
||||
waitForActivity("com.tencent.mobileqq.activity.VisitorsActivity");
|
||||
|
||||
while(notStopped()){
|
||||
var i = 0;
|
||||
var i = 0;
|
||||
while(i < 10){
|
||||
i += 赞() ? 1 : 0;
|
||||
click("取消");
|
||||
}
|
||||
显示更多();
|
||||
下滑();
|
||||
if(currentActivity() == "com.tencent.mobileqq.activity.VisitorsActivity"){
|
||||
下滑();
|
||||
}
|
||||
}
|
||||
21
app/src/main/assets/sample/QQ与微信/QQ名片点赞(只点赞好友).js
Normal file
21
app/src/main/assets/sample/QQ与微信/QQ名片点赞(只点赞好友).js
Normal file
@ -0,0 +1,21 @@
|
||||
"auto";
|
||||
|
||||
toast("请打开自己的资料页,点击点赞图标");
|
||||
sleep(500);
|
||||
waitForActivity("com.tencent.mobileqq.activity.VisitorsActivity");
|
||||
|
||||
while(notStopped()){
|
||||
for(var i = 0; i < 10; i++){
|
||||
className("ImageView").desc("赞").untilFind().each(function(like){
|
||||
var parent = like.parent();
|
||||
if(like.parent().findByText("(好友)")){
|
||||
like.click();
|
||||
}
|
||||
});
|
||||
}
|
||||
click("显示更多");
|
||||
click("显示更多");
|
||||
if(currentActivity() == "com.tencent.mobileqq.activity.VisitorsActivity"){
|
||||
className("AbsListView").scrollable().scrollForward();
|
||||
}
|
||||
}
|
||||
@ -1,24 +1,32 @@
|
||||
"auto";
|
||||
var liked = {};
|
||||
|
||||
launchApp("QQ");
|
||||
toast("请打开要点赞的群");
|
||||
sleep(500);
|
||||
if(currentActivity() != "com.tencent.mobileqq.activity.TroopMemberListActivity"){
|
||||
openGroupMemberList();
|
||||
}
|
||||
|
||||
while(true){
|
||||
var list = className("AbsListView").findOne();
|
||||
list.children().each(function(child){
|
||||
if(child.className() != "android.widget.FrameLayout"){
|
||||
return;
|
||||
}
|
||||
if(!isGroupMember(child)){
|
||||
return;
|
||||
}
|
||||
if(isMyself(child)){
|
||||
return;
|
||||
}
|
||||
child.child(0).click();
|
||||
like();
|
||||
while(!click("返回"));
|
||||
while(!click("成员资料"));
|
||||
while(!click("返回"));
|
||||
});
|
||||
className("AbsListView").findOne().scrollForward();
|
||||
var count = list.childCount();
|
||||
for(var i = 0; i < count; i++){
|
||||
var child = list.child(i);
|
||||
if(!child || child.className() != "android.widget.FrameLayout"){
|
||||
continue;
|
||||
}
|
||||
if(!isGroupMember(child) || isMyself(child)){
|
||||
continue;
|
||||
}
|
||||
child.child(0).click();
|
||||
sleep(500);
|
||||
like();
|
||||
while(!click("返回"));
|
||||
while(!click("成员资料"));
|
||||
while(!click("返回"));
|
||||
sleep(500);
|
||||
}
|
||||
list.scrollForward();
|
||||
}
|
||||
|
||||
|
||||
@ -26,6 +34,9 @@ function isGroupMember(child){
|
||||
if(child.childCount() != 1){
|
||||
return false;
|
||||
}
|
||||
if(!child.findByText("Baby Q").isEmpty()){
|
||||
return false;
|
||||
}
|
||||
return child.child(0) && child.child(0).className() == "android.widget.FrameLayout";
|
||||
}
|
||||
|
||||
@ -35,11 +46,6 @@ function isMyself(child){
|
||||
}
|
||||
|
||||
function like(){
|
||||
var qq = getQQ();
|
||||
if(liked[qq]){
|
||||
while(!click("返回"));
|
||||
return;
|
||||
}
|
||||
while(!click("更多"));
|
||||
while(!click("查看个人资料卡"));
|
||||
var likeBtn = descEndsWith("点击可赞").findOne();
|
||||
@ -52,4 +58,12 @@ function like(){
|
||||
function getQQ(){
|
||||
var qq = textMatches("\\d{5,12}").findOne().text();
|
||||
return qq;
|
||||
}
|
||||
|
||||
function openGroupMemberList(){
|
||||
desc("群资料卡").click();
|
||||
var groupMemberCountView = textEndsWith("名成员").findOne();
|
||||
var groupMemberCount = parseInt(/\d+/.exec(groupMemberCountView.text())[0]);
|
||||
groupMemberCountView.parent().click();
|
||||
sleep(groupMemberCount * 4);
|
||||
}
|
||||
@ -30,7 +30,12 @@ public class HoverMenuManger {
|
||||
if (!HoverMenuService.isServiceRunning()) {
|
||||
if (!SettingsCompat.canDrawOverlays(App.getApp())) {
|
||||
Toast.makeText(App.getApp(), R.string.text_no_floating_window_permission, Toast.LENGTH_SHORT).show();
|
||||
SettingsCompat.manageDrawOverlays(App.getApp());
|
||||
try {
|
||||
SettingsCompat.manageDrawOverlays(App.getApp());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
IntentUtil.goToAppDetailSettings(App.getApp());
|
||||
}
|
||||
} else {
|
||||
HoverMenuService.startService(App.getApp());
|
||||
}
|
||||
|
||||
@ -22,6 +22,7 @@ import com.stardust.scriptdroid.external.floatingwindow.menu.view.FloatingLayout
|
||||
import com.stardust.scriptdroid.external.floatingwindow.menu.view.FloatingLayoutHierarchyView;
|
||||
import com.stardust.scriptdroid.tool.AccessibilityServiceTool;
|
||||
import com.stardust.theme.ThemeColorManagerCompat;
|
||||
import com.stardust.util.IntentUtil;
|
||||
import com.stardust.util.MessageEvent;
|
||||
import com.stardust.util.MessageIntent;
|
||||
|
||||
@ -129,7 +130,12 @@ public class HoverMenuService extends Service {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(this, R.string.text_no_floating_window_permission, Toast.LENGTH_SHORT).show();
|
||||
SettingsCompat.manageDrawOverlays(this);
|
||||
try {
|
||||
SettingsCompat.manageDrawOverlays(this);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
IntentUtil.goToAppDetailSettings(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -17,6 +17,7 @@ import com.stardust.scriptdroid.tool.AccessibilityServiceTool;
|
||||
import com.stardust.scriptdroid.ui.main.MainActivity_;
|
||||
import com.stardust.util.ClipboardUtil;
|
||||
import com.stardust.util.MessageEvent;
|
||||
import com.stardust.view.accessibility.AccessibilityService;
|
||||
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
@ -61,10 +62,14 @@ public class MainMenuNavigatorContent implements NavigatorContent {
|
||||
Toast.makeText(mView.getContext(), R.string.text_layout_inspector_is_dumping, Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
if (inspector.getCapture() == null) {
|
||||
if (AccessibilityService.getInstance() == null) {
|
||||
Toast.makeText(mView.getContext(), R.string.text_no_accessibility_permission_to_capture, Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
if (inspector.getCapture() == null) {
|
||||
Toast.makeText(mView.getContext(), R.string.text_inspect_failed, Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package com.stardust.scriptdroid.external.floatingwindow.menu.layout_inspector;
|
||||
|
||||
import android.os.Build;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.util.Log;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
|
||||
@ -43,6 +45,17 @@ public class LayoutInspector {
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
|
||||
private void refreshChildList(AccessibilityNodeInfo root) {
|
||||
if (root == null)
|
||||
return;
|
||||
root.refresh();
|
||||
int childCount = root.getChildCount();
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
refreshChildList(root.getChild(i));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDumping() {
|
||||
return mDumping;
|
||||
}
|
||||
|
||||
@ -207,6 +207,7 @@
|
||||
<string name="text_number_format_error">格式错误</string>
|
||||
<string name="text_accessibility_settings">打开无障碍服务</string>
|
||||
<string name="text_discard_record">放弃录制</string>
|
||||
<string name="text_inspect_failed">布局抓取失败,请关闭悬浮窗后动一下页面重试</string>
|
||||
|
||||
<string-array name="record_control_keys">
|
||||
<item>无</item>
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:accessibilityEventTypes="typeNotificationStateChanged|typeAnnouncement|typeAssistReadingContext|typeContextClicked|typeGestureDetectionEnd|typeGestureDetectionStart|typeTouchExplorationGestureEnd|typeTouchExplorationGestureStart|typeTouchInteractionEnd|typeTouchInteractionStart|typeViewAccessibilityFocusCleared|typeViewAccessibilityFocused|typeViewClicked|typeViewHoverEnter|typeViewHoverExit|typeViewFocused|typeViewLongClicked|typeViewScrolled|typeViewSelected|typeViewTextChanged|typeViewTextSelectionChanged|typeViewTextTraversedAtMovementGranularity|typeWindowContentChanged|typeWindowsChanged|typeWindowStateChanged"
|
||||
android:accessibilityEventTypes="typeContextClicked|typeViewClicked|typeViewHoverEnter|typeViewHoverExit|typeViewFocused|typeViewLongClicked|typeViewScrolled|typeViewSelected|typeViewTextChanged|typeViewTextSelectionChanged|typeWindowContentChanged|typeWindowsChanged|typeWindowStateChanged"
|
||||
android:accessibilityFeedbackType="feedbackGeneric"
|
||||
android:accessibilityFlags="flagIncludeNotImportantViews|flagReportViewIds|flagRetrieveInteractiveWindows|flagRequestEnhancedWebAccessibility"
|
||||
android:accessibilityFlags="flagIncludeNotImportantViews|flagReportViewIds|flagRequestEnhancedWebAccessibility"
|
||||
android:canPerformGestures="true"
|
||||
android:canRequestEnhancedWebAccessibility="true"
|
||||
android:canRetrieveWindowContent="true"
|
||||
|
||||
@ -1,22 +1,25 @@
|
||||
package com.stardust.view.accessibility;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.CallSuper;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.WindowManager;
|
||||
import android.view.InputDevice;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
import android.widget.TextView;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.stardust.util.ScreenMetrics;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.Condition;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
@ -27,8 +30,6 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
public class AccessibilityService extends android.accessibilityservice.AccessibilityService {
|
||||
|
||||
private AccessibilityNodeInfo mRootInActiveWindow;
|
||||
|
||||
|
||||
private static final String TAG = "AccessibilityService";
|
||||
|
||||
@ -38,6 +39,8 @@ public class AccessibilityService extends android.accessibilityservice.Accessibi
|
||||
private static AccessibilityService instance;
|
||||
private static boolean containsAllEventTypes = false;
|
||||
private static final Set<Integer> eventTypes = new HashSet<>();
|
||||
private volatile AccessibilityNodeInfo mRootInActiveWindow;
|
||||
private Timer mTimer;
|
||||
|
||||
public static void addDelegate(int uniquePriority, AccessibilityDelegate delegate) {
|
||||
mDelegates.put(uniquePriority, delegate);
|
||||
@ -59,15 +62,6 @@ public class AccessibilityService extends android.accessibilityservice.Accessibi
|
||||
@Override
|
||||
public void onAccessibilityEvent(final AccessibilityEvent event) {
|
||||
Log.v(TAG, "onAccessibilityEvent: " + event);
|
||||
if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
|
||||
|| event.getEventType() == AccessibilityEvent.TYPE_VIEW_HOVER_ENTER
|
||||
|| event.getEventType() == AccessibilityEvent.TYPE_VIEW_HOVER_EXIT) {
|
||||
AccessibilityNodeInfo root = super.getRootInActiveWindow();
|
||||
if (root != null) {
|
||||
mRootInActiveWindow = root;
|
||||
Log.d(TAG, "rootInActiveWindow: " + mRootInActiveWindow);
|
||||
}
|
||||
}
|
||||
if (!containsAllEventTypes && !eventTypes.contains(event.getEventType()))
|
||||
return;
|
||||
for (Map.Entry<Integer, AccessibilityDelegate> entry : mDelegates.entrySet()) {
|
||||
@ -90,13 +84,17 @@ public class AccessibilityService extends android.accessibilityservice.Accessibi
|
||||
|
||||
@Override
|
||||
public AccessibilityNodeInfo getRootInActiveWindow() {
|
||||
return mRootInActiveWindow;
|
||||
try {
|
||||
return super.getRootInActiveWindow();
|
||||
} catch (IllegalStateException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
instance = null;
|
||||
mTimer.cancel();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@ -109,6 +107,16 @@ public class AccessibilityService extends android.accessibilityservice.Accessibi
|
||||
LOCK.lock();
|
||||
ENABLED.signalAll();
|
||||
LOCK.unlock();
|
||||
mTimer = new Timer();
|
||||
mTimer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
AccessibilityNodeInfo root = getRootInActiveWindow();
|
||||
if (root != null) {
|
||||
mRootInActiveWindow = root;
|
||||
}
|
||||
}
|
||||
}, 0, 100);
|
||||
// FIXME: 2017/2/12 有时在无障碍中开启服务后这里不会调用服务也不会运行,安卓的BUG???
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
package com.stardust.view.accessibility;
|
||||
|
||||
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/7/13.
|
||||
*/
|
||||
|
||||
public class LayoutInspectService extends AccessibilityService {
|
||||
|
||||
private static LayoutInspectService instance;
|
||||
|
||||
public static LayoutInspectService getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onServiceConnected() {
|
||||
AccessibilityServiceInfo info = getServiceInfo();
|
||||
info.flags |= AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS;
|
||||
setServiceInfo(info);
|
||||
super.onServiceConnected();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user