Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
李雅为
/
wechat_click
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
5720b9bd
authored
Apr 18, 2018
by
jeffrey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
看看自动打开咋搞
parent
5dd575b0
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
811 additions
and
652 deletions
+811
-652
app/src/main/java/com/xf/weixinclick/MainActivity.java
+8
-8
app/src/main/java/com/xf/weixinclick/NewService.java
+66
-605
app/src/main/java/com/xf/weixinclick/agent/AutoProcesser.java
+4
-0
app/src/main/java/com/xf/weixinclick/agent/UiHierarchyFinder.java
+8
-3
app/src/main/java/com/xf/weixinclick/agent/auto/EnableAccessibility.java
+39
-21
app/src/main/java/com/xf/weixinclick/core/Cmder.java
+140
-0
app/src/main/java/com/xf/weixinclick/core/MsgSender.java
+3
-0
app/src/main/java/com/xf/weixinclick/core/TaskSession2.java
+340
-0
app/src/main/java/com/xf/weixinclick/core/WXIdsConfig.java
+2
-2
app/src/main/java/com/xf/weixinclick/core/WXIdsConfig2.java
+9
-5
app/src/main/java/com/xf/weixinclick/core/Worker2.java
+174
-0
app/src/main/java/com/xf/weixinclick/receiver/MyMessageReceiver.java
+7
-7
app/src/main/java/com/xf/weixinclick/utils/Accessibilitys.java
+3
-1
app/src/main/java/com/xf/weixinclick/utils/Common.java
+8
-0
No files found.
app/src/main/java/com/xf/weixinclick/MainActivity.java
View file @
5720b9bd
...
...
@@ -164,14 +164,14 @@ public class MainActivity extends BaseActivity {
@Override
public
void
onClick
(
View
v
)
{
// WeChatStatus.receiverMsg();
Intent
intent
=
new
Intent
();
//// 报名该有activity
ComponentName
cmp
=
new
ComponentName
(
"com.tencent.mm"
,
"com.tencent.mm.ui.LauncherUI"
);
intent
.
setAction
(
Intent
.
ACTION_MAIN
);
intent
.
addCategory
(
Intent
.
CATEGORY_LAUNCHER
);
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
|
Intent
.
FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
);
intent
.
setComponent
(
cmp
);
startActivity
(
intent
);
//
Intent intent = new Intent();
//
//// 报名该有activity
//
ComponentName cmp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI");
//
intent.setAction(Intent.ACTION_MAIN);
//
intent.addCategory(Intent.CATEGORY_LAUNCHER);
//
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
//
intent.setComponent(cmp);
//
startActivity(intent);
new
Thread
(
new
Runnable
()
{
...
...
app/src/main/java/com/xf/weixinclick/NewService.java
View file @
5720b9bd
...
...
@@ -20,6 +20,7 @@ import android.widget.Toast;
import
com.alibaba.sdk.android.push.noonesdk.PushServiceFactory
;
import
com.xf.weixinclick.bean.DelayBean
;
import
com.xf.weixinclick.bean.msg.ReceiverMsg
;
import
com.xf.weixinclick.core.Worker2
;
import
com.xf.weixinclick.http.HttpClientApi
;
import
com.xf.weixinclick.http.HttpSubscriber
;
import
com.xf.weixinclick.receiver.WeChatStatus
;
...
...
@@ -61,14 +62,13 @@ public class NewService extends AccessibilityService {
private
final
static
String
MM_PNAME
=
"com.tencent.mm"
;
public
static
final
String
PARAMS_MSG
=
"msg"
;
int
ACTION_SUCCESS
=
1
;
int
ACTION_FAIL
=
0
;
// private String Url = "https://weapp-dev.wangjia.com/qr.jpg?dd=1";
private
String
message_id
=
"123"
;
private
DelayBean
delayBean
;
private
ReceiverMsg
taskMsg
;
//
private ReceiverMsg taskMsg;
/**
* 当前任务的步骤,完成一步+1
*/
...
...
@@ -82,428 +82,47 @@ public class NewService extends AccessibilityService {
* 因为首次进来的时候检测到不是首页的时候也会返回,所以用step的话不准确,要单独弄个变量出来
*/
private
boolean
inBacking
=
false
;
private
int
actionResult
=
ACTION_FAIL
;
// @Override
// public int onStartCommand(Intent intent, int flags, int startId) {
//
// Log.d("fei", "onStartCommand start");
//// NotificationUtils.foreground(getApplicationContext(),this);
////
//// //todo 当多任务过来的时候,没处理
//// if (intent != null && intent.getSerializableExtra(PARAMS_MSG) != null){
//// //先设置变量 然后唤起微信,微信唤起后会通知onAccessibilityEvent
//// //然后一步步走流程
//// ReceiverMsg msg = (ReceiverMsg) intent.getSerializableExtra(PARAMS_MSG);
//// taskMsg = msg;
//// delayBean = msg.getTime_config();
//// step=0;
////
//// awakeWechat(getApplicationContext());
//// }
//
// //当service因为低内存被杀掉后,等内存足够时可以重启
// return START_STICKY;
// }
@Subscribe
public
void
receiverMsg
(
final
ReceiverMsg
msg
)
{
logToastAndUpload
(
TAG
,
"receiverMsg"
);
delayBean
=
msg
.
getTime_config
();
if
(
delayBean
==
null
){
logToastAndUpload
(
TAG
,
"delayBean 是空"
);
}
if
(
step
!=
0
&&
taskMsg
!=
null
){
long
haveRunTime
=
System
.
currentTimeMillis
()/
1000
-
taskMsg
.
getPushed_at
();
if
(
haveRunTime
<
20
){
logToastAndUpload
(
TAG
,
"前还有任务在执行,什么都不做"
);
return
;
}
if
(
haveRunTime
>
40
){
logToastAndUpload
(
TAG
,
"之前任务超过40秒,清除并开始新任务"
);
resetAll
();
}
Worker2
mWorker
=
null
;
@Override
public
void
onCreate
()
{
super
.
onCreate
();
if
(
mWorker
==
null
){
mWorker
=
Worker2
.
getInstance
();
}
//发送触发的消息给service,难道微信没有触发?
delayDeal
(
delayBean
.
getAfter_open_weixin_file_helper_delay
(),
new
IDelayMethord
()
{
@Override
public
void
delayMethord
()
{
logToastAndUpload
(
TAG
,
"receiverMsg里面触发下页面消息 unique_id "
+
msg
.
getUnique_id
());
WeChatStatus
.
receiverMsg
();
// String Url = msg.getQr_addr();
// Log.d(TAG, "receiverMsg里面触发下页面消息 Url " + Url);
message_id
=
msg
.
getUnique_id
();
taskMsg
=
msg
;
step
=
0
;
AccessibilityEvent
accessibilityEvent
=
AccessibilityEvent
.
obtain
(
32
);
accessibilityEvent
.
setClassName
(
WeChatUi
);
onAccessibilityEvent
(
accessibilityEvent
);
}
});
Log
.
d
(
TAG
,
"NewService onCreate"
);
}
@Override
public
void
onAccessibilityEvent
(
AccessibilityEvent
event
)
{
Log
.
d
(
TAG
,
"NewService onAccessibilityEvent"
);
if
(!
EventBus
.
getDefault
().
isRegistered
(
this
)){
EventBus
.
getDefault
().
register
(
this
);
}
int
eventType
=
event
.
getEventType
();
String
className
=
event
.
getClassName
().
toString
();
logToastAndUpload
(
TAG
,
"get event = "
+
eventType
+
" class "
+
className
+
" step "
+
step
);
long
currentTime
=
System
.
currentTimeMillis
();
if
(
currentTime
-
lastShowToastTime
>
10
*
1000
){
boolean
taskMsgExist
=
taskMsg
==
null
;
String
taskMsgPrompt
=
taskMsgExist
?
"消息是空"
:
"消息存在"
;
logToastAndUpload
(
TAG
,
"辅助service还活着 step = "
+
step
+
" "
+
taskMsgPrompt
);
lastShowToastTime
=
currentTime
;
}
if
(!
className
.
contains
(
MM_PNAME
))
{
return
;
}
if
(
inBacking
){
logToastAndUpload
(
TAG
,
"执行返回中"
);
// showToast(getApplicationContext(),"执行返回中");
//都是点击左上角
execShellCmd
(
"input tap "
+
dip2px
(
20
)
+
" "
+
dip2px
(
50
));
if
(
className
.
equals
(
WeChatUi
)){
//到了首页就结束
inBacking
=
false
;
logToastAndUpload
(
TAG
,
"执行返回完成"
);
// showToast(getApplicationContext(),"执行返回完成");
upResult
(
actionResult
,
message_id
);
}
return
;
}
if
(
taskMsg
==
null
){
logToastAndUpload
(
TAG
,
"NewService but taskMsg is null"
);
return
;
}
if
(
step
==
0
&&
!
findNodeByTexts
(
this
,
"微信"
,
"通讯录"
,
"发现"
,
"我"
)){
logToastAndUpload
(
TAG
,
"当前页不是首页"
);
// showToast(getApplicationContext(),"当前页不是首页");
turnBack
(
ACTION_FAIL
);
resetAll
();
return
;
}
// if (eventType == 32 && className.contains("WebviewScanImageActivity")) {
// return;
// }
// if (WeChatStatus.isClose()) {
// return;
// }
// if (step == 0&& !findNodeByTexts(this,"微信","通讯录","发现","我")){
// Log.d(TAG, "是在第一步,但不是在首页,重新进入再来");
// resetAll();
// showToast(getApplicationContext(),"当前页不是首页");
// turnBack(ACTION_FAIL,2);
// }
if
(
step
==
0
&&
findNodeByTexts
(
this
,
"微信"
,
"通讯录"
,
"发现"
,
"我"
)){
//点击文件传输助手的位置
//最好还是找到文字然后点击位置
//没办法 首页打印出来的是通讯录的布局,所以坐标是错误的
step
++;
logToastAndUpload
(
TAG
,
"准备点击首页的文件传输助手"
);
delayDeal
(
delayBean
.
getAfter_open_weixin_index_delay
(),
new
IDelayMethord
()
{
@Override
public
void
delayMethord
()
{
AccessibilityNodeInfo
rootNode
=
getRootInActiveWindow
();
if
(
rootNode
==
null
){
return
;
}
if
(!
findNodeByTexts
(
NewService
.
this
,
"微信"
,
"通讯录"
,
"发现"
,
"我"
)){
logToastAndUpload
(
TAG
,
"没有发现文件传输助手,不点击"
);
// showToast(myApplication.getInstence(),"没有发现文件传输助手,不点击");
return
;
}
logToastAndUpload
(
TAG
,
"开始点击首页的文件传输助手"
);
printAllNode
();
execShellCmd
(
"input tap 220 200"
);
step
++;
}
});
delayDeal
(
delayBean
.
getAfter_open_weixin_index_delay
()+
5000
,
new
IDelayMethord
()
{
@Override
public
void
delayMethord
()
{
step
++;
logToastAndUpload
(
TAG
,
"文件传输详情页面_填充_准备"
);
// delayDeal(5000, new IDelayMethord() {
// @Override
// public void delayMethord() {
logToastAndUpload
(
TAG
,
"文件传输详情页面_填充"
);
printAllNode
();
if
(
fill
()){
logToastAndUpload
(
TAG
,
"文件传输详情页面_填充_完成"
);
send
();
clickMsg
(
getRootInActiveWindow
());
step
++;
}
else
{
logToastAndUpload
(
TAG
,
"文件传输详情页面_填充_失败"
);
}
// }
// });
}
});
// clickHomeWJCSZS();
}
// if (step == 1 ){
// printAllNode();
// }
// && findNodeByTexts(this,"文件传输助手")
// if (step == 2 && !findNodeByTexts(this,"文件传输助手")){
// resetAll();
// logToastAndUpload(TAG,"当前页不是文件传输助手页");
// turnBack(ACTION_FAIL);
// return;
// }
// if (step == 2 && findNodeByTexts(this,"文件传输助手")){
// step++;
// logToastAndUpload(TAG, "文件传输详情页面_填充_准备");
// delayDeal(5000, new IDelayMethord() {
// @Override
// public void delayMethord() {
// logToastAndUpload(TAG, "文件传输详情页面_填充");
// printAllNode();
//
// if(fill()){
// logToastAndUpload(TAG, "文件传输详情页面_填充_完成");
// send();
// clickMsg(getRootInActiveWindow());
//
// step++;
// }else{
// logToastAndUpload(TAG, "文件传输详情页面_填充_失败");
// }
// }
// });
//
// }
// if (step == 4 && findNodeByTexts(this,"文件传输助手")){
// //填充完了 有时候发送不出现,那就再点击下文字 ,点完了要变下空白区域 让输入框消失
// execShellCmd("input tap " + dip2px(130) + " " + dip2px(600));
// execShellCmd("input tap " + dip2px(10) + " " + dip2px(200));
// Log.d(TAG, "文件传输详情页面_发送");
// send();
// step++;
//
// }
// if (step == 4 && findNodeByTexts(this,"文件传输助手")){
// //填充完了 有时候发送不出现,那就再点击下文字 ,点完了要变下空白区域 让输入框消失
// execShellCmd("input tap " + dip2px(130) + " " + dip2px(600));
// execShellCmd("input tap " + dip2px(10) + " " + dip2px(200));
// Log.d(TAG, "文件传输详情页面_点击发送的文字");
// clickMsg(getRootInActiveWindow());
// step++;
// long currentTime = System.currentTimeMillis();
// if (currentTime - lastShowToastTime > 10 *1000){
// boolean taskMsgExist = taskMsg == null ;
// String taskMsgPrompt = taskMsgExist ? "消息是空":"消息存在";
// logToastAndUpload(TAG,"辅助service还活着 step = " + step + " " + taskMsgPrompt);
// lastShowToastTime = currentTime;
// }
if
(
step
==
4
&&
className
.
equals
(
WeChatWebView
)){
step
++;
// 二维码长点击
delayDeal
(
delayBean
.
getAfter_click_message_delay
(),
new
IDelayMethord
()
{
@Override
public
void
delayMethord
()
{
execShellCmd
(
"input swipe 300 600 300 600 4000"
);
step
++;
}
});
}
if
(
step
==
6
&&
className
.
equals
(
WeChatAlert
)){
logToastAndUpload
(
TAG
,
"开始点击确认二维码"
);
step
++;
delayDeal
(
delayBean
.
getLong_press_qrcode_delay
(),
new
IDelayMethord
()
{
@Override
public
void
delayMethord
()
{
pressRecognitionImg
();
step
++;
}
});
}
if
(
step
==
8
&&
className
.
equals
(
WeChatWebView
)){
logToastAndUpload
(
TAG
,
"开始点击确认登录"
);
pressSure
();
step
++;
// resetAll();
if
(
mWorker
==
null
){
mWorker
=
Worker2
.
getInstance
();
}
// switch (eventType) {
// //点击事件
// case 32:
// switch (className) {
// case WeChatUi:
// if (clickDone){
// Log.d("fei ", "点击过了文件传输助手 ,准备下一步");
//
// delayDeal(1000, new IDelayMethord() {
// @Override
// public void delayMethord() {
// if (WeChatStatus.status[0] ) {
//
// Log.d("fei ", "进入文件传输详情页面");
// if (fill()) {
//
// //填充完了 有时候发送不出现,那就再点击下文字 ,点完了要变下空白区域 让输入框消失
// execShellCmd("input tap " + dip2px(130) + " " + dip2px(600));
// execShellCmd("input tap " + dip2px(10) + " " + dip2px(200));
// Log.d("fei ", "文件传输详情页面_填充成功准备发送");
// delayDeal(delayBean.getAfter_paste_message_delay(), new IDelayMethord() {
// @Override
// public void delayMethord() {
// Log.d("fei ", "文件传输详情页面_发送");
//
// send();
// }
// });
// delayDeal(delayBean.getAfter_paste_message_delay()+delayBean.getAfter_send_message_delay()+2000, new IDelayMethord() {
// @Override
// public void delayMethord() {
// Log.d("fei", "文件传输详情页面_点击发送的文字");
// clickMsg(getRootInActiveWindow());
// }
// });
// WeChatStatus.finishClick();
//
// } else {
// Log.d("fei", "文件传输详情页面_填充失败");
//
// }
// }
//
// }
// });
// }else {
// Log.d("fei ", "没有点击过了文件传输助手什么都不干");
//
// }
//
//
// break;
// case WeChatWebView:
// if(WeChatStatus.status[1])
//
// {
// WeChatStatus.longPressCodeFinish();
// Log.d("fei", "长按二维码");
//
// longPress();
// } else if(WeChatStatus.status[3]&&!WeChatStatus.status[2])
//
// {
// //这里加一句 第二步已经完成
// WeChatStatus.pressSureFinish();
// Log.d("fei", "点击确认关注");
//
// pressSure();
// }
// break;
// case WeChatAlert:
// if(WeChatStatus.status[2])
//
// {
// delayDeal(delayBean.getLong_press_qrcode_delay(), new IDelayMethord() {
// @Override
// public void delayMethord() {
// Log.d("fei", "点击识别二维码");
// pressRecognitionImg();
// }
// });
// }
// break;
// default:
// break;
// }
// break;
// default:
// break;
// }
mWorker
.
onAccessibilityEvent
(
getRootInActiveWindow
(),
event
);
}
@Override
public
void
onInterrupt
()
{
Log
.
d
(
TAG
,
"NewService onInterrupt"
);
if
(
EventBus
.
getDefault
().
isRegistered
(
this
))
{
EventBus
.
getDefault
().
unregister
(
this
);
if
(
mWorker
!=
null
)
{
mWorker
.
onIntercept
(
);
}
}
@Override
protected
boolean
onKeyEvent
(
KeyEvent
event
)
{
return
super
.
onKeyEvent
(
event
);
}
/**
* 二维码长点击
*
*/
private
void
longPress
()
{
delayDeal
(
delayBean
.
getAfter_click_message_delay
(),
new
IDelayMethord
()
{
@Override
public
void
delayMethord
()
{
execShellCmd
(
"input swipe 300 600 300 600 4000"
);
}
});
}
/**
* 点击识别图中二维码
*/
void
pressRecognitionImg
()
{
List
<
AccessibilityNodeInfo
>
allData
=
getRootInActiveWindow
()
.
findAccessibilityNodeInfosByText
(
needClick
);
if
(
allData
.
isEmpty
())
{
turnBack
(
ACTION_FAIL
);
}
else
{
for
(
AccessibilityNodeInfo
temp
:
allData
)
{
Rect
rect
=
new
Rect
();
temp
.
getBoundsInScreen
(
rect
);
final
float
x
=
rect
.
left
+
dip2px
(
5
),
y
=
rect
.
top
+
dip2px
(
5
);
Log
.
d
(
TAG
,
String
.
format
(
"click %f %f "
,
x
,
y
));
execShellCmd
(
"input tap "
+
x
+
" "
+
y
);
WeChatStatus
.
clickCodeFinish
();
}
}
}
/**
* 点击确认执行关注
...
...
@@ -558,7 +177,6 @@ public class NewService extends AccessibilityService {
public
void
delayMethord
()
{
Log
.
d
(
TAG
,
String
.
format
(
"确认页的最终超时确认"
));
isPassTime
();
}
});
}
else
{
...
...
@@ -579,7 +197,6 @@ public class NewService extends AccessibilityService {
@Override
public
void
delayMethord
()
{
isPassTime
();
}
});
...
...
@@ -587,209 +204,53 @@ public class NewService extends AccessibilityService {
}
/**
* 点击首页的文件传输助手
*/
void
clickHomeWJCSZS
(){
AccessibilityNodeInfo
root
=
getRootInActiveWindow
();
if
(
root
==
null
){
return
;
}
int
count
=
root
.
getChildCount
();
for
(
int
i
=
0
;
i
<
count
;
i
++){
AccessibilityNodeInfo
nodeInfo
=
root
.
getChild
(
i
);
AccessibilityNodeInfo
findNode
=
recycle
(
nodeInfo
,
"文件传输助手"
);
if
(
findNode
!=
null
){
Rect
rect
=
new
Rect
();
findNode
.
getBoundsInScreen
(
rect
);
execShellCmd
(
"input tap "
+
rect
.
left
+
" "
+
rect
.
top
);
Log
.
d
(
TAG
,
String
.
format
(
"找到了文件传输助手 %d %d"
,
rect
.
left
,
rect
.
top
));
Log
.
i
(
TAG
,
"child widget----------------------------"
+
findNode
.
getClassName
());
Log
.
i
(
TAG
,
"Text:"
+
findNode
.
getText
());
Log
.
i
(
TAG
,
"windowId:"
+
findNode
.
getWindowId
());
Log
.
i
(
TAG
,
"rect:"
+
rect
.
toString
());
findNode
.
getBoundsInParent
(
rect
);
Log
.
i
(
TAG
,
"rect:"
+
rect
.
toString
());
return
;
}
}
Log
.
d
(
TAG
,
String
.
format
(
"没有找到了文件传输助手"
));
}
void
resetAll
(){
taskMsg
=
null
;
step
=
0
;
}
/**
* 是否过期
*/
void
isPassTime
()
{
try
{
List
<
AccessibilityNodeInfo
>
allData
=
getRootInActiveWindow
()
.
findAccessibilityNodeInfosByText
(
needBack2
);
if
(
allData
.
isEmpty
())
{
logToastAndUpload
(
TAG
,
String
.
format
(
"回头了成功 没有确定按钮"
));
turnBack
(
ACTION_SUCCESS
);
}
else
{
for
(
AccessibilityNodeInfo
temp
:
allData
)
{
Log
.
d
(
TAG
,
String
.
format
(
"回头了 有确定按钮 再点击下"
));
Rect
rect
=
new
Rect
();
temp
.
getBoundsInScreen
(
rect
);
final
float
x
=
rect
.
left
+
dip2px
(
5
),
y
=
rect
.
top
+
dip2px
(
5
);
execShellCmd
(
"input tap "
+
x
+
" "
+
y
);
}
Log
.
d
(
TAG
,
String
.
format
(
"回头了 失败"
));
delayDeal
(
800
,
new
IDelayMethord
()
{
@Override
public
void
delayMethord
()
{
turnBack
(
ACTION_FAIL
);
}
});
}
}
catch
(
Exception
ignored
)
{
logToastAndUpload
(
TAG
,
"异常 "
+
ignored
.
getMessage
());
}
}
private
void
turnBack
(
int
code
){
Log
.
d
(
TAG
,
"执行返回"
+
code
+
"turnBack"
);
inBacking
=
true
;
//需要返回
execShellCmd
(
"input keyevent 4"
);
resetAll
();
// upResult(code,message_id);
}
/**
* 返回
*/
private
void
turnBack
(
final
int
code
,
int
size
)
{
Log
.
d
(
TAG
,
"执行返回"
+
code
+
" size "
+
size
);
//需要返回
execShellCmd
(
"input keyevent 4"
);
delayDeal
(
1000
,
new
IDelayMethord
()
{
@Override
public
void
delayMethord
()
{
Log
.
d
(
TAG
,
"执行返回 step 1"
);
execShellCmd
(
"input keyevent 4"
);
}
});
delayDeal
(
2000
,
new
IDelayMethord
()
{
@Override
public
void
delayMethord
()
{
Log
.
d
(
TAG
,
"执行返回 step 2"
);
execShellCmd
(
"input keyevent 4"
);
}
});
delayDeal
(
3000
,
new
IDelayMethord
()
{
@Override
public
void
delayMethord
()
{
Log
.
d
(
TAG
,
"执行返回 step 3"
);
execShellCmd
(
"input keyevent 4"
);
}
});
delayDeal
(
4000
,
new
IDelayMethord
()
{
@Override
public
void
delayMethord
()
{
Log
.
d
(
"fei "
,
"执行返回 step 4"
);
execShellCmd
(
"input keyevent 4"
);
upResult
(
code
,
message_id
);
}
});
// if (size > 1) {
// delayDeal(4500, new IDelayMethord() {
// @Override
// public void delayMethord() {
// Log.d("fei ", "执行返回 step 5");
// execShellCmd("input keyevent 4");
// }
// });
// }
// WeChatStatus.finishAll();
// String uniqueID = taskMsg.getUnique_id();
resetAll
();
}
/**
* 上传结果
*
* @param code
*/
private
void
upResult
(
final
int
code
,
final
String
id
)
{
if
(
TextUtils
.
isEmpty
(
id
)){
return
;
}
Log
.
d
(
TAG
,
"开始上报结果 "
+
code
+
" "
+
id
);
showToast
(
getApplicationContext
(),
"开始上报结果 "
+
code
+
" "
+
id
);
HttpClientApi
.
devicesScan
(
PushServiceFactory
.
getCloudPushService
().
getDeviceId
(),
code
,
id
,
new
HttpSubscriber
<
String
>()
{
@Override
public
void
onCompleted
()
{
}
@Override
public
void
onNext
(
String
responseBase
)
{
Log
.
d
(
TAG
,
"上报结果 "
+
responseBase
);
showToast
(
getApplicationContext
(),
String
.
format
(
"code %d message_id %s 上报结果 %s"
,
code
,
id
,
responseBase
));
}
});
}
/**
* 点击消息
*
* @param rootNode
*/
@SuppressLint
(
"NewApi"
)
private
void
clickMsg
(
AccessibilityNodeInfo
rootNode
)
{
long
temp
=
System
.
currentTimeMillis
();
if
(
temp
-
times
<
2000
)
{
times
=
temp
;
return
;
}
if
(
rootNode
==
null
)
{
return
;
}
List
<
AccessibilityNodeInfo
>
ac2
=
rootNode
.
findAccessibilityNodeInfosByText
(
taskMsg
.
getQr_addr
());
// List<AccessibilityNodeInfo> ac = rootNode.findAccessibilityNodeInfosByViewId("@id/ji");
List
<
AccessibilityNodeInfo
>
ac
=
rootNode
.
findAccessibilityNodeInfosByViewId
(
"com.tencent.mm:id/ji"
);
AccessibilityNodeInfo
n
=
null
;
if
(
ac
.
size
()
>
0
)
{
n
=
ac
.
get
(
ac
.
size
()
-
1
);
}
if
(
ac2
.
size
()
>
0
)
{
n
=
ac2
.
get
(
ac2
.
size
()
-
1
);
}
if
(
n
!=
null
)
{
// final AccessibilityNodeInfo n = ac.get(ac.size() - 1);
Rect
rect
=
new
Rect
();
n
.
getBoundsInScreen
(
rect
);
final
float
x
=
rect
.
left
+
dip2px
(
40
),
y
=
rect
.
top
+
dip2px
(
20
);
Log
.
d
(
TAG
,
String
.
format
(
"click %f %f "
,
x
,
y
));
execShellCmd
(
"input tap "
+
x
+
" "
+
y
);
}
else
{
Log
.
d
(
TAG
,
"找不到消息 消息url"
+
taskMsg
.
getQr_addr
());
execShellCmd
(
"input tap "
+
dip2px
(
100
)
+
" "
+
dip2px
(
540
));
}
}
//
@SuppressLint("NewApi")
//
private void clickMsg(AccessibilityNodeInfo rootNode) {
//
long temp = System.currentTimeMillis();
//
if (temp - times < 2000) {
//
times = temp;
//
return;
//
}
//
if (rootNode == null) {
//
return;
//
}
//
//
List<AccessibilityNodeInfo> ac2 = rootNode.findAccessibilityNodeInfosByText(taskMsg.getQr_addr());
//
//
List<AccessibilityNodeInfo> ac = rootNode.findAccessibilityNodeInfosByViewId("@id/ji");
//
List<AccessibilityNodeInfo> ac = rootNode.findAccessibilityNodeInfosByViewId("com.tencent.mm:id/ji");
//
AccessibilityNodeInfo n = null;
//
if (ac.size() > 0) {
//
n = ac.get(ac.size() - 1);
//
}
//
if (ac2.size() > 0) {
//
n = ac2.get(ac2.size() - 1);
//
}
//
//
if (n != null) {
//
//
final AccessibilityNodeInfo n = ac.get(ac.size() - 1);
//
//
Rect rect = new Rect();
//
n.getBoundsInScreen(rect);
//
final float x = rect.left + dip2px(40), y = rect.top + dip2px(20);
//
Log.d(TAG, String.format("click %f %f ", x, y));
//
//
execShellCmd("input tap " + x + " " + y);
//
} else {
//
Log.d(TAG, "找不到消息 消息url" + taskMsg.getQr_addr());
//
execShellCmd("input tap " + dip2px(100) + " " + dip2px(540));
//
//
}
//
}
/**
* 执行shell命令
...
...
@@ -857,14 +318,14 @@ public class NewService extends AccessibilityService {
}
}
@SuppressLint
(
"NewApi"
)
private
boolean
fill
()
{
AccessibilityNodeInfo
rootNode
=
getRootInActiveWindow
();
if
(
rootNode
!=
null
&&
taskMsg
!=
null
)
{
return
findEditText
(
rootNode
,
taskMsg
.
getQr_addr
());
}
return
false
;
}
//
@SuppressLint("NewApi")
//
private boolean fill() {
//
AccessibilityNodeInfo rootNode = getRootInActiveWindow();
//
if (rootNode != null && taskMsg != null) {
//
return findEditText(rootNode, taskMsg.getQr_addr());
//
}
//
return false;
//
}
private
boolean
findEditText
(
AccessibilityNodeInfo
rootNode
,
String
content
)
{
int
count
=
rootNode
.
getChildCount
();
...
...
app/src/main/java/com/xf/weixinclick/agent/AutoProcesser.java
View file @
5720b9bd
...
...
@@ -5,6 +5,7 @@ import android.util.Log;
import
android.widget.Toast
;
import
com.xf.weixinclick.agent.auto.EnableAccessibility
;
import
com.xf.weixinclick.agent.auto.EnableUsageStats
;
import
com.xf.weixinclick.core.Cmder
;
import
com.xf.weixinclick.myApplication
;
import
rx.Single
;
import
rx.SingleSubscriber
;
...
...
@@ -44,6 +45,9 @@ public class AutoProcesser {
@Override
public
void
onError
(
Throwable
error
)
{
DebugTools
.
dismiss
();
Cmder
.
clickWxBack
();
Cmder
.
clickWxBack
();
Cmder
.
clickWxBack
();
Log
.
e
(
TAG
,
"onError --> "
,
error
);
if
(
subscriber
!=
null
){
...
...
app/src/main/java/com/xf/weixinclick/agent/UiHierarchyFinder.java
View file @
5720b9bd
package
com
.
xf
.
weixinclick
.
agent
;
import
android.os.SystemClock
;
import
android.support.annotation.NonNull
;
import
android.text.TextUtils
;
import
android.util.Log
;
...
...
@@ -7,6 +8,8 @@ import com.xf.agent.common.CmdResult;
import
com.xf.weixinclick.agent.uiautomator.BasicTreeNode
;
import
com.xf.weixinclick.agent.uiautomator.UiHierarchyXmlLoader
;
import
com.xf.weixinclick.agent.uiautomator.UiNode
;
import
com.xf.weixinclick.core.Cmder
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.concurrent.Callable
;
...
...
@@ -26,10 +29,12 @@ public class UiHierarchyFinder {
public
void
dump
()
{
CmdResult
value
=
AgentExecutor
.
exec
(
CMD
).
toBlocking
().
value
();
// CmdResult value = AgentExecutor.exec(CMD).toBlocking().value();
boolean
success
=
Cmder
.
execShellCmd
(
CMD
);
Log
.
e
(
TAG
,
"dump --> "
+
success
);
SystemClock
.
sleep
(
2000
);
Log
.
e
(
TAG
,
"dump --> "
+
value
);
if
(
value
==
null
||
value
.
code
!=
0
){
if
(!
success
){
throw
new
RuntimeException
(
"dump ERROR !!!"
);
}
...
...
app/src/main/java/com/xf/weixinclick/agent/auto/EnableAccessibility.java
View file @
5720b9bd
...
...
@@ -9,6 +9,8 @@ import com.xf.weixinclick.agent.DebugTools;
import
com.xf.weixinclick.agent.MotionRunner
;
import
com.xf.weixinclick.agent.UiHierarchyFinder
;
import
com.xf.weixinclick.agent.uiautomator.UiNode
;
import
com.xf.weixinclick.core.Cmder
;
import
java.util.List
;
import
java.util.concurrent.Callable
;
...
...
@@ -40,22 +42,31 @@ public class EnableAccessibility implements Callable<Boolean> {
DebugTools
.
log
(
"exec --> 滑动 到底部"
);
Log
.
e
(
TAG
,
"exec --> 滑动 到底部"
);
MotionRunner
.
get
().
scrollDown
(
5
00
);
Cmder
.
scrollDown
(
4
00
);
SystemClock
.
sleep
(
1000
);
MotionRunner
.
get
().
scrollDown
(
800
);
SystemClock
.
sleep
(
1000
);
MotionRunner
.
get
().
scrollDown
(
800
);
Cmder
.
scrollDown
(
400
);
SystemClock
.
sleep
(
1000
);
Cmder
.
scrollDown
(
400
);
SystemClock
.
sleep
(
5000
);
// MotionRunner.get().scrollDown(800);
// SystemClock.sleep(1000);
Log
.
e
(
TAG
,
"exec --> 滑动 结束,搜索[无障碍]"
);
UiHierarchyFinder
finder
=
new
UiHierarchyFinder
();
List
<
UiNode
>
nodes
=
finder
.
dumpAndFindByName
(
"无障碍"
);
int
maxTry
=
2
;
int
currentTry
=
0
;
UiHierarchyFinder
finder
=
null
;
List
<
UiNode
>
nodes
=
null
;
while
(
currentTry
<
maxTry
&&
(
nodes
==
null
||
nodes
.
isEmpty
())){
finder
=
new
UiHierarchyFinder
();
nodes
=
finder
.
dumpAndFindByName
(
"无障碍"
);
Log
.
e
(
TAG
,
"第"
+
currentTry
+
"次,找到"
+
nodes
.
size
()+
"个节点"
);
currentTry
++;
}
Log
.
e
(
TAG
,
"找到"
+
nodes
.
size
()+
"个节点"
);
if
(
nodes
.
isEmpty
()){
DebugTools
.
log
(
"没有在[设置]-[辅助功能]中找到 [无障碍]选项 !"
);
...
...
@@ -65,35 +76,40 @@ public class EnableAccessibility implements Callable<Boolean> {
//点击无障碍
Rect
bounds
=
nodes
.
get
(
0
).
getBounds
();
DebugTools
.
log
(
"点击第0个节点的位置"
+
bounds
);
Log
.
e
(
TAG
,
"点击第0个节点的位置"
+
bounds
);
MotionRunner
.
get
().
tap
(
bounds
.
centerX
(),
bounds
.
centerY
());
SystemClock
.
sleep
(
1
000
);
Cmder
.
clickPX
(
bounds
.
centerX
(),
bounds
.
centerY
());
SystemClock
.
sleep
(
4
000
);
//打开了无障碍页面
//搜索家粉
DebugTools
.
log
(
"跳转到无障碍服务列表页面,开始搜索[家粉]"
);
Log
.
e
(
TAG
,
"跳转到无障碍服务列表页面,开始搜索[家粉]"
);
finder
=
new
UiHierarchyFinder
();
SystemClock
.
sleep
(
4000
);
nodes
=
finder
.
dumpAndFindByName
(
"家粉"
);
if
(
nodes
.
isEmpty
()){
Log
.
e
(
TAG
,
"没有在[无障碍]页面找到[家粉] 的辅助服务!"
);
throw
new
RuntimeException
(
"没有在[无障碍]页面找到[家粉] 的辅助服务!"
);
}
else
{
//找到了家粉 点击
Log
.
e
(
TAG
,
"找到了家粉 点击"
);
bounds
=
nodes
.
get
(
0
).
getBounds
();
MotionRunner
.
get
().
tap
(
bounds
.
centerX
(),
bounds
.
centerY
());
Cmder
.
clickPX
(
bounds
.
centerX
(),
bounds
.
centerY
());
SystemClock
.
sleep
(
2
000
);
SystemClock
.
sleep
(
4
000
);
//如果正常 进入家粉辅助服务详情页面
//判断是否跳转成功了,搜索辅助服务的描述
finder
=
new
UiHierarchyFinder
();
SystemClock
.
sleep
(
2000
);
nodes
=
finder
.
dumpAndFindByName
(
"微信点击辅助服务"
);
if
(
nodes
.
isEmpty
()){
Log
.
e
(
TAG
,
"没有正常打开 辅助服务详情 界面 !"
);
throw
new
RuntimeException
(
" 没有正常打开 辅助服务详情 界面 !"
);
}
else
{
...
...
@@ -108,29 +124,31 @@ public class EnableAccessibility implements Callable<Boolean> {
bounds
=
nodes
.
get
(
0
).
getBounds
();
//点击,显示弹窗
MotionRunner
.
get
().
tap
(
bounds
.
centerX
(),
bounds
.
centerY
());
Cmder
.
clickPX
(
bounds
.
centerX
(),
bounds
.
centerY
());
SystemClock
.
sleep
(
2000
);
//点击确定按钮
MotionRunner
.
get
().
tap
(
470
,
870
);
Cmder
.
clickPX
(
470
,
870
);
SystemClock
.
sleep
(
1500
);
//然后返回
MotionRunner
.
get
().
click
Back
();
Cmder
.
clickWx
Back
();
SystemClock
.
sleep
(
1
500
);
SystemClock
.
sleep
(
500
);
MotionRunner
.
get
().
click
Back
();
Cmder
.
clickWx
Back
();
SystemClock
.
sleep
(
1
5
00
);
SystemClock
.
sleep
(
1
0
00
);
MotionRunner
.
get
().
clickBack
();
Cmder
.
clickWxBack
();
Log
.
e
(
TAG
,
"点击最后一个返回"
);
SystemClock
.
sleep
(
1500
);
SystemClock
.
sleep
(
4500
);
Log
.
e
(
TAG
,
"最后一个返回等待结束"
);
return
true
;
}
...
...
app/src/main/java/com/xf/weixinclick/core/Cmder.java
View file @
5720b9bd
package
com
.
xf
.
weixinclick
.
core
;
import
android.graphics.Rect
;
import
android.support.v4.view.ViewCompat
;
import
android.util.Log
;
import
android.view.KeyEvent
;
import
android.view.View
;
import
android.view.accessibility.AccessibilityNodeInfo
;
import
com.xf.weixinclick.agent.AgentExecutor
;
import
com.xf.weixinclick.utils.Common
;
import
java.io.DataOutputStream
;
import
java.io.OutputStream
;
/**
* 创建日期:2018/4/17 on 13:58
* 描述:
...
...
@@ -7,4 +20,131 @@ package com.xf.weixinclick.core;
*/
public
class
Cmder
{
private
static
final
String
TAG
=
Cmder
.
class
.
getSimpleName
();
private
static
final
String
KEY_EVENT_CMD
=
"input keyevent "
;
private
static
final
String
TAP_EVENT_CMD
=
"input tap "
;
private
static
final
String
SWIPE_EVENT_CMD
=
"input swipe "
;
/**
* 返回
*/
public
static
void
clickBack
(){
sendKeyEvent
(
KeyEvent
.
KEYCODE_BACK
);
}
/**
* 点击微信的左上角返回
*/
public
static
void
clickWxBack
(){
execShellCmd
(
TAP_EVENT_CMD
+
Common
.
dip2px
(
20
)
+
" "
+
Common
.
dip2px
(
50
));
}
public
static
void
clickNode
(
AccessibilityNodeInfo
node
){
Rect
rect
=
new
Rect
();
node
.
getBoundsInScreen
(
rect
);
int
x
=
rect
.
left
+
Common
.
dip2px
(
10
);
int
y
=
rect
.
top
+
Common
.
dip2px
(
10
);
execShellCmd
(
TAP_EVENT_CMD
+
x
+
" "
+
y
);
}
/**
* Home键
*/
public
static
void
clickHome
(){
sendKeyEvent
(
KeyEvent
.
KEYCODE_HOME
);
}
/**
*
* @param x dp
* @param y dp
*/
public
static
void
click
(
int
x
,
int
y
){
execShellCmd
(
TAP_EVENT_CMD
+
" "
+
Common
.
dip2px
(
x
)
+
" "
+
Common
.
dip2px
(
y
)
);
}
public
static
void
clickPX
(
int
x
,
int
y
){
execShellCmd
(
TAP_EVENT_CMD
+
" "
+
x
+
" "
+
y
);
}
/**
*
* @param x dp
* @param y dp
* @param duration
*/
public
static
void
longPress
(
int
x
,
int
y
,
int
duration
){
StringBuilder
cmd
=
new
StringBuilder
(
SWIPE_EVENT_CMD
);
cmd
.
append
(
Common
.
dip2px
(
x
)).
append
(
' '
)
.
append
(
Common
.
dip2px
(
y
)).
append
(
' '
)
.
append
(
Common
.
dip2px
(
x
)).
append
(
' '
)
.
append
(
Common
.
dip2px
(
y
)).
append
(
' '
)
.
append
(
duration
);
execShellCmd
(
cmd
.
toString
());
}
public
static
void
scrollDown
(
int
distance
){
swipeTo
(
180
,
540
,
View
.
FOCUS_UP
,
distance
,
100
);
}
public
static
void
swipeTo
(
int
startX
,
int
startY
,
@ViewCompat
.
FocusRealDirection
int
direction
,
int
distance
,
int
duration
){
int
endX
=
startX
,
endY
=
startY
;
switch
(
direction
){
case
View
.
FOCUS_UP
:
endY
-=
distance
;
break
;
case
View
.
FOCUS_DOWN
:
endY
+=
distance
;
break
;
case
View
.
FOCUS_LEFT
:
endX
-=
distance
;
break
;
case
View
.
FOCUS_RIGHT
:
endY
+=
distance
;
break
;
}
swipe
(
startX
,
startY
,
endX
,
endY
,
duration
);
}
private
static
void
swipe
(
int
startX
,
int
startY
,
int
endX
,
int
endY
,
int
duration
){
StringBuilder
cmd
=
new
StringBuilder
(
SWIPE_EVENT_CMD
);
cmd
.
append
(
Common
.
dip2px
(
startX
)).
append
(
' '
)
.
append
(
Common
.
dip2px
(
startY
)).
append
(
' '
)
.
append
(
Common
.
dip2px
(
endX
)).
append
(
' '
)
.
append
(
Common
.
dip2px
(
endY
)).
append
(
' '
)
.
append
(
duration
);
execShellCmd
(
cmd
.
toString
());
}
private
static
void
sendKeyEvent
(
int
code
){
execShellCmd
(
KEY_EVENT_CMD
+
code
);
}
public
static
boolean
execShellCmd
(
String
cmd
)
{
Log
.
d
(
TAG
,
"execShellCmd "
+
cmd
);
try
{
// 申请获取root权限,这一步很重要,不然会没有作用
Process
process
=
Runtime
.
getRuntime
().
exec
(
"su"
);
// 获取输出流
OutputStream
outputStream
=
process
.
getOutputStream
();
DataOutputStream
dataOutputStream
=
new
DataOutputStream
(
outputStream
);
dataOutputStream
.
writeBytes
(
cmd
);
dataOutputStream
.
flush
();
dataOutputStream
.
close
();
outputStream
.
close
();
}
catch
(
Throwable
t
)
{
t
.
printStackTrace
();
//报错说明权限没有
Log
.
e
(
TAG
,
"没有root权限,点击失败"
);
return
false
;
}
return
true
;
}
}
app/src/main/java/com/xf/weixinclick/core/MsgSender.java
View file @
5720b9bd
package
com
.
xf
.
weixinclick
.
core
;
import
android.content.Context
;
import
android.util.Log
;
import
com.xf.weixinclick.NewService
;
import
com.xf.weixinclick.agent.AutoProcesser
;
import
com.xf.weixinclick.bean.msg.ReceiverMsg
;
...
...
@@ -22,6 +24,7 @@ public class MsgSender {
@Override
public
void
onSuccess
(
Boolean
aBoolean
)
{
if
(
aBoolean
){
Log
.
d
(
TAG
,
"开启无障碍成功"
);
EventBus
.
getDefault
().
post
(
msg
);
}
else
{
...
...
app/src/main/java/com/xf/weixinclick/core/TaskSession2.java
View file @
5720b9bd
package
com
.
xf
.
weixinclick
.
core
;
import
android.annotation.SuppressLint
;
import
android.graphics.Rect
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.os.HandlerThread
;
import
android.os.Message
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.view.accessibility.AccessibilityEvent
;
import
android.view.accessibility.AccessibilityNodeInfo
;
import
com.xf.weixinclick.NewService
;
import
com.xf.weixinclick.bean.msg.ReceiverMsg
;
import
com.xf.weixinclick.receiver.WeChatStatus
;
import
java.util.List
;
import
static
com
.
xf
.
weixinclick
.
NewService
.
findNodeByTexts
;
import
static
com
.
xf
.
weixinclick
.
receiver
.
WeChatStatus
.
needClick
;
/**
* 创建日期:2018/4/17 on 11:36
* 描述:
...
...
@@ -7,4 +27,324 @@ package com.xf.weixinclick.core;
*/
public
class
TaskSession2
{
private
final
int
MSG_TIME_OUT
=
-
100
;
private
final
int
TIME_OUT
=
40
*
1000
;
ReceiverMsg
mMsg
;
int
mStep
;
final
String
TAG
=
TaskSession2
.
class
.
getSimpleName
();
long
mLastShowToastTime
;
boolean
mBacking
;
private
Handler
handler
;
private
boolean
mSuccess
;
private
boolean
mTaskFinish
;
private
TaskCallback
mCallback
;
public
TaskSession2
(
ReceiverMsg
msg
,
TaskCallback
callback
){
this
.
mMsg
=
msg
;
this
.
mLastShowToastTime
=
0
;
HandlerThread
handlerThread
=
new
HandlerThread
(
"timeOutThread"
);
handlerThread
.
start
();
handler
=
new
Handler
(
handlerThread
.
getLooper
(),
new
Handler
.
Callback
()
{
@Override
public
boolean
handleMessage
(
Message
msg
)
{
if
(
msg
.
what
==
MSG_TIME_OUT
){
Log
(
TAG
,
"超时返回"
);
turnBack
();
taskFinish
();
}
return
true
;
}
});
mSuccess
=
false
;
mBacking
=
false
;
this
.
mCallback
=
callback
;
}
public
void
handle
(
final
AccessibilityNodeInfo
rootInActiveWindow
,
AccessibilityEvent
event
){
int
eventType
=
event
.
getEventType
();
String
className
=
event
.
getClassName
().
toString
();
Log
.
d
(
TAG
,
"get event = "
+
eventType
+
" class "
+
className
+
" step "
+
mStep
);
long
currentTime
=
System
.
currentTimeMillis
();
if
(
currentTime
-
mLastShowToastTime
>
10
*
1000
){
boolean
taskMsgExist
=
mMsg
==
null
;
String
taskMsgPrompt
=
taskMsgExist
?
"消息是空"
:
"消息存在"
;
Log
.
d
(
TAG
,
"辅助service还活着 step = "
+
mStep
+
" "
+
taskMsgPrompt
);
mLastShowToastTime
=
currentTime
;
}
if
(!
className
.
contains
(
WXIdsConfig2
.
MM_PNAME
))
{
return
;
}
if
(
mBacking
){
Log
(
TAG
,
"执行返回中"
);
//都是点击左上角
Cmder
.
clickWxBack
();
if
(
className
.
equals
(
WXIdsConfig2
.
WeChatUi
)){
//到了首页就结束
mBacking
=
false
;
Log
(
TAG
,
"执行返回完成"
);
handler
.
removeMessages
(
MSG_TIME_OUT
);
taskFinish
();
}
return
;
}
if
(
mMsg
==
null
){
Log
(
TAG
,
"NewService but taskMsg is null"
);
return
;
}
if
(
mStep
==
0
&&
findByIdAndText
(
rootInActiveWindow
,
WXIdsConfig2
.
TV_HOME_WX
,
"微信"
)
==
null
){
Log
(
TAG
,
"当前页不是首页"
);
turnBack
();
resetAll
();
return
;
}
if
(
mStep
==
0
&&
findByIdAndText
(
rootInActiveWindow
,
WXIdsConfig2
.
TV_HOME_WX
,
"微信"
)
!=
null
){
//点击文件传输助手的位置
//最好还是找到文字然后点击位置
//没办法 首页打印出来的是通讯录的布局,所以坐标是错误的
handler
.
sendEmptyMessageDelayed
(
MSG_TIME_OUT
,
TIME_OUT
);
mStep
++;
Log
.
d
(
TAG
,
"准备点击首页的文件传输助手"
);
handler
.
postDelayed
(
new
Runnable
()
{
@Override
public
void
run
()
{
if
(
rootInActiveWindow
==
null
){
return
;
}
AccessibilityNodeInfo
fileNode
=
findByIdAndText
(
rootInActiveWindow
,
WXIdsConfig2
.
HOME_MSG_TITLE
,
"文件传输助手"
);
if
(
fileNode
==
null
){
Log
(
TAG
,
"没有发现文件传输助手,不点击"
);
return
;
}
Log
(
TAG
,
"开始点击首页的文件传输助手"
);
Cmder
.
clickNode
(
fileNode
);
mStep
++;
}
},
mMsg
.
getTime_config
().
getAfter_open_weixin_index_delay
());
//魅族5s 有时候进入详情页不触发消息,所有直接点击
handler
.
postDelayed
(
new
Runnable
()
{
@Override
public
void
run
()
{
mStep
++;
Log
(
TAG
,
"文件传输详情页面_填充_准备"
);
if
(
fill
(
rootInActiveWindow
,
mMsg
.
getQr_addr
())){
Log
(
TAG
,
"文件传输详情页面_填充_完成"
);
send
(
rootInActiveWindow
);
clickMsg
(
rootInActiveWindow
,
mMsg
.
getQr_addr
());
mStep
++;
}
else
{
Log
(
TAG
,
"文件传输详情页面_填充_失败"
);
}
}
},
mMsg
.
getTime_config
().
getAfter_open_weixin_index_delay
()
+
5000
);
}
if
(
mStep
==
4
&&
className
.
equals
(
WXIdsConfig2
.
WeChatWebView
)){
mStep
++;
handler
.
postDelayed
(
new
Runnable
()
{
@Override
public
void
run
()
{
Cmder
.
longPress
(
150
,
300
,
4000
);
mStep
++;
}
},
mMsg
.
getTime_config
().
getAfter_click_message_delay
());
}
if
(
mStep
==
6
&&
className
.
equals
(
WXIdsConfig2
.
WeChatAlert
)){
Log
(
TAG
,
"开始点击确认二维码"
);
mStep
++;
handler
.
postDelayed
(
new
Runnable
()
{
@Override
public
void
run
()
{
pressRecognitionImg
(
rootInActiveWindow
);
mStep
++;
}
},
mMsg
.
getTime_config
().
getLong_press_qrcode_delay
());
}
if
(
mStep
==
8
&&
className
.
equals
(
WXIdsConfig2
.
WeChatWebView
)){
Log
(
TAG
,
"开始点击确认登录"
);
handler
.
postDelayed
(
new
Runnable
()
{
@Override
public
void
run
()
{
Cmder
.
click
(
40
,
315
);
Cmder
.
click
(
40
,
375
);
mSuccess
=
true
;
turnBack
();
}
},
mMsg
.
getTime_config
().
getAfter_click_decode_button_delay
());
mStep
++;
}
//todo找下确认登录的标记
}
/**
* 点击识别图中二维码
*/
void
pressRecognitionImg
(
AccessibilityNodeInfo
rootInActiveWindo
)
{
List
<
AccessibilityNodeInfo
>
allData
=
rootInActiveWindo
.
findAccessibilityNodeInfosByText
(
"识别图中二维码"
);
if
(
allData
.
isEmpty
())
{
turnBack
();
}
else
{
for
(
AccessibilityNodeInfo
temp
:
allData
)
{
Cmder
.
clickNode
(
temp
);
}
}
}
@SuppressLint
(
"NewApi"
)
private
void
clickMsg
(
AccessibilityNodeInfo
rootNode
,
String
msg
)
{
if
(
rootNode
==
null
)
{
return
;
}
List
<
AccessibilityNodeInfo
>
ac
=
rootNode
.
findAccessibilityNodeInfosByViewId
(
WXIdsConfig2
.
ITEM_MSG_CARD
);
List
<
AccessibilityNodeInfo
>
ac2
=
rootNode
.
findAccessibilityNodeInfosByText
(
msg
);
AccessibilityNodeInfo
n
=
null
;
if
(
ac
.
size
()
>
0
)
{
Log
.
d
(
TAG
,
"通过id找到了消息url"
);
n
=
ac
.
get
(
ac
.
size
()
-
1
);
}
if
(
ac2
.
size
()
>
0
)
{
Log
.
d
(
TAG
,
"通过文字找到了消息url"
);
n
=
ac2
.
get
(
ac2
.
size
()
-
1
);
}
if
(
n
!=
null
)
{
Cmder
.
clickNode
(
n
);
}
else
{
Log
.
d
(
TAG
,
"找不到消息 消息url"
+
msg
);
Cmder
.
click
(
100
,
540
);
}
}
@SuppressLint
(
"NewApi"
)
private
void
send
(
AccessibilityNodeInfo
rootInActiveWindow
)
{
if
(
rootInActiveWindow
!=
null
)
{
List
<
AccessibilityNodeInfo
>
list
=
rootInActiveWindow
.
findAccessibilityNodeInfosByText
(
"发送"
);
if
(
list
!=
null
&&
list
.
size
()
>
0
)
{
for
(
AccessibilityNodeInfo
n
:
list
)
{
n
.
performAction
(
AccessibilityNodeInfo
.
ACTION_CLICK
);
}
}
else
{
List
<
AccessibilityNodeInfo
>
liste
=
rootInActiveWindow
.
findAccessibilityNodeInfosByText
(
"Send"
);
if
(
liste
!=
null
&&
liste
.
size
()
>
0
)
{
for
(
AccessibilityNodeInfo
n
:
liste
)
{
n
.
performAction
(
AccessibilityNodeInfo
.
ACTION_CLICK
);
}
}
}
}
}
private
boolean
fill
(
AccessibilityNodeInfo
rootInActiveWindow
,
String
msg
){
List
<
AccessibilityNodeInfo
>
ets
=
rootInActiveWindow
.
findAccessibilityNodeInfosByViewId
(
WXIdsConfig
.
ET_INPUT_MSG
);
if
(
ets
!=
null
&&
!
ets
.
isEmpty
()){
for
(
AccessibilityNodeInfo
et
:
ets
)
{
if
(
"android.widget.EditText"
.
equals
(
et
.
getClassName
())){
Bundle
arguments
=
new
Bundle
();
arguments
.
putCharSequence
(
AccessibilityNodeInfo
.
ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE
,
msg
);
et
.
performAction
(
AccessibilityNodeInfo
.
ACTION_SET_TEXT
,
arguments
);
return
true
;
}
}
}
return
false
;
}
private
void
taskFinish
(){
if
(!
mTaskFinish
){
mTaskFinish
=
true
;
if
(
mSuccess
){
mCallback
.
onSuccess
();
}
else
{
mCallback
.
onError
(
"fail"
);
}
}
}
private
void
turnBack
(){
Log
.
d
(
TAG
,
"执行返回turnBack"
);
mBacking
=
true
;
//需要返回
Cmder
.
clickBack
();
resetAll
();
}
private
void
resetAll
(){
mMsg
=
null
;
mStep
=
0
;
}
private
void
Log
(
String
tag
,
String
msg
){
Log
.
d
(
tag
,
msg
);
}
private
AccessibilityNodeInfo
findByIdAndText
(
AccessibilityNodeInfo
rootInActiveWindow
,
String
id
,
String
text
){
List
<
AccessibilityNodeInfo
>
nodeInfos
=
rootInActiveWindow
.
findAccessibilityNodeInfosByViewId
(
id
);
if
(
isEmptyNodes
(
nodeInfos
)){
return
null
;
}
for
(
AccessibilityNodeInfo
nodeInfo
:
nodeInfos
)
{
if
(
TextUtils
.
equals
(
text
,
nodeInfo
.
getText
())){
return
nodeInfo
;
}
}
return
null
;
}
private
boolean
isEmptyNodes
(
List
<
AccessibilityNodeInfo
>
nodeInfos
){
return
nodeInfos
==
null
||
nodeInfos
.
isEmpty
();
}
interface
TaskCallback
{
void
onSuccess
();
void
onError
(
String
msg
);
}
}
app/src/main/java/com/xf/weixinclick/core/WXIdsConfig.java
View file @
5720b9bd
...
...
@@ -13,11 +13,11 @@ final class WXIdsConfig {
public
static
final
String
BTN_CHANGE_INPUT
=
ID_PREFIX
+
"aaa"
;
//却换输入文字,匹配 切换到键盘
public
static
final
String
ET_INPUT_MSG
=
ID_PREFIX
+
"aa
c
"
;
//聊天页面输入框
public
static
final
String
ET_INPUT_MSG
=
ID_PREFIX
+
"aa
a
"
;
//聊天页面输入框
public
static
final
String
BTN_SEND_MSG
=
ID_PREFIX
+
"aai"
;
//聊天页面发送按钮
public
static
final
String
ITEM_MSG_CARD
=
ID_PREFIX
+
"j
j
"
;
//聊天页面消息卡片
public
static
final
String
ITEM_MSG_CARD
=
ID_PREFIX
+
"j
z
"
;
//聊天页面消息卡片
public
static
final
String
BTN_SCAN_QR
=
ID_PREFIX
+
"ga"
;
//识别二维码
...
...
app/src/main/java/com/xf/weixinclick/core/WXIdsConfig2.java
View file @
5720b9bd
package
com
.
xf
.
weixinclick
.
core
;
final
class
WXIdsConfig
{
private
static
final
String
ID_PREFIX
=
"com.tencent.mm:id/"
;
final
class
WXIdsConfig2
{
public
static
final
String
WeChatUi
=
"com.tencent.mm.ui.LauncherUI"
;
public
static
final
String
WeChatWebView
=
"com.tencent.mm.plugin.webview.ui.tools.WebViewUI"
;
public
static
final
String
WeChatAlert
=
"com.tencent.mm.ui.base.m"
;
public
static
String
MM_PNAME
=
"com.tencent.mm"
;
public
static
final
String
ID_PREFIX
=
"com.tencent.mm:id/"
;
//todo 这里换成数组,因为id会各种变
//不同版本id可能不同,根据后台配置更新
public
static
final
String
TV_HOME_WX
=
ID_PREFIX
+
"c
a5
"
;
//底部导航文件,根据 微信 匹配
public
static
final
String
TV_HOME_WX
=
ID_PREFIX
+
"c
9f
"
;
//底部导航文件,根据 微信 匹配
public
static
final
String
HOME_MSG_TITLE
=
ID_PREFIX
+
"ap
x
"
;
//文件传输助手,有多个,再根据文本匹配
public
static
final
String
HOME_MSG_TITLE
=
ID_PREFIX
+
"ap
v
"
;
//文件传输助手,有多个,再根据文本匹配
public
static
final
String
BTN_CHANGE_INPUT
=
ID_PREFIX
+
"aaa"
;
//却换输入文字,匹配 切换到键盘
...
...
app/src/main/java/com/xf/weixinclick/core/Worker2.java
View file @
5720b9bd
package
com
.
xf
.
weixinclick
.
core
;
import
android.content.ComponentName
;
import
android.content.Intent
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.view.accessibility.AccessibilityEvent
;
import
android.view.accessibility.AccessibilityNodeInfo
;
import
com.alibaba.sdk.android.push.noonesdk.PushServiceFactory
;
import
com.xf.weixinclick.bean.msg.ReceiverMsg
;
import
com.xf.weixinclick.http.HttpClientApi
;
import
com.xf.weixinclick.http.HttpSubscriber
;
import
com.xf.weixinclick.myApplication
;
import
org.greenrobot.eventbus.EventBus
;
import
org.greenrobot.eventbus.Subscribe
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
java.util.concurrent.locks.Condition
;
import
java.util.concurrent.locks.ReentrantLock
;
/**
* 创建日期:2018/4/17 on 10:11
* 描述:
...
...
@@ -7,4 +27,158 @@ package com.xf.weixinclick.core;
*/
public
class
Worker2
{
private
String
TAG
=
Worker2
.
class
.
getSimpleName
();
private
LinkedBlockingQueue
<
ReceiverMsg
>
mTasks
=
new
LinkedBlockingQueue
<>();
private
TaskSession2
mCurrentTaskSession
;
private
ReentrantLock
mReentrantLock
;
private
Condition
mCondition
;
private
static
Worker2
sWorker
;
private
static
final
int
ACTION_SUCCESS
=
1
;
private
static
final
int
ACTION_FAIL
=
0
;
public
static
Worker2
getInstance
(){
if
(
sWorker
==
null
){
synchronized
(
Worker2
.
class
){
if
(
sWorker
==
null
){
sWorker
=
new
Worker2
();
}
}
}
return
sWorker
;
}
private
Worker2
(){
mReentrantLock
=
new
ReentrantLock
();
mCondition
=
mReentrantLock
.
newCondition
();
Log
.
d
(
TAG
,
" 构造函数"
);
EventBus
.
getDefault
().
register
(
this
);
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
boolean
run
=
true
;
while
(
run
){
//从队列里拿任务
//没有就等待
//有的话就开始执行任务 直到成功或者失败
try
{
//take会一直等待到有新的任务
Log
.
d
(
TAG
,
" 准备拿任务"
);
final
ReceiverMsg
msg
=
mTasks
.
take
();
Log
.
d
(
TAG
,
" 拿到任务了 "
+
msg
.
getUnique_id
()
+
" 剩余 "
+
mTasks
.
size
());
mCurrentTaskSession
=
new
TaskSession2
(
msg
,
new
TaskSession2
.
TaskCallback
()
{
@Override
public
void
onSuccess
()
{
Log
.
d
(
TAG
,
" 任务成功"
);
taskCanStart
();
upResult
(
ACTION_SUCCESS
,
msg
.
getOrigin_id
());
}
@Override
public
void
onError
(
String
errMsg
)
{
Log
.
d
(
TAG
,
" 任务失败"
);
taskCanStart
();
upResult
(
ACTION_FAIL
,
msg
.
getOrigin_id
());
}
});
startWechat
();
//开始等待任务结束
taskWait
();
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
run
=
false
;
}
}
}
}).
start
();
}
private
void
taskWait
(){
mReentrantLock
.
lock
();
try
{
mCondition
.
await
();
}
catch
(
Exception
e
){
}
finally
{
mReentrantLock
.
unlock
();
}
}
private
void
taskCanStart
(){
mReentrantLock
.
lock
();
try
{
mCondition
.
signal
();
}
catch
(
Exception
e
){
}
finally
{
mReentrantLock
.
unlock
();
}
}
/**
* 上传结果
*
* @param code
*/
private
void
upResult
(
final
int
code
,
final
String
id
)
{
if
(
TextUtils
.
isEmpty
(
id
)){
return
;
}
Log
.
d
(
TAG
,
"开始上报结果 "
+
code
+
" "
+
id
);
HttpClientApi
.
devicesScan
(
PushServiceFactory
.
getCloudPushService
().
getDeviceId
(),
code
,
id
,
new
HttpSubscriber
<
String
>()
{
@Override
public
void
onCompleted
()
{
}
@Override
public
void
onNext
(
String
responseBase
)
{
Log
.
d
(
TAG
,
"上报结果 "
+
responseBase
);
}
});
}
@Subscribe
public
void
receiverMsg
(
final
ReceiverMsg
msg
)
{
Log
.
d
(
TAG
,
"receiverMsg"
+
" mTaskSize "
+
mTasks
.
size
());
mTasks
.
add
(
msg
);
}
public
void
onIntercept
(){
if
(
EventBus
.
getDefault
().
isRegistered
(
this
)){
EventBus
.
getDefault
().
unregister
(
this
);
}
Log
.
d
(
TAG
,
" onIntercept"
);
}
public
void
onAccessibilityEvent
(
final
AccessibilityNodeInfo
rootInActiveWindow
,
AccessibilityEvent
event
){
if
(
mCurrentTaskSession
!=
null
){
mCurrentTaskSession
.
handle
(
rootInActiveWindow
,
event
);
}
}
private
void
startWechat
(){
Intent
intent
=
new
Intent
();
//// 报名该有activity
ComponentName
cmp
=
new
ComponentName
(
"com.tencent.mm"
,
"com.tencent.mm.ui.LauncherUI"
);
intent
.
setAction
(
Intent
.
ACTION_MAIN
);
intent
.
addCategory
(
Intent
.
CATEGORY_LAUNCHER
);
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
|
Intent
.
FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
);
intent
.
setComponent
(
cmp
);
myApplication
.
getInstence
().
startActivity
(
intent
);
}
}
app/src/main/java/com/xf/weixinclick/receiver/MyMessageReceiver.java
View file @
5720b9bd
...
...
@@ -56,13 +56,13 @@ public class MyMessageReceiver extends MessageReceiver {
Log
.
e
(
"MyMessageReceiver"
,
"onMessage, messageId: "
+
cPushMessage
.
getMessageId
()
+
", title: "
+
cPushMessage
.
getTitle
()
+
", content:"
+
cPushMessage
.
getContent
());
Intent
intent
=
new
Intent
();
ComponentName
cmp
=
new
ComponentName
(
"com.tencent.mm"
,
"com.tencent.mm.ui.LauncherUI"
);
// 报名该有activity
intent
.
setAction
(
Intent
.
ACTION_MAIN
);
intent
.
addCategory
(
Intent
.
CATEGORY_LAUNCHER
);
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
|
Intent
.
FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
);
intent
.
setComponent
(
cmp
);
myApplication
.
getInstence
().
startActivity
(
intent
);
//
Intent intent = new Intent();
//
ComponentName cmp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI");// 报名该有activity
//
intent.setAction(Intent.ACTION_MAIN);
//
intent.addCategory(Intent.CATEGORY_LAUNCHER);
//
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
//
intent.setComponent(cmp);
//
myApplication.getInstence().startActivity(intent);
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
...
...
app/src/main/java/com/xf/weixinclick/utils/Accessibilitys.java
View file @
5720b9bd
...
...
@@ -15,7 +15,9 @@ public class Accessibilitys {
public
static
boolean
isSettingsOn
(
Context
context
)
{
if
(
context
==
null
)
return
false
;
if
(
context
==
null
){
return
false
;
}
try
{
int
accessibilityEnabled
=
Settings
.
Secure
.
getInt
(
...
...
app/src/main/java/com/xf/weixinclick/utils/Common.java
View file @
5720b9bd
package
com
.
xf
.
weixinclick
.
utils
;
import
com.xf.weixinclick.myApplication
;
/**
* 创建日期:2018/4/17 on 14:03
* 描述:
...
...
@@ -7,4 +9,10 @@ package com.xf.weixinclick.utils;
*/
public
class
Common
{
public
static
int
dip2px
(
float
dpValue
)
{
float
scale
=
myApplication
.
getInstence
().
getResources
().
getDisplayMetrics
().
density
;
return
(
int
)
(
dpValue
*
scale
+
0.5
F
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment