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
caf4e2f3
authored
Apr 13, 2018
by
zhengli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new services
parent
4ffda1aa
Show whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
1312 additions
and
78 deletions
+1312
-78
agent/src/androidTest/java/com/xf/agent/ExampleInstrumentedTest.java
+0
-27
agent/src/main/java/com/xf/agent/AgentHandler.java
+13
-0
agentcommon/src/main/java/com/xf/agent/common/Types.java
+15
-1
agentlib/src/main/java/com/xf/agent/wrap/AgentManager.java
+11
-1
agentlib/src/main/java/com/xf/agent/wrap/LocalServerManager.java
+21
-1
app/build.gradle
+1
-1
app/src/main/AndroidManifest.xml
+9
-4
app/src/main/java/com/xf/weixinclick/DebugActivity.java
+23
-2
app/src/main/java/com/xf/weixinclick/HeartBeatAction.java
+9
-1
app/src/main/java/com/xf/weixinclick/MainActivity.java
+4
-1
app/src/main/java/com/xf/weixinclick/WXCService.java
+35
-0
app/src/main/java/com/xf/weixinclick/agent/AgentExecutor.java
+23
-2
app/src/main/java/com/xf/weixinclick/agent/AutoProcesser.java
+43
-1
app/src/main/java/com/xf/weixinclick/agent/DebugTools.java
+93
-23
app/src/main/java/com/xf/weixinclick/agent/MotionRunner.java
+5
-2
app/src/main/java/com/xf/weixinclick/agent/UiHierarchyFinder.java
+22
-0
app/src/main/java/com/xf/weixinclick/agent/auto/EnableAccessibility.java
+5
-5
app/src/main/java/com/xf/weixinclick/agent/auto/EnableUsageStats.java
+42
-0
app/src/main/java/com/xf/weixinclick/core/MsgSender.java
+43
-0
app/src/main/java/com/xf/weixinclick/core/TaskSession.java
+675
-0
app/src/main/java/com/xf/weixinclick/core/WXIdsConfig.java
+24
-0
app/src/main/java/com/xf/weixinclick/core/Worker.java
+167
-0
app/src/main/java/com/xf/weixinclick/receiver/MyMessageReceiver.java
+8
-1
app/src/main/java/com/xf/weixinclick/utils/Accessibilitys.java
+9
-0
app/src/main/res/layout/activity_debug.xml
+10
-3
app/src/main/res/xml/accessibility.xml
+2
-2
No files found.
agent/src/androidTest/java/com/xf/agent/ExampleInstrumentedTest.java
deleted
100644 → 0
View file @
4ffda1aa
package
com
.
xf
.
agent
;
import
android.content.Context
;
import
android.support.test.InstrumentationRegistry
;
import
android.support.test.runner.AndroidJUnit4
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
static
org
.
junit
.
Assert
.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith
(
AndroidJUnit4
.
class
)
public
class
ExampleInstrumentedTest
{
@Test
public
void
useAppContext
()
{
// Context of the app under test.
Context
appContext
=
InstrumentationRegistry
.
getTargetContext
();
assertEquals
(
"com.xf.agent.test"
,
appContext
.
getPackageName
());
}
}
agent/src/main/java/com/xf/agent/AgentHandler.java
View file @
caf4e2f3
...
...
@@ -3,7 +3,10 @@ package com.xf.agent;
import
android.app.ActivityThread
;
import
android.content.ComponentName
;
import
android.content.Context
;
import
android.os.IBinder
;
import
android.os.Parcelable
;
import
android.os.ServiceManager
;
import
android.os.SystemClock
;
import
android.text.TextUtils
;
import
android.view.accessibility.AccessibilityManager
;
import
com.xf.agent.common.CallRequest
;
...
...
@@ -117,6 +120,16 @@ class AgentHandler implements OpsDataTransfer.OnRecvCallback{
destory
();
}
else
if
(
callRequest
.
type
==
Types
.
RESTART
){
}
else
if
(
callRequest
.
type
==
Types
.
RESTART_NETWORK
){
//
IBinder
service
=
ServiceManager
.
getService
(
Context
.
TELEPHONY_SERVICE
);
MethodUtils
.
invokeExactMethod
(
service
,
"setDataEnabled"
,
false
);
SystemClock
.
sleep
(
2000
);
MethodUtils
.
invokeExactMethod
(
service
,
"setDataEnabled"
,
true
);
FLog
.
log
(
"---restart network success --- "
);
}
else
{
System
.
out
.
println
(
"unknown type !"
);
}
...
...
agentcommon/src/main/java/com/xf/agent/common/Types.java
View file @
caf4e2f3
...
...
@@ -2,11 +2,25 @@ package com.xf.agent.common;
public
final
class
Types
{
/**
* 执行命令
*/
public
static
final
int
CMD
=
1
;
/**
* 关闭服务
*/
public
static
final
int
CLOSE
=
2
;
/**
* 重启服务
*/
public
static
final
int
RESTART
=
3
;
/**
* 重启4G网络
*/
public
static
final
int
RESTART_NETWORK
=
4
;
}
agentlib/src/main/java/com/xf/agent/wrap/AgentManager.java
View file @
caf4e2f3
...
...
@@ -3,9 +3,10 @@ package com.xf.agent.wrap;
import
android.content.Context
;
import
com.xf.agent.common.CallResult
;
import
com.xf.agent.common.CmdResult
;
import
com.xf.agent.common.NormalCmd
;
import
com.xf.agent.common.ParcelableUtil
;
import
com.xf.agent.common.TypeCmd
;
import
com.xf.agent.common.Types
;
public
class
AgentManager
{
...
...
@@ -40,6 +41,15 @@ public class AgentManager {
return
ParcelableUtil
.
unmarshall
(
result
.
data
,
CmdResult
.
CREATOR
);
}
public
boolean
restart4G
()
throws
Throwable
{
checkConnect
();
NormalCmd
normalCmd
=
new
NormalCmd
(
Types
.
RESTART_NETWORK
);
CallResult
result
=
mLocalServerManager
.
execNew
(
normalCmd
);
if
(
result
!=
null
&&
result
.
throwable
!=
null
){
throw
result
.
throwable
;
}
return
true
;
}
public
void
destory
()
{
...
...
agentlib/src/main/java/com/xf/agent/wrap/LocalServerManager.java
View file @
caf4e2f3
...
...
@@ -191,9 +191,19 @@ class LocalServerManager {
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
try
{
if
(
exec
!=
null
)
{
exec
.
destroy
();
}
}
catch
(
Exception
e2
)
{
e2
.
printStackTrace
();
}
if
(
checker
!=
null
)
{
checker
.
interrupt
();
}
throw
e
;
}
finally
{
try
{
...
...
@@ -217,7 +227,17 @@ class LocalServerManager {
private
void
startServer
()
throws
Exception
{
useRootStartServer
();
//重试10次
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
try
{
if
(
useRootStartServer
()){
return
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
Log
.
e
(
TAG
,
"startServer --> end ---"
);
}
...
...
app/build.gradle
View file @
caf4e2f3
...
...
@@ -86,7 +86,7 @@ dependencies {
implementation
'io.reactivex:rxandroid:1.2.1'
implementation
'com.google.code.gson:gson:2.8.2'
implementation
'com.github.bumptech.glide:glide:3.5.2'
implementation
'org.greenrobot:eventbus:3.
0.0
'
implementation
'org.greenrobot:eventbus:3.
1.1
'
implementation
'com.android.support.constraint:constraint-layout:1.0.2'
implementation
"com.android.support:appcompat-v7:$versions.supportLibVersion"
...
...
app/src/main/AndroidManifest.xml
View file @
caf4e2f3
...
...
@@ -2,12 +2,14 @@
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
package=
"com.xf.weixinclick"
>
<uses-permission
android:name=
"android.permission.WRITE_SETTINGS"
/>
<uses-permission
android:name=
"android.permission.WRITE_SETTINGS"
tools:ignore=
"ProtectedPermissions"
/>
<uses-permission
android:name=
"android.permission.PROCESS_OUTGOING_CALLS"
/>
<uses-permission
android:name=
"android.permission.DISABLE_KEYGUARD"
/>
<uses-permission
android:name=
"android.permission.MODIFY_AUDIO_SETTINGS"
/>
<uses-permission
android:name=
"android.permission.WRITE_EXTERNAL_STORAGE"
/>
<uses-permission
android:name=
"android.permission.BIND_ACCESSIBILITY_SERVICE"
/>
<uses-permission
android:name=
"android.permission.BIND_ACCESSIBILITY_SERVICE"
tools:ignore=
"ProtectedPermissions"
/>
<uses-permission
android:name=
"android.permission.INTERNET"
/>
<uses-permission
android:name=
"android.permission.ACCESS_NETWORK_STATE"
/>
<uses-permission
android:name=
"android.permission.ACCESS_WIFI_STATE"
/>
...
...
@@ -19,7 +21,10 @@
<uses-permission
android:name=
"android.permission.RECEIVE_BOOT_COMPLETED"
/>
<uses-permission
android:name=
"android.permission.VIBRATE"
/>
<uses-permission
android:name=
"android.permission.READ_EXTERNAL_STORAGE"
/>
<uses-permission
android:name=
"android.permission.MOUNT_UNMOUNT_FILESYSTEMS"
/>
<uses-permission
android:name=
"android.permission.MOUNT_UNMOUNT_FILESYSTEMS"
tools:ignore=
"ProtectedPermissions"
/>
<uses-permission
android:name=
"android.permission.PACKAGE_USAGE_STATS"
tools:ignore=
"ProtectedPermissions"
/>
<uses-permission
android:name=
"android.permission.INJECT_EVENTS"
...
...
@@ -64,7 +69,7 @@
<service
android:name=
".
New
Service"
android:name=
".
WXC
Service"
android:enabled=
"true"
android:exported=
"true"
android:label=
"@string/app_name"
...
...
app/src/main/java/com/xf/weixinclick/DebugActivity.java
View file @
caf4e2f3
...
...
@@ -2,9 +2,11 @@ package com.xf.weixinclick;
import
android.os.Bundle
;
import
android.support.annotation.Nullable
;
import
android.util.Log
;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
butterknife.BindView
;
import
butterknife.OnClick
;
import
com.xf.weixinclick.agent.AgentExecutor
;
...
...
@@ -18,6 +20,8 @@ import rx.schedulers.Schedulers;
public
class
DebugActivity
extends
BaseActivity
{
private
static
final
String
TAG
=
"DebugActivity"
;
@BindView
(
R
.
id
.
tv_logcat_url
)
TextView
tvLogcatUrl
;
@BindView
(
R
.
id
.
btn_logcat
)
...
...
@@ -55,7 +59,24 @@ public class DebugActivity extends BaseActivity {
@OnClick
(
R
.
id
.
btn_enable_accessibility
)
void
onClickAutoEnableAccessibility
(
View
view
){
AutoProcesser
.
enableAccessibility
(
this
);
AutoProcesser
.
enableAccessibility
(
this
,
null
);
}
@OnClick
(
R
.
id
.
btn_restart_4g
)
void
onClickRestart4G
(
View
view
){
AgentExecutor
.
restartNetwork
().
subscribe
(
new
SingleSubscriber
<
Boolean
>()
{
@Override
public
void
onSuccess
(
Boolean
aBoolean
)
{
Toast
.
makeText
(
getApplicationContext
(),
"重启网络 "
+
aBoolean
,
Toast
.
LENGTH_SHORT
).
show
();
}
@Override
public
void
onError
(
Throwable
error
)
{
Log
.
e
(
TAG
,
"onError --> "
,
error
);
}
});
}
...
...
@@ -85,7 +106,7 @@ public class DebugActivity extends BaseActivity {
}
else
{
btnSwitchLogcat
.
setText
(
"开启logcat"
);
tvLogcatUrl
.
setText
(
null
);
tvLogcatUrl
.
setText
(
"off"
);
}
}
...
...
app/src/main/java/com/xf/weixinclick/HeartBeatAction.java
View file @
caf4e2f3
...
...
@@ -63,7 +63,7 @@ public class HeartBeatAction {
if
(
TextUtils
.
isEmpty
(
name
)){
return
;
}
onWake
();
HttpClientApi
.
heartBat
(
name
,
PushServiceFactory
.
getCloudPushService
().
getDeviceId
(),
getBattery
());
...
...
@@ -77,4 +77,12 @@ public class HeartBeatAction {
int
capacity
=
batteryManager
.
getIntProperty
(
BatteryManager
.
BATTERY_PROPERTY_CAPACITY
);
return
capacity
;
}
private
void
onWake
(){
}
}
app/src/main/java/com/xf/weixinclick/MainActivity.java
View file @
caf4e2f3
...
...
@@ -36,11 +36,13 @@ import com.xf.agent.common.Actions;
import
com.xf.agent.common.CmdResult
;
import
com.xf.agent.wrap.AgentManager
;
import
com.xf.weixinclick.agent.AgentExecutor
;
import
com.xf.weixinclick.agent.AutoProcesser
;
import
com.xf.weixinclick.bean.DelayBean
;
import
com.xf.weixinclick.bean.EnableResult
;
import
com.xf.weixinclick.bean.LoginBean
;
import
com.xf.weixinclick.bean.ResponseBase
;
import
com.xf.weixinclick.bean.msg.ReceiverMsg
;
import
com.xf.weixinclick.core.MsgSender
;
import
com.xf.weixinclick.http.HttpClientApi
;
import
com.xf.weixinclick.http.HttpSubscriber
;
import
com.xf.weixinclick.receiver.WeChatStatus
;
...
...
@@ -185,7 +187,8 @@ public class MainActivity extends BaseActivity {
// msg.setQr_addr("https://weapp-dev.wangjia.com/qr.jpg?dd=1");
msg
.
setUnique_id
(
"1111111111111"
);
msg
.
setTime_config
(
new
Gson
().
fromJson
(
"{\"qrcode_timeout\":60,\"after_open_weixin_index_delay\":2000,\"after_open_weixin_file_helper_delay\":6000,\"after_paste_message_delay\":2000,\"after_send_message_delay\":2000,\"after_click_message_delay\":5000,\"long_press_qrcode_delay\":4000,\"after_click_decode_button_delay\":5000,\"after_click_confirm_button_delay\":3000}"
,
DelayBean
.
class
));
EventBus
.
getDefault
().
post
(
msg
);
//EventBus.getDefault().post(msg);
MsgSender
.
checkAndSend
(
getApplicationContext
(),
msg
);
// startWorkService(MainActivity.this,msg);
}
...
...
app/src/main/java/com/xf/weixinclick/WXCService.java
0 → 100644
View file @
caf4e2f3
package
com
.
xf
.
weixinclick
;
import
android.accessibilityservice.AccessibilityService
;
import
android.view.accessibility.AccessibilityEvent
;
import
com.xf.weixinclick.core.Worker
;
public
class
WXCService
extends
AccessibilityService
{
private
Worker
worker
=
null
;
@Override
public
void
onCreate
()
{
super
.
onCreate
();
worker
=
Worker
.
getInstance
();
}
@Override
public
void
onAccessibilityEvent
(
AccessibilityEvent
event
)
{
if
(
worker
==
null
){
worker
=
Worker
.
getInstance
();
}
worker
.
handleEvent
(
this
,
event
);
}
@Override
public
void
onInterrupt
()
{
if
(
worker
==
null
){
worker
=
Worker
.
getInstance
();
}
worker
.
onInterrupt
(
this
);
}
}
app/src/main/java/com/xf/weixinclick/agent/AgentExecutor.java
View file @
caf4e2f3
...
...
@@ -12,6 +12,7 @@ import com.xf.weixinclick.myApplication;
import
java.util.concurrent.Callable
;
import
rx.Single
;
import
rx.SingleSubscriber
;
import
rx.android.schedulers.AndroidSchedulers
;
import
rx.schedulers.Schedulers
;
public
class
AgentExecutor
{
...
...
@@ -59,11 +60,31 @@ public class AgentExecutor {
}
public
static
void
execNonReturn
(
final
String
cmd
){
public
static
CmdResult
execNonReturn
(
final
String
cmd
){
exec
(
cmd
).
toBlocking
().
value
();
return
exec
(
cmd
).
toBlocking
().
value
();
}
public
static
Single
<
Boolean
>
restartNetwork
(){
return
Single
.
fromCallable
(
new
Callable
<
Boolean
>()
{
@Override
public
Boolean
call
()
throws
Exception
{
try
{
return
agentManager
.
restart4G
();
}
catch
(
Throwable
throwable
)
{
throw
new
Exception
(
throwable
);
}
}
}).
subscribeOn
(
Schedulers
.
io
())
.
observeOn
(
AndroidSchedulers
.
mainThread
());
}
public
static
boolean
isConnected
(){
return
agentManager
.
isRunning
();
}
...
...
app/src/main/java/com/xf/weixinclick/agent/AutoProcesser.java
View file @
caf4e2f3
...
...
@@ -4,9 +4,11 @@ import android.content.Context;
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.myApplication
;
import
rx.Single
;
import
rx.SingleSubscriber
;
import
rx.Subscriber
;
import
rx.android.schedulers.AndroidSchedulers
;
import
rx.schedulers.Schedulers
;
...
...
@@ -18,22 +20,62 @@ public class AutoProcesser {
* 自动开启辅助服务
* @param context
*/
public
static
void
enableAccessibility
(
Context
context
){
public
static
void
enableAccessibility
(
final
Context
context
,
final
SingleSubscriber
<
Boolean
>
subscriber
){
DebugTools
.
showAction
(
"自动开启辅助服务中,请勿点击!"
);
Single
.
fromCallable
(
new
EnableAccessibility
(
context
.
getApplicationContext
()))
.
subscribeOn
(
Schedulers
.
io
())
.
observeOn
(
AndroidSchedulers
.
mainThread
()).
subscribe
(
new
SingleSubscriber
<
Boolean
>()
{
@Override
public
void
onSuccess
(
Boolean
aBoolean
)
{
DebugTools
.
dismiss
();
Log
.
e
(
TAG
,
"onSuccess -->自动开启辅助服务 "
+
aBoolean
);
Toast
.
makeText
(
context
,
"开启辅助服务 "
+
aBoolean
,
Toast
.
LENGTH_SHORT
).
show
();
if
(
subscriber
!=
null
){
subscriber
.
onSuccess
(
aBoolean
);
}
}
@Override
public
void
onError
(
Throwable
error
)
{
DebugTools
.
dismiss
();
Log
.
e
(
TAG
,
"onError --> "
,
error
);
if
(
subscriber
!=
null
){
subscriber
.
onError
(
error
);
}
}
});
}
public
static
void
enableUsageStats
(
final
Context
context
,
final
SingleSubscriber
<
Boolean
>
subscriber
){
DebugTools
.
showAction
(
"自动开启UsageStats,请勿点击!"
);
Single
.
fromCallable
(
new
EnableUsageStats
(
context
))
.
subscribeOn
(
Schedulers
.
io
())
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
subscribe
(
new
SingleSubscriber
<
Boolean
>()
{
@Override
public
void
onSuccess
(
Boolean
aBoolean
)
{
Log
.
e
(
TAG
,
"onSuccess -->自动开启 UsageStats "
+
aBoolean
);
DebugTools
.
dismiss
();
}
@Override
public
void
onError
(
Throwable
error
)
{
DebugTools
.
dismiss
();
}
});
}
}
app/src/main/java/com/xf/weixinclick/agent/DebugTools.java
View file @
caf4e2f3
package
com
.
xf
.
weixinclick
.
agent
;
import
android.content.Context
;
import
android.graphics.Color
;
import
android.graphics.PixelFormat
;
import
android.os.Handler
;
import
android.os.Looper
;
import
android.util.Log
;
import
android.view.Gravity
;
import
android.view.ViewGroup
;
import
android.view.WindowManager
;
import
android.view.WindowManager.LayoutParams
;
import
android.widget.ScrollView
;
import
android.widget.TextView
;
import
com.xf.weixinclick.debugtool.LogcatTools
;
import
com.xf.weixinclick.myApplication
;
import
rx.android.schedulers.AndroidSchedulers
;
public
class
DebugTools
{
private
static
Handler
sHandler
=
new
Handler
(
Looper
.
getMainLooper
());
private
static
TextView
textView
;
...
...
@@ -14,32 +26,30 @@ public class DebugTools {
//LogcatTools.startLogcat(context);
// WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
//
// WindowManager.LayoutParams lp = new LayoutParams();
// lp.flags = LayoutParams.FLAG_NOT_FOCUSABLE |LayoutParams.FLAG_NOT_TOUCHABLE|LayoutParams.FLAG_NOT_TOUCH_MODAL;
// lp.type = LayoutParams.TYPE_TOAST;
// lp.gravity = Gravity.RIGHT|Gravity.TOP;
// lp.format= PixelFormat.RGBA_8888;
//
// lp.width = dip2px(200);
// lp.height = dip2px(200);
//
//
// ScrollView scrollView = new ScrollView(context);
//
// textView = new TextView(context);
// textView.setTextColor(Color.RED);
// textView.setText("debug");
// //textView.setVerticalScrollBarEnabled(true);
//
// scrollView.addView(textView, ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
//
// windowManager.addView(scrollView,lp);
}
public
static
void
showLog
(
boolean
show
){
public
static
void
showLog
(
String
title
){
Context
context
=
myApplication
.
getInstence
();
WindowManager
windowManager
=
(
WindowManager
)
context
.
getSystemService
(
Context
.
WINDOW_SERVICE
);
WindowManager
.
LayoutParams
lp
=
new
LayoutParams
();
lp
.
flags
=
LayoutParams
.
FLAG_NOT_FOCUSABLE
|
LayoutParams
.
FLAG_NOT_TOUCHABLE
|
LayoutParams
.
FLAG_NOT_TOUCH_MODAL
;
lp
.
type
=
LayoutParams
.
TYPE_TOAST
;
lp
.
gravity
=
Gravity
.
CENTER
;
lp
.
format
=
PixelFormat
.
RGBA_8888
;
lp
.
width
=
dip2px
(
200
);
lp
.
height
=
dip2px
(
200
);
textView
=
new
TextView
(
context
);
textView
.
setTextColor
(
Color
.
RED
);
textView
.
setText
(
title
);
textView
.
setTextSize
(
16
);
//textView.setVerticalScrollBarEnabled(true);
windowManager
.
addView
(
textView
,
lp
);
}
...
...
@@ -57,10 +67,70 @@ public class DebugTools {
}
public
static
void
showAction
(
final
String
text
){
Runnable
runnable
=
new
Runnable
()
{
@Override
public
void
run
()
{
Context
context
=
myApplication
.
getInstence
();
WindowManager
windowManager
=
(
WindowManager
)
context
.
getSystemService
(
Context
.
WINDOW_SERVICE
);
WindowManager
.
LayoutParams
lp
=
new
LayoutParams
();
lp
.
flags
=
LayoutParams
.
FLAG_NOT_FOCUSABLE
|
LayoutParams
.
FLAG_NOT_TOUCHABLE
|
LayoutParams
.
FLAG_NOT_TOUCH_MODAL
;
lp
.
type
=
LayoutParams
.
TYPE_TOAST
;
lp
.
gravity
=
Gravity
.
CENTER
;
lp
.
format
=
PixelFormat
.
RGBA_8888
;
lp
.
width
=
dip2px
(
200
);
lp
.
height
=
dip2px
(
200
);
textView
=
new
TextView
(
context
);
textView
.
setTextColor
(
Color
.
RED
);
textView
.
setText
(
text
);
textView
.
setTextSize
(
16
);
//textView.setVerticalScrollBarEnabled(true);
windowManager
.
addView
(
textView
,
lp
);
}
};
runOnMainThread
(
runnable
);
}
public
static
void
dismiss
(){
Runnable
runnable
=
new
Runnable
()
{
@Override
public
void
run
()
{
Context
context
=
myApplication
.
getInstence
();
WindowManager
windowManager
=
(
WindowManager
)
context
.
getSystemService
(
Context
.
WINDOW_SERVICE
);
if
(
textView
!=
null
&&
textView
.
getParent
()
!=
null
){
Log
.
e
(
"test"
,
"run --> dismiss "
);
windowManager
.
removeView
(
textView
);
}
textView
=
null
;
}
};
runOnMainThread
(
runnable
);
}
public
static
int
dip2px
(
float
dpValue
)
{
float
scale
=
myApplication
.
getInstence
().
getResources
().
getDisplayMetrics
().
density
;
return
(
int
)
(
dpValue
*
scale
+
0.5
F
);
}
private
static
void
runOnMainThread
(
Runnable
runnable
){
if
(
Thread
.
currentThread
()
!=
Looper
.
getMainLooper
().
getThread
()){
sHandler
.
post
(
runnable
);
}
else
{
runnable
.
run
();
}
}
}
app/src/main/java/com/xf/weixinclick/agent/MotionRunner.java
View file @
caf4e2f3
...
...
@@ -4,6 +4,7 @@ import android.graphics.Rect;
import
android.support.v4.view.ViewCompat.FocusRealDirection
;
import
android.view.KeyEvent
;
import
android.view.View
;
import
com.xf.agent.common.CmdResult
;
/**
...
...
@@ -61,9 +62,11 @@ public class MotionRunner {
* @param x
* @param y
*/
public
void
tap
(
int
x
,
int
y
){
public
boolean
tap
(
int
x
,
int
y
){
AgentExecutor
.
execNonReturn
(
TAP_EVENT_CMD
+
x
+
" "
+
y
);
CmdResult
cmdResult
=
AgentExecutor
.
execNonReturn
(
TAP_EVENT_CMD
+
x
+
" "
+
y
);
return
cmdResult
!=
null
&&
cmdResult
.
code
==
0
;
}
...
...
app/src/main/java/com/xf/weixinclick/agent/UiHierarchyFinder.java
View file @
caf4e2f3
...
...
@@ -9,6 +9,10 @@ import com.xf.weixinclick.agent.uiautomator.UiHierarchyXmlLoader;
import
com.xf.weixinclick.agent.uiautomator.UiNode
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.concurrent.Callable
;
import
rx.Single
;
import
rx.android.schedulers.AndroidSchedulers
;
import
rx.schedulers.Schedulers
;
public
class
UiHierarchyFinder
{
...
...
@@ -41,6 +45,24 @@ public class UiHierarchyFinder {
return
findNodeByText
(
text
);
}
public
Single
<
List
<
UiNode
>>
dumpAndFindByNameAsync
(
final
String
text
)
{
return
Single
.
fromCallable
(
new
Callable
<
List
<
UiNode
>>()
{
@Override
public
List
<
UiNode
>
call
()
throws
Exception
{
if
(
basicTreeNode
==
null
)
{
dump
();
parseDefault
();
}
return
findNodeByText
(
text
);
}
}).
subscribeOn
(
Schedulers
.
io
())
.
observeOn
(
AndroidSchedulers
.
mainThread
());
}
public
void
parseDefault
()
{
UiHierarchyXmlLoader
loader
=
new
UiHierarchyXmlLoader
();
basicTreeNode
=
loader
.
parseXml
(
DEF_FILE_PATH
);
...
...
app/src/main/java/com/xf/weixinclick/agent/auto/EnableAccessibility.java
View file @
caf4e2f3
...
...
@@ -68,7 +68,7 @@ public class EnableAccessibility implements Callable<Boolean> {
DebugTools
.
log
(
"点击第0个节点的位置"
+
bounds
);
MotionRunner
.
get
().
tap
(
bounds
.
centerX
(),
bounds
.
centerY
());
SystemClock
.
sleep
(
2
000
);
SystemClock
.
sleep
(
1
000
);
//打开了无障碍页面
//搜索家粉
...
...
@@ -116,21 +116,21 @@ public class EnableAccessibility implements Callable<Boolean> {
//点击确定按钮
MotionRunner
.
get
().
tap
(
470
,
870
);
SystemClock
.
sleep
(
20
00
);
SystemClock
.
sleep
(
15
00
);
//然后返回
MotionRunner
.
get
().
clickBack
();
SystemClock
.
sleep
(
20
00
);
SystemClock
.
sleep
(
15
00
);
MotionRunner
.
get
().
clickBack
();
SystemClock
.
sleep
(
20
00
);
SystemClock
.
sleep
(
15
00
);
MotionRunner
.
get
().
clickBack
();
SystemClock
.
sleep
(
20
00
);
SystemClock
.
sleep
(
15
00
);
return
true
;
}
...
...
app/src/main/java/com/xf/weixinclick/agent/auto/EnableUsageStats.java
0 → 100644
View file @
caf4e2f3
package
com
.
xf
.
weixinclick
.
agent
.
auto
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.os.SystemClock
;
import
android.util.Log
;
import
java.util.concurrent.Callable
;
/**
* 自动开启UsageStatsManager
*/
public
class
EnableUsageStats
implements
Callable
<
Boolean
>
{
private
static
final
String
TAG
=
"EnableUsageStats"
;
private
Context
context
;
public
EnableUsageStats
(
Context
context
)
{
this
.
context
=
context
;
}
@Override
public
Boolean
call
()
throws
Exception
{
Log
.
e
(
TAG
,
"exec --> 启动act"
);
startAct
();
SystemClock
.
sleep
(
2000
);
return
true
;
}
private
void
startAct
(){
Intent
intent2
=
new
Intent
(
android
.
provider
.
Settings
.
ACTION_USAGE_ACCESS_SETTINGS
);
intent2
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
context
.
startActivity
(
intent2
);
}
}
app/src/main/java/com/xf/weixinclick/core/MsgSender.java
0 → 100644
View file @
caf4e2f3
package
com
.
xf
.
weixinclick
.
core
;
import
android.content.Context
;
import
com.xf.weixinclick.NewService
;
import
com.xf.weixinclick.agent.AutoProcesser
;
import
com.xf.weixinclick.bean.msg.ReceiverMsg
;
import
com.xf.weixinclick.utils.Accessibilitys
;
import
org.greenrobot.eventbus.EventBus
;
import
rx.SingleSubscriber
;
public
class
MsgSender
{
private
static
final
String
TAG
=
"MsgSender"
;
public
static
void
checkAndSend
(
Context
context
,
final
ReceiverMsg
msg
){
//辅助服务开启并且可以收到消息
if
(
Accessibilitys
.
isSettingsOn
(
context
)
&&
EventBus
.
getDefault
().
hasSubscriberForEvent
(
ReceiverMsg
.
class
)
){
EventBus
.
getDefault
().
post
(
msg
);
}
else
{
//没有开启,先打开
AutoProcesser
.
enableAccessibility
(
context
,
new
SingleSubscriber
<
Boolean
>()
{
@Override
public
void
onSuccess
(
Boolean
aBoolean
)
{
if
(
aBoolean
){
EventBus
.
getDefault
().
post
(
msg
);
}
else
{
NewService
.
logToastAndUpload
(
TAG
,
"auto open AccessibilityService fail?"
);
}
}
@Override
public
void
onError
(
Throwable
error
)
{
NewService
.
logToastAndUpload
(
TAG
,
"auto open AccessibilityService error:"
+
error
.
getMessage
());
}
});
}
}
}
app/src/main/java/com/xf/weixinclick/core/TaskSession.java
0 → 100644
View file @
caf4e2f3
package
com
.
xf
.
weixinclick
.
core
;
import
android.accessibilityservice.AccessibilityService
;
import
android.content.ComponentName
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.graphics.Rect
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.os.Handler.Callback
;
import
android.os.Looper
;
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.agent.AutoProcesser
;
import
com.xf.weixinclick.agent.MotionRunner
;
import
com.xf.weixinclick.agent.UiHierarchyFinder
;
import
com.xf.weixinclick.agent.uiautomator.UiNode
;
import
com.xf.weixinclick.bean.msg.ReceiverMsg
;
import
com.xf.weixinclick.myApplication
;
import
com.xf.weixinclick.utils.Accessibilitys
;
import
java.lang.reflect.Field
;
import
java.util.List
;
import
org.greenrobot.eventbus.EventBus
;
import
rx.SingleSubscriber
;
class
TaskSession
{
private
static
final
String
TAG
=
"TaskSession"
;
private
static
final
String
WX_PKG
=
"com.tencent.mm"
;
private
static
final
String
WX_MAIN_UI
=
"com.tencent.mm.ui.LauncherUI"
;
private
static
final
String
WX_WEB_UI
=
"com.tencent.mm.plugin.webview.ui.tools.WebViewUI"
;
private
static
final
String
LINE_SEP
=
System
.
getProperty
(
"line.separator"
);
private
static
final
int
TIME_OUT_WHAT
=
2
;
private
ReceiverMsg
message
;
private
Context
context
;
private
Handler
handler
;
private
Rect
nodeRect
=
new
Rect
();
private
TaskCallback
taskCallback
;
private
AccessibilityService
service
;
TaskSession
(
ReceiverMsg
message
,
TaskCallback
callback
)
{
this
.
message
=
message
;
context
=
myApplication
.
getInstence
();
taskCallback
=
callback
;
handler
=
new
Handler
(
Looper
.
getMainLooper
(),
new
Callback
()
{
@Override
public
boolean
handleMessage
(
Message
msg
)
{
if
(
msg
.
what
==
TIME_OUT_WHAT
){
onError
(
"Timeout! last step:"
+
step
+
", reason:"
+
msg
.
obj
);
return
true
;
}
return
false
;
}
});
}
private
boolean
isEnd
=
false
;
private
int
step
=
-
1
;
void
start
(){
isEnd
=
false
;
final
Runnable
runnable
=
new
Runnable
()
{
@Override
public
void
run
()
{
//启动微信
startWechat
();
//开始监听事件
step
=
0
;
}
};
//先检查辅助服务
if
(!
Accessibilitys
.
isSettingsOn
(
context
)){
//没有开启,先打开
AutoProcesser
.
enableAccessibility
(
context
,
new
SingleSubscriber
<
Boolean
>()
{
@Override
public
void
onSuccess
(
Boolean
aBoolean
)
{
if
(
aBoolean
){
//
taskLog
(
"auto open AccessibilityService success !"
);
runnable
.
run
();
}
else
{
isEnd
=
true
;
taskLog
(
"auto open AccessibilityService fail?"
);
toastLog
(
"自动开启辅助服务失败"
);
TaskSession
.
this
.
onError
(
"自动开启辅助服务失败"
);
}
}
@Override
public
void
onError
(
Throwable
error
)
{
taskLog
(
"auto open AccessibilityService error:"
,
error
);
isEnd
=
true
;
toastLog
(
"自动开启辅助服务失败"
+
error
.
getMessage
());
TaskSession
.
this
.
onError
(
"自动开启辅助服务失败"
+
error
.
getMessage
());
}
});
}
else
{
runnable
.
run
();
}
}
//启动微信
private
void
startWechat
(){
Intent
intent
=
new
Intent
();
ComponentName
cmp
=
new
ComponentName
(
WX_PKG
,
WX_MAIN_UI
);
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
);
context
.
startActivity
(
intent
);
}
void
handleEvent
(
AccessibilityService
service
,
AccessibilityEvent
event
){
this
.
service
=
service
;
if
(
step
==
-
1
||
isEnd
){
return
;
}
Log
.
e
(
TAG
,
"handleEvent --> "
+
event
);
final
AccessibilityNodeInfo
rootInActiveWindow
=
service
.
getRootInActiveWindow
();
if
(
rootInActiveWindow
!=
null
){
if
(
step
==
0
){
//先点击[微信]按钮
AccessibilityNodeInfo
homeWX
=
findByIdAndText
(
rootInActiveWindow
,
WXIdsConfig
.
TV_HOME_WX
,
"微信"
);
taskLog
(
"查找 homeWX "
+
homeWX
);
if
(
clickNode
(
homeWX
)){
taskLog
(
"点击微信 成功!"
);
setNextStep
(
10
);
}
else
{
trackTimeout
(
"找不到微信按钮,不在主界面?"
);
}
}
else
if
(
step
==
10
){
//当前在微信首页了
AccessibilityNodeInfo
homeWX
=
findByIdAndText
(
rootInActiveWindow
,
WXIdsConfig
.
HOME_MSG_TITLE
,
"文件传输助手"
);
taskLog
(
"查找 文件传输助手 "
+
homeWX
);
if
(
clickNode
(
homeWX
)){
taskLog
(
"点击微信 文件传输助手!"
);
setNextStep
(
20
);
}
else
{
trackTimeout
(
"点击微信 文件传输助手 失败,出现错误!"
);
}
}
else
if
(
step
==
20
){
//进入聊天界面并填充
AccessibilityNodeInfo
changeInput
=
findByIdAndDesc
(
rootInActiveWindow
,
WXIdsConfig
.
BTN_CHANGE_INPUT
,
"切换到键盘"
);
if
(
changeInput
!=
null
){
//切换键盘
changeInput
.
performAction
(
AccessibilityNodeInfo
.
ACTION_CLICK
);
taskLog
(
"点击了 切换到键盘"
);
//等待下个事件触发
trackTimeout
(
"切换到键盘,等待显示输入框"
);
return
;
}
AccessibilityNodeInfo
etNodeInfo
=
findEditText
(
rootInActiveWindow
);
if
(
etNodeInfo
!=
null
)
{
Bundle
arguments
=
new
Bundle
();
arguments
.
putCharSequence
(
AccessibilityNodeInfo
.
ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE
,
message
.
getQr_addr
());
etNodeInfo
.
performAction
(
AccessibilityNodeInfo
.
ACTION_SET_TEXT
,
arguments
);
taskLog
(
"填充点击地址成功"
);
setNextStep
(
21
);
}
else
{
trackTimeout
(
"没有找到消息输入框!无法输入数据!"
);
}
}
else
if
(
step
==
21
){
taskLog
(
"点击输入框,显示发送按钮"
);
delayRun
(
2000
,
new
Runnable
()
{
@Override
public
void
run
()
{
AccessibilityNodeInfo
editText
=
findEditText
(
rootInActiveWindow
);
if
(
editText
!=
null
){
taskLog
(
"点击输入框"
);
clickNode
(
editText
);
setNextStep
(
30
);
recycle
(
rootInActiveWindow
);
}
else
{
taskLog
(
"没有找到输入框!!"
);
trackTimeout
(
"没有找到输入框,无法切换到线索发送按钮!"
);
}
}
});
step
=
22
;
return
;
}
else
if
(
step
==
30
){
//点击发送按钮
toastLog
(
"延迟点击发送按钮"
);
delayRun
(
4000
,
new
Runnable
()
{
@Override
public
void
run
()
{
sendMsg
(
rootInActiveWindow
);
try
{
recycle
(
rootInActiveWindow
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
});
step
=
31
;
return
;
}
else
if
(
step
==
40
){
//准备点击链接
List
<
AccessibilityNodeInfo
>
nodeInfos
=
rootInActiveWindow
.
findAccessibilityNodeInfosByViewId
(
WXIdsConfig
.
ITEM_MSG_CARD
);
if
(
nodeInfos
!=
null
&&
!
nodeInfos
.
isEmpty
()){
//点击最下面的消息链接,
int
msgY
=
0
;
nodeRect
.
setEmpty
();
AccessibilityNodeInfo
lastMsgNode
=
null
;
for
(
AccessibilityNodeInfo
nodeInfo
:
nodeInfos
)
{
nodeInfo
.
getBoundsInScreen
(
nodeRect
);
if
(
nodeRect
.
centerY
()
>
msgY
){
//靠下
lastMsgNode
=
nodeInfo
;
msgY
=
nodeRect
.
centerY
();
}
}
if
(
lastMsgNode
!=
null
){
taskLog
(
"最可能的区域 node -->> "
+
lastMsgNode
);
// boolean b = lastMsgNode.performAction(AccessibilityNodeInfo.ACTION_CLICK);
// taskLog("点击最后一条消息 "+b);
boolean
b
=
clickNode
(
lastMsgNode
);
taskLog
(
"点击最后一条消息 "
+
b
);
setNextStep
(
50
);
}
else
{
trackTimeout
(
"点击 消息 失败!"
);
}
}
else
{
trackTimeout
(
"找不到刚才发送的消息"
);
}
}
else
if
(
step
==
50
){
if
(
TextUtils
.
equals
(
WX_WEB_UI
,
event
.
getClassName
())){
//成功打开webview页面
taskLog
(
"成功打开webview页面"
);
setNextStep
(
51
);
}
else
{
trackTimeout
(
"没有打开webview界面!"
);
}
}
else
if
(
step
==
51
){
//长按
taskLog
(
"长按图片"
);
delayRun
(
3000
,
new
Runnable
()
{
@Override
public
void
run
()
{
taskLog
(
"长按图片识别"
);
MotionRunner
.
get
().
longPress
(
300
,
600
,
4000
);
setNextStep
(
53
);
}
});
step
=
52
;
}
else
if
(
step
==
53
){
//识别图片中的二维码
AccessibilityNodeInfo
qrScan
=
findByIdAndText
(
rootInActiveWindow
,
WXIdsConfig
.
BTN_SCAN_QR
,
"识别图中二维码"
);
taskLog
(
"搜索 识别图片中的二维码"
);
if
(
qrScan
!=
null
){
taskLog
(
"点击 识别图片中的二维码"
);
clickNode
(
qrScan
);
isOkStep
();
setNextStep
(
54
);
}
else
{
trackTimeout
(
"找不到 识别图中二维码按钮"
);
}
}
else
if
(
step
==
54
){
if
(
WX_WEB_UI
.
equals
(
event
.
getClassName
())){
//已经跳转到下一个页面
setNextStep
(
55
);
}
else
{
trackTimeout
(
"跳转到下一个页面超时 "
);
}
}
else
if
(
step
==
55
){
step
=
56
;
delayRun
(
3000
,
new
Runnable
()
{
@Override
public
void
run
()
{
if
(
MotionRunner
.
get
().
tap
(
200
,
680
)){
setNextStep
(
60
);
isOkStep
();
}
else
{
trackTimeout
(
"点击确定失败!"
);
}
}
});
}
else
if
(
step
==
60
){
step
=
61
;
delayRun
(
3000
,
new
Runnable
()
{
@Override
public
void
run
()
{
UiHierarchyFinder
finder
=
new
UiHierarchyFinder
();
finder
.
dumpAndFindByNameAsync
(
""
).
subscribe
(
new
SingleSubscriber
<
List
<
UiNode
>>()
{
@Override
public
void
onSuccess
(
List
<
UiNode
>
uiNodes
)
{
}
@Override
public
void
onError
(
Throwable
error
)
{
}
});
}
});
boolean
isLogined
=
contains
(
rootInActiveWindow
,
"已确认登录"
);
if
(
isLogined
){
isOkStep
();
end
();
delayRun
(
2000
,
new
Runnable
()
{
@Override
public
void
run
()
{
MotionRunner
.
get
().
clickBack
();
}
});
delayRun
(
4000
,
new
Runnable
()
{
@Override
public
void
run
()
{
MotionRunner
.
get
().
clickBack
();
}
});
delayRun
(
6000
,
new
Runnable
()
{
@Override
public
void
run
()
{
MotionRunner
.
get
().
clickBack
();
onSuccess
();
}
});
}
else
{
trackTimeout
(
"找不到 确认登录 标记"
);
}
}
}
recycle
(
rootInActiveWindow
);
}
private
void
setNextStep
(
int
nextStep
){
isOkStep
();
step
=
nextStep
;
}
private
boolean
contains
(
AccessibilityNodeInfo
nodeInfo
,
String
text
){
int
childCount
=
nodeInfo
.
getChildCount
();
if
(
childCount
>
0
)
{
for
(
int
i
=
0
;
i
<
nodeInfo
.
getChildCount
();
i
++)
{
AccessibilityNodeInfo
child
=
nodeInfo
.
getChild
(
i
);
if
(
child
!=
null
){
contains
(
child
,
text
);
}
}
}
else
{
CharSequence
viewText
=
nodeInfo
.
getText
();
if
(!
TextUtils
.
isEmpty
(
viewText
)){
return
viewText
.
toString
().
startsWith
(
text
);
}
}
return
false
;
}
private
void
sendMsg
(
AccessibilityNodeInfo
rootInActiveWindow
)
{
AccessibilityNodeInfo
btnSend
=
findByIdAndText
(
rootInActiveWindow
,
WXIdsConfig
.
BTN_SEND_MSG
,
"发送"
);
if
(
btnSend
!=
null
){
//点击发送按钮
btnSend
.
performAction
(
AccessibilityNodeInfo
.
ACTION_CLICK
);
taskLog
(
"消息发送成功!"
);
setNextStep
(
40
);
}
else
{
taskLog
(
"找不到发送按钮!"
);
trackTimeout
(
"找不到 [发送] 按钮!"
);
}
}
private
void
printNodes
(
List
<
AccessibilityNodeInfo
>
nodes
){
if
(
nodes
==
null
||
nodes
.
isEmpty
()){
Log
.
e
(
TAG
,
"printNodes --> is empty!"
);
}
else
{
Log
.
e
(
TAG
,
"printNodes --> start"
);
for
(
AccessibilityNodeInfo
node
:
nodes
)
{
Log
.
e
(
TAG
,
"printNodes --> "
+
node
.
getViewIdResourceName
()+
" "
+
node
.
getText
());
}
Log
.
e
(
TAG
,
"printNodes --> end"
);
}
}
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
AccessibilityNodeInfo
findByIdAndDesc
(
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
.
getContentDescription
())){
return
nodeInfo
;
}
}
return
null
;
}
private
boolean
isEmptyNodes
(
List
<
AccessibilityNodeInfo
>
nodeInfos
){
return
nodeInfos
==
null
||
nodeInfos
.
isEmpty
();
}
private
void
recycle
(
AccessibilityNodeInfo
info
)
{
if
(
info
==
null
){
return
;
}
int
childCount
=
info
.
getChildCount
();
if
(
childCount
>
0
)
{
for
(
int
i
=
0
;
i
<
info
.
getChildCount
();
i
++)
{
recycle
(
info
.
getChild
(
i
));
}
}
else
{
info
.
recycle
();
}
}
private
void
taskLog
(
String
log
){
Log
.
e
(
TAG
,
step
+
" "
+
log
+
LINE_SEP
);
}
private
void
taskLog
(
String
log
,
Throwable
throwable
){
Log
.
e
(
TAG
,
step
+
" "
+
log
,
throwable
);
}
private
void
toastLog
(
String
msg
){
}
private
void
delayRun
(
int
delay
,
Runnable
runnable
){
handler
.
postDelayed
(
runnable
,
delay
);
}
//点击
private
boolean
clickNode
(
AccessibilityNodeInfo
nodeInfo
){
nodeRect
.
setEmpty
();
if
(
nodeInfo
!=
null
){
nodeInfo
.
getBoundsInScreen
(
nodeRect
);
}
if
(
nodeRect
.
isEmpty
()){
return
false
;
}
return
MotionRunner
.
get
().
tap
(
nodeRect
.
centerX
(),
nodeRect
.
centerY
());
}
private
boolean
isWechatUI
(
AccessibilityEvent
event
){
return
event
!=
null
&&
TextUtils
.
equals
(
event
.
getClassName
(),
WX_MAIN_UI
);
}
private
void
trackTimeout
(
String
timeOutMsg
){
taskLog
(
"检查超时---"
);
Message
msg
=
Message
.
obtain
();
msg
.
what
=
TIME_OUT_WHAT
;
msg
.
obj
=
timeOutMsg
;
handler
.
removeMessages
(
TIME_OUT_WHAT
);
handler
.
sendMessageDelayed
(
msg
,
1000
*
20
);
}
private
void
isOkStep
(){
handler
.
removeMessages
(
TIME_OUT_WHAT
);
}
private
AccessibilityNodeInfo
findEditText
(
AccessibilityNodeInfo
rootInActiveWindow
){
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
())){
return
et
;
}
}
}
return
null
;
}
//成功回调
private
void
onSuccess
(){
end
();
taskCallback
.
onSuccess
();
service
=
null
;
}
//失败
private
void
onError
(
String
msg
){
end
();
taskCallback
.
onError
(
msg
);
service
=
null
;
}
//停止接收事件
void
end
(){
isEnd
=
true
;
}
boolean
canHandle
(){
return
!
isEnd
;
}
interface
TaskCallback
{
void
onSuccess
();
void
onError
(
String
msg
);
}
}
app/src/main/java/com/xf/weixinclick/core/WXIdsConfig.java
0 → 100644
View file @
caf4e2f3
package
com
.
xf
.
weixinclick
.
core
;
final
class
WXIdsConfig
{
private
static
final
String
ID_PREFIX
=
"com.tencent.mm:id/"
;
//不同版本id可能不同,根据后台配置更新
public
static
final
String
TV_HOME_WX
=
ID_PREFIX
+
"ca5"
;
//底部导航文件,根据 微信 匹配
public
static
final
String
HOME_MSG_TITLE
=
ID_PREFIX
+
"apx"
;
//文件传输助手,有多个,再根据文本匹配
public
static
final
String
BTN_CHANGE_INPUT
=
ID_PREFIX
+
"aaa"
;
//却换输入文字,匹配 切换到键盘
public
static
final
String
ET_INPUT_MSG
=
ID_PREFIX
+
"aac"
;
//聊天页面输入框
public
static
final
String
BTN_SEND_MSG
=
ID_PREFIX
+
"aai"
;
//聊天页面发送按钮
public
static
final
String
ITEM_MSG_CARD
=
ID_PREFIX
+
"jj"
;
//聊天页面消息卡片
public
static
final
String
BTN_SCAN_QR
=
ID_PREFIX
+
"ga"
;
//识别二维码
}
app/src/main/java/com/xf/weixinclick/core/Worker.java
0 → 100644
View file @
caf4e2f3
package
com
.
xf
.
weixinclick
.
core
;
import
android.accessibilityservice.AccessibilityService
;
import
android.support.annotation.Keep
;
import
android.util.Log
;
import
android.view.accessibility.AccessibilityEvent
;
import
com.xf.weixinclick.bean.msg.ReceiverMsg
;
import
com.xf.weixinclick.core.TaskSession.TaskCallback
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
java.util.concurrent.locks.Condition
;
import
java.util.concurrent.locks.Lock
;
import
java.util.concurrent.locks.ReentrantLock
;
import
org.greenrobot.eventbus.EventBus
;
import
org.greenrobot.eventbus.Subscribe
;
/**
* 收到任务消息 --> 加入队列 --> 启动执行 --> 检测运行环境(开启辅助服务,打开微信首页等)
*
* --> 依次点击(并检查点击结果) --> 返回并且执行结果上报 --> 继续下一个消息或者
*/
public
class
Worker
{
private
static
final
String
LINE_SEP
=
System
.
getProperty
(
"line.separator"
);
private
static
final
String
TAG
=
"Worker"
;
private
static
Worker
sWorker
=
null
;
public
static
Worker
getInstance
()
{
if
(
sWorker
==
null
)
{
synchronized
(
Worker
.
class
)
{
if
(
sWorker
==
null
)
{
sWorker
=
new
Worker
();
}
}
}
return
sWorker
;
}
private
Lock
lock
=
new
ReentrantLock
();
private
Condition
condition
=
lock
.
newCondition
();
private
TaskSession
currentTaskSession
;
private
LinkedBlockingQueue
<
ReceiverMsg
>
msgQueue
=
new
LinkedBlockingQueue
<>();
private
Worker
()
{
EventBus
.
getDefault
().
register
(
this
);
startQueue
();
}
private
void
startQueue
(){
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
boolean
run
=
true
;
while
(
run
)
{
try
{
if
(!
msgQueue
.
isEmpty
())
{
ReceiverMsg
msg
=
msgQueue
.
poll
();
Log
.
e
(
TAG
,
"run --> 读取下一个消息"
);
startSession
(
msg
);
taskWait
();
Log
.
e
(
TAG
,
"run --> "
+
msg
.
getUnique_id
()
+
" 结束"
+
LINE_SEP
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
run
=
false
;
}
}
}
}).
start
();
}
public
void
handleEvent
(
AccessibilityService
service
,
AccessibilityEvent
event
)
{
if
(
currentTaskSession
!=
null
&&
currentTaskSession
.
canHandle
())
{
currentTaskSession
.
handleEvent
(
service
,
event
);
}
else
{
Log
.
e
(
TAG
,
"handleEvent --> 当前不需要处理"
+
LINE_SEP
);
}
}
public
void
onInterrupt
(
AccessibilityService
service
)
{
stopSession
();
}
@Keep
@Subscribe
public
void
receiverMsg
(
final
ReceiverMsg
msg
)
{
Log
.
e
(
TAG
,
"receiverMsg --> 收到消息"
);
msgQueue
.
add
(
msg
);
}
private
void
taskWait
()
{
try
{
lock
.
lock
();
condition
.
await
();
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
finally
{
lock
.
unlock
();
}
}
private
void
taskOver
()
{
try
{
lock
.
lock
();
condition
.
signal
();
}
finally
{
lock
.
unlock
();
}
}
private
void
startSession
(
ReceiverMsg
msg
)
{
Log
.
e
(
TAG
,
"startSession --> "
+
LINE_SEP
);
currentTaskSession
=
new
TaskSession
(
msg
,
new
TaskCallback
()
{
@Override
public
void
onSuccess
()
{
Log
.
e
(
TAG
,
"onSuccess --> "
+
LINE_SEP
);
taskOver
();
}
@Override
public
void
onError
(
String
msg
)
{
Log
.
e
(
TAG
,
"onError --> "
+
msg
+
LINE_SEP
);
taskOver
();
}
});
currentTaskSession
.
start
();
}
public
void
stopSession
()
{
Log
.
e
(
TAG
,
"stopSession --> "
);
taskOver
();
if
(
currentTaskSession
!=
null
)
{
currentTaskSession
.
end
();
}
currentTaskSession
=
null
;
}
public
void
clearAllMessage
(){
msgQueue
.
clear
();
}
}
app/src/main/java/com/xf/weixinclick/receiver/MyMessageReceiver.java
View file @
caf4e2f3
...
...
@@ -13,9 +13,12 @@ import com.google.gson.Gson;
import
com.xf.weixinclick.MainActivity
;
import
com.xf.weixinclick.NewService
;
import
com.xf.weixinclick.R
;
import
com.xf.weixinclick.agent.AutoProcesser
;
import
com.xf.weixinclick.bean.msg.ReceiverMsg
;
import
com.xf.weixinclick.core.MsgSender
;
import
com.xf.weixinclick.myApplication
;
import
com.xf.weixinclick.utils.Accessibilitys
;
import
org.greenrobot.eventbus.EventBus
;
import
java.text.SimpleDateFormat
;
...
...
@@ -24,6 +27,7 @@ import java.util.Locale;
import
java.util.Map
;
import
rx.Observable
;
import
rx.SingleSubscriber
;
import
rx.Subscriber
;
import
rx.android.schedulers.AndroidSchedulers
;
import
rx.observers.Observers
;
...
...
@@ -72,7 +76,8 @@ public class MyMessageReceiver extends MessageReceiver {
e
.
printStackTrace
();
}
NewService
.
showToast
(
context
,
String
.
format
(
"接收到消息,时间:%d秒前"
,
second
));
EventBus
.
getDefault
().
post
(
msg
);
MsgSender
.
checkAndSend
(
context
,
msg
);
}
else
{
NewService
.
showToast
(
context
,
String
.
format
(
"接收到消息,任务超时,时间:%d秒前"
,
second
));
}
...
...
@@ -123,4 +128,6 @@ public class MyMessageReceiver extends MessageReceiver {
}
}
app/src/main/java/com/xf/weixinclick/utils/Accessibilitys.java
View file @
caf4e2f3
package
com
.
xf
.
weixinclick
.
utils
;
import
android.app.AppOpsManager
;
import
android.content.ComponentName
;
import
android.content.Context
;
import
android.provider.Settings
;
...
...
@@ -83,4 +84,12 @@ public class Accessibilitys {
}
public
static
boolean
hasUsageStatsPermission
(
Context
context
)
{
AppOpsManager
appOps
=
(
AppOpsManager
)
context
.
getSystemService
(
Context
.
APP_OPS_SERVICE
);
int
mode
=
appOps
.
checkOp
(
AppOpsManager
.
OPSTR_GET_USAGE_STATS
,
android
.
os
.
Process
.
myUid
(),
context
.
getPackageName
());
return
mode
==
AppOpsManager
.
MODE_ALLOWED
;
}
}
app/src/main/res/layout/activity_debug.xml
View file @
caf4e2f3
...
...
@@ -18,13 +18,14 @@
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Logcat"
android:layout_margin=
"4dp"
/>
<TextView
android:id=
"@+id/tv_logcat_url"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"
d
f"
android:text=
"
of
f"
android:layout_gravity=
"center_vertical"
/>
...
...
@@ -42,8 +43,15 @@
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"自动开启家粉辅助服务"
android:layout_margin=
"4dp"
/>
<Button
android:id=
"@+id/btn_restart_4g"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"重启网络"
android:layout_margin=
"4dp"
/>
</LinearLayout>
</LinearLayout>
\ No newline at end of file
app/src/main/res/xml/accessibility.xml
View file @
caf4e2f3
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes=
"type
NotificationStateChanged|typeWindowStateChanged
"
android:accessibilityFlags=
"flagDefault"
android:accessibilityEventTypes=
"type
AllMask
"
android:accessibilityFlags=
"flagDefault
|flagReportViewIds|flagRequestEnhancedWebAccessibility
"
android:accessibilityFeedbackType=
"feedbackGeneric"
android:notificationTimeout=
"100"
android:canRetrieveWindowContent=
"true"
...
...
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