Commit 26dd3e83 by zhengli

improved click workflow

parent 9dc3c589
......@@ -2,13 +2,21 @@ package android.app;
import android.content.ContentProviderNative;
import android.content.IContentProvider;
import android.content.Intent;
import android.content.pm.ProviderInfo;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Parcel;
import android.os.ParcelFileDescriptor;
import android.os.Parcelable;
import android.os.RemoteException;
public interface IActivityManager {
public int startActivityAsUser(IApplicationThread caller, String callingPackage, Intent intent,
String resolvedType, IBinder resultTo, String resultWho, int requestCode, int flags,
ProfilerInfo profilerInfo, Bundle options, int userId) throws RemoteException;
public ContentProviderHolder getContentProviderExternal(String name, int userId, IBinder token) throws RemoteException;
public void removeContentProviderExternal(String name, IBinder token) throws RemoteException;
......
package android.app;
public interface IApplicationThread {
}
package android.app;
public class ProfilerInfo {
}
package com.xf.agent;
import android.app.ActivityManagerNative;
import android.app.ActivityThread;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.hardware.input.InputManager;
import android.os.IBinder;
import android.os.Parcelable;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.UserHandle;
import android.text.TextUtils;
import android.view.accessibility.AccessibilityManager;
import com.xf.agent.common.CallRequest;
......@@ -22,6 +26,7 @@ import com.xf.agent.common.server.FLog;
import com.xf.agent.common.server.OpsDataTransfer;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Map;
import java.util.Set;
......@@ -102,9 +107,19 @@ class AgentHandler implements OpsDataTransfer.OnRecvCallback{
TypeCmd typeCmd = ParcelableUtil.unmarshall(callRequest.data, TypeCmd.CREATOR);
if(shell.isClose()){
shell=Shell.getShell();
shell = Shell.getShell();
}
Result execResult = null;
try{
execResult = shell.exec(typeCmd.command);
}catch (Throwable e){
if(e instanceof IllegalStateException){
shell = Shell.getShell();
}
e.printStackTrace();
}
Result execResult = shell.exec(typeCmd.command);
FLog.log(execResult.toString());
......@@ -130,6 +145,29 @@ class AgentHandler implements OpsDataTransfer.OnRecvCallback{
MethodUtils.invokeExactMethod(service,"setDataEnabled",true);
FLog.log("---restart network success --- ");
}else if(callRequest.type == Types.START_ACTIVITY){
Intent intent = ParcelableUtil.unmarshall(callRequest.data, Intent.CREATOR);
getContext().startActivity(intent);
ActivityManagerNative.getDefault().startActivityAsUser(null, null, intent, null,
null, null, 0, 0, null, null, 0);
}else if(callRequest.type == Types.INPUT_EVENT){
String args = new String(callRequest.data);
String[] split = args.trim().split("\\s+");
for (int i = 0; i < split.length; i++) {
split[i] = split[i].trim();
}
FLog.log("input --> "+ Arrays.toString(split));
new Input().run(split);
}else {
System.out.println("unknown type !");
}
......
......@@ -40,6 +40,7 @@ public class Shell {
}
}else {
if(sShell.isClose()){
sShell = null;
try {
sShell = new Shell("sh");
} catch (IOException e) {
......@@ -276,6 +277,7 @@ public class Shell {
if (close) {
throw new IllegalStateException("Unable to add commands to a closed shell");
}
command.setId(generateCommandID());
commandQueue.offer(command);
return command;
......
......@@ -23,4 +23,13 @@ public final class Types {
*/
public static final int RESTART_NETWORK = 4;
/**
* 启动activity
*/
public static final int START_ACTIVITY = 5;
/**
* 事件
*/
public static final int INPUT_EVENT = 6;
}
package com.xf.agent.common.req;
import android.content.Intent;
import com.xf.agent.common.IReq;
import com.xf.agent.common.ParcelableUtil;
import com.xf.agent.common.Types;
public class ReqFactory {
public static IReq startActivity(final Intent intent){
return new IReq() {
@Override
public int getType() {
return Types.START_ACTIVITY;
}
@Override
public byte[] getData() {
return ParcelableUtil.marshall(intent);
}
};
}
public static IReq inputEvent(final String event){
return new IReq() {
@Override
public int getType() {
return Types.INPUT_EVENT;
}
@Override
public byte[] getData() {
return event.getBytes();
}
};
}
}
package com.xf.agent.wrap;
import android.content.Context;
import android.content.Intent;
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;
import com.xf.agent.common.req.ReqFactory;
public class AgentManager {
......@@ -51,6 +53,23 @@ public class AgentManager {
return true;
}
public boolean startActivity(Intent intent) throws Throwable {
checkConnect();
CallResult result = mLocalServerManager.execNew(ReqFactory.startActivity(intent));
if(result!= null && result.throwable != null){
throw result.throwable;
}
return true;
}
public boolean input(String inputEvent) throws Throwable {
checkConnect();
CallResult result = mLocalServerManager.execNew(ReqFactory.inputEvent(inputEvent));
if(result!= null && result.throwable != null){
throw result.throwable;
}
return true;
}
public void destory() {
if (mLocalServerManager != null) {
......
......@@ -22,8 +22,8 @@ android {
applicationId versions.applicationId
minSdkVersion versions.minSdkVersion
targetSdkVersion versions.targetSdkVersion
versionCode 9
versionName "1.5.7"
versionCode 10
versionName "1.5.8"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// externalNativeBuild {
......@@ -85,26 +85,27 @@ dependencies {
implementation 'com.squareup.okhttp3:logging-interceptor:3.6.0'
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.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation "com.android.support:appcompat-v7:$versions.supportLibVersion"
implementation "com.android.support:design:$versions.supportLibVersion"
implementation "com.android.support:recyclerview-v7:${versions.supportLibVersion}"
implementation "com.jakewharton:butterknife:${versions.butterknife}"
annotationProcessor "com.jakewharton:butterknife-compiler:${versions.butterknife}"
implementation 'com.jakewharton:butterknife:8.2.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.2.1'
// implementation 'com.aliyun.ams:alicloud-android-push:3.1.2@aar'
// implementation 'com.aliyun.ams:alicloud-android-utdid:1.1.5.3'
// implementation 'com.aliyun.ams:alicloud-android-ut:5.1.0'
// implementation 'com.aliyun.ams:alicloud-android-third-push:3.0.3@aar'
implementation 'com.aliyun.ams:alicloud-android-push:3.0.11@aar'
implementation 'com.aliyun.ams:alicloud-android-utdid:1.1.5.3'
implementation 'com.aliyun.ams:alicloud-android-ut:5.0.0'
implementation 'com.aliyun.ams:alicloud-android-third-push:3.0.3@aar'
implementation 'com.aliyun.ams:alicloud-android-push:3.1.2'
annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
//annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
annotationProcessor ("com.tinkerpatch.tinker:tinker-android-anno:1.9.2")
implementation("com.tinkerpatch.sdk:tinkerpatch-android-sdk:1.2.2")
annotationProcessor ("com.tinkerpatch.tinker:tinker-android-anno:1.9.6")
implementation("com.tinkerpatch.sdk:tinkerpatch-android-sdk:1.2.6")
implementation "com.android.support:multidex:1.0.3"
}
......
package com.xf.weixinclick;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
......@@ -9,12 +11,15 @@ import android.widget.TextView;
import android.widget.Toast;
import butterknife.BindView;
import butterknife.OnClick;
import com.xf.agent.common.CmdResult;
import com.xf.weixinclick.agent.AgentExecutor;
import com.xf.weixinclick.agent.AutoProcesser;
import com.xf.weixinclick.debugtool.LogcatTools;
import com.xf.weixinclick.http.HttpClientApi;
import java.util.concurrent.Callable;
import rx.Single;
import rx.SingleSubscriber;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
......@@ -80,6 +85,85 @@ public class DebugActivity extends BaseActivity {
}
@OnClick(R.id.btn_start_act)
void onClickStartAct(View view){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName("com.tencent.mm","com.tencent.mm.plugin.webview.ui.tools.WebViewUI");
intent.setData(Uri.parse("https://www.baidu.com"));
// AgentExecutor.startActivity(intent).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);
// }
// });
String url = "http://test.mp-watch.checheng.net/qr-addr?url=http%253A%252F%252Ftest.mp-watch.checheng.net%252Ftemp%252Fspider%252Fgh_4e07defd60d4%252Flogin_qrcode.png?1522133567961?1522722411902?1526285925734";
AgentExecutor.startWechatWeb(url).subscribe(new SingleSubscriber<Boolean>() {
@Override
public void onSuccess(Boolean aBoolean) {
Log.e(TAG, "onSuccess --> "+aBoolean);
}
@Override
public void onError(Throwable error) {
Log.e(TAG, "onError --> ",error);
}
});
// AgentExecutor.exec("am start -n com.tencent.mm/com.tencent.mm.plugin.webview.ui.tools.WebViewUI -a android.intent.action.VIEW -d https://www.baidu.com")
// .subscribe(new SingleSubscriber<CmdResult>() {
// @Override
// public void onSuccess(CmdResult cmdResult) {
// Log.e(TAG, "onSuccess --> "+cmdResult);
// }
//
// @Override
// public void onError(Throwable error) {
// Log.e(TAG, "onError --> ",error);
// }
// });
}
@OnClick(R.id.btn_test_qr)
void btn_test_qr(View view){
HttpClientApi.getQr(new Subscriber<String>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
Log.e(TAG, "onError --> ",e);
}
@Override
public void onNext(String s) {
Log.e(TAG, "onNext --> "+s);
Toast.makeText(getApplicationContext(),"获取成功,请稍等...",Toast.LENGTH_SHORT).show();
}
});
}
private void updateStatus(){
if(LogcatTools.isRunning()){
......
......@@ -95,7 +95,7 @@ public class LoginActivity extends BaseActivity {
new HttpSubscriber<String>() {
@Override
public void onStart() {
execShellCmd("input tap " + 10 + " " + 10);
//execShellCmd("input tap " + 10 + " " + 10);
showProgress("正在请求");
}
......
......@@ -47,6 +47,7 @@ import com.xf.weixinclick.http.HttpClientApi;
import com.xf.weixinclick.http.HttpSubscriber;
import com.xf.weixinclick.receiver.WeChatStatus;
import com.xf.weixinclick.utils.Accessibilitys;
import com.xf.weixinclick.utils.JsonKit;
import com.xf.weixinclick.utils.SP;
import com.xf.weixinclick.view.WaveHelper;
import com.xf.weixinclick.view.WaveView;
......@@ -186,7 +187,7 @@ public class MainActivity extends BaseActivity {
msg.setQr_addr("http://test.mp-watch.checheng.net/qr-addr?url=http%253A%252F%252Ftest.mp-watch.checheng.net%252Ftemp%252Fspider%252Fgh_4e07defd60d4%252Flogin_qrcode.png?1522133567961?1522722411902");
// 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));
msg.setTime_config(JsonKit.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);
MsgSender.checkAndSend(getApplicationContext(),msg);
// startWorkService(MainActivity.this,msg);
......@@ -315,7 +316,7 @@ public class MainActivity extends BaseActivity {
// SP.setParam("divice", d_name);
Log.d("fei",responseBase);
Type type = new TypeToken<ResponseBase<EnableResult>>(){}.getType();
ResponseBase<EnableResult> result = new Gson().fromJson(responseBase,type);
ResponseBase<EnableResult> result = JsonKit.GSON.fromJson(responseBase,type);
if (result == null){
NewService.showToast(MainActivity.this,"失败:解析失败");
}else {
......
......@@ -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.Worker;
import com.xf.weixinclick.core.Worker2;
import com.xf.weixinclick.http.HttpClientApi;
import com.xf.weixinclick.http.HttpSubscriber;
......@@ -69,12 +70,12 @@ public class NewService extends AccessibilityService {
*/
private boolean inBacking = false;
Worker2 mWorker = null;
Worker mWorker = null;
@Override
public void onCreate() {
super.onCreate();
if (mWorker == null){
mWorker = Worker2.getInstance();
mWorker = Worker.getInstance();
}
Log.d(TAG,"NewService onCreate");
}
......@@ -82,19 +83,22 @@ public class NewService extends AccessibilityService {
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
Log.d(TAG, "NewService onAccessibilityEvent");
if (mWorker == null){
mWorker = Worker2.getInstance();
mWorker = Worker.getInstance();
}
mWorker.onAccessibilityEvent(getRootInActiveWindow(),event);
//mWorker.onAccessibilityEvent(getRootInActiveWindow(),event);
mWorker.handleEvent(this,event);
}
@Override
public void onInterrupt () {
Log.d(TAG, "NewService onInterrupt");
if (mWorker != null){
mWorker.onIntercept();
//mWorker.onIntercept();
mWorker.onInterrupt(this);
}
}
......@@ -291,7 +295,6 @@ public class NewService extends AccessibilityService {
if (TextUtils.isEmpty(name)){
return;
}
String device_code = PushServiceFactory.getCloudPushService().getDeviceId();
if (TextUtils.isEmpty(device_code)){
return;
......
package com.xf.weixinclick.agent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Rect;
import android.util.DisplayMetrics;
import android.util.Log;
......@@ -84,6 +85,42 @@ public class AgentExecutor {
}
public static Single<Boolean> inputEvent(final String event){
return Single.fromCallable(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
try {
return agentManager.input(event);
} catch (Throwable throwable) {
throw new Exception(throwable);
}
}
}).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public static Single<Boolean> startWechatWeb(final String url){
return Single.fromCallable(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
try {
String cmd = "am start -n com.tencent.mm/com.tencent.mm.plugin.webview.ui.tools.WebViewUI -a android.intent.action.VIEW -d ";
return agentManager.exeCommand(cmd+url).code == 0;
} catch (Throwable throwable) {
throw new Exception(throwable);
}
}
}).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public static boolean isConnected(){
return agentManager.isRunning();
......
......@@ -45,9 +45,7 @@ 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){
......
......@@ -2,9 +2,11 @@ package com.xf.weixinclick.agent;
import android.graphics.Rect;
import android.support.v4.view.ViewCompat.FocusRealDirection;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import com.xf.agent.common.CmdResult;
import rx.SingleSubscriber;
/**
......@@ -12,9 +14,10 @@ import com.xf.agent.common.CmdResult;
*/
public class MotionRunner {
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 ";
private static final String PREFIX = "";
private static final String KEY_EVENT_CMD = PREFIX+" keyevent ";
private static final String TAP_EVENT_CMD = PREFIX+" tap ";
private static final String SWIPE_EVENT_CMD = PREFIX+" swipe ";
private static MotionRunner sInstance = null;
......@@ -64,10 +67,13 @@ public class MotionRunner {
*/
public boolean tap(int x,int y){
CmdResult cmdResult = AgentExecutor.execNonReturn(TAP_EVENT_CMD + x + " " + y);
return cmdResult!=null && cmdResult.code == 0;
// CmdResult cmdResult = AgentExecutor.execNonReturn(TAP_EVENT_CMD + x + " " + y);
//
// return cmdResult!=null && cmdResult.code == 0;
execInputEvent(TAP_EVENT_CMD + x + " " + y);
return true;
//return AgentExecutor.inputEvent(TAP_EVENT_CMD + x + " " + y).toBlocking().value();
}
/**
......@@ -85,7 +91,7 @@ public class MotionRunner {
.append(y).append(' ')
.append(duration);
AgentExecutor.execNonReturn(cmd.toString());
execInputEvent(cmd.toString());
}
/**
......@@ -103,7 +109,7 @@ public class MotionRunner {
.append(endX).append(' ')
.append(endY).append(' ')
.append(duration);
AgentExecutor.execNonReturn(cmd.toString());
execInputEvent(cmd.toString());
}
/**
......@@ -142,8 +148,23 @@ public class MotionRunner {
}
private void sendKeyEvent(int code){
AgentExecutor.execNonReturn(KEY_EVENT_CMD+code);
execInputEvent(KEY_EVENT_CMD+code);
}
private void execInputEvent(String event){
Log.e("MotionRunner", "execInputEvent --> "+event);
AgentExecutor.inputEvent(event).subscribe(new SingleSubscriber<Boolean>() {
@Override
public void onSuccess(Boolean aBoolean) {
}
@Override
public void onError(Throwable error) {
Log.e("test", "onError --> ",error);
}
});
}
}
......@@ -27,14 +27,27 @@ public class UiHierarchyFinder {
private BasicTreeNode basicTreeNode;
public static Single<UiHierarchyFinder> createFinder(){
return Single.fromCallable(new Callable<UiHierarchyFinder>() {
@Override
public UiHierarchyFinder call() throws Exception {
UiHierarchyFinder finder = new UiHierarchyFinder();
finder.dump();
finder.parseDefault();
return finder;
}
}).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public void dump() {
// CmdResult value = AgentExecutor.exec(CMD).toBlocking().value();
boolean success = Cmder.execShellCmd(CMD);
Log.e(TAG, "dump --> "+success);
CmdResult value = AgentExecutor.exec(CMD).toBlocking().value();
// boolean success = Cmder.execShellCmd(CMD);
Log.e(TAG, "dump --> "+value.message);
SystemClock.sleep(2000);
if(!success){
if(value.code != 0){
throw new RuntimeException("dump ERROR !!!");
}
......@@ -91,31 +104,81 @@ public class UiHierarchyFinder {
List<UiNode> findNodeByText(String text) {
List<UiNode> ret = new ArrayList<>();
findByAttr(basicTreeNode.getChildren(), "text", text, ret);
findByAttr(basicTreeNode.getChildren(), "text", text, ret,true);
return ret;
}
public @NonNull
List<UiNode> findNodeByAttr(String attrKey,String text) {
List<UiNode> ret = new ArrayList<>();
findByAttr(basicTreeNode.getChildren(), attrKey, text, ret,false);
return ret;
}
public @NonNull
List<UiNode> findNodeByAttr(String attrKey,String text,boolean exact) {
List<UiNode> ret = new ArrayList<>();
findByAttr(basicTreeNode.getChildren(), attrKey, text, ret,exact);
return ret;
}
public @NonNull
List<UiNode> findNodeById(String id) {
List<UiNode> ret = new ArrayList<>();
findByAttr(basicTreeNode.getChildren(), "resource-id", id, ret);
findByAttr(basicTreeNode.getChildren(), "resource-id", id, ret,true);
return ret;
}
public List<String> getAttrValues(String key){
List<String> ret = new ArrayList<>();
getValue(basicTreeNode.getChildren(),key,ret);
return ret;
}
private void findByAttr(BasicTreeNode[] nodes, String key, String value, List<UiNode> ret) {
private void getValue(BasicTreeNode[] nodes, String key,List<String> ret){
if (nodes != null) {
for (BasicTreeNode node : nodes) {
if (node.hasChild()) {
getValue(node.getChildren(), key, ret);
} else {
if (node instanceof UiNode) {
String text = ((UiNode) node).getAttribute(key);
if(!TextUtils.isEmpty(text) && text.length() > 1){
ret.add(text.trim());
}
}
}
}
}
}
private void findByAttr(BasicTreeNode[] nodes, String key, String value, List<UiNode> ret,boolean exact) {
if (nodes != null) {
for (BasicTreeNode node : nodes) {
if (node.hasChild()) {
findByAttr(node.getChildren(), key, value, ret);
findByAttr(node.getChildren(), key, value, ret,exact);
} else {
if (node instanceof UiNode) {
String text = ((UiNode) node).getAttribute(key);
if (ret != null && TextUtils.equals(text, value)) {
if (ret != null && !TextUtils.isEmpty(text) ) {
if( (exact && TextUtils.equals(text, value)) || text.contains(value)){
ret.add(((UiNode) node));
}
}
}
}
......@@ -130,9 +193,10 @@ public class UiHierarchyFinder {
printNodes(node.getChildren());
} else {
if (node instanceof UiNode) {
String text = ((UiNode) node).getAttribute("text");
if (!TextUtils.isEmpty(text)) {
Log.e(TAG, "printNodes --> " + text);
String text1 = ((UiNode) node).getAttribute("text");
String text2 = ((UiNode) node).getAttribute("content-desc");
if (!TextUtils.isEmpty(text1) || !TextUtils.isEmpty(text2) ) {
Log.e(TAG, "printNodes -->text: " + text1+" content-desc:"+text2);
}
}
}
......
......@@ -66,6 +66,7 @@ public class EnableAccessibility implements Callable<Boolean> {
Log.e(TAG, "点击第0个节点的位置"+bounds);
MotionRunner.get().clickBack();
Cmder.clickPX(bounds.centerX(),bounds.centerY());
SystemClock.sleep(5000);
//打开了无障碍页面
......@@ -122,8 +123,6 @@ public class EnableAccessibility implements Callable<Boolean> {
//然后返回
Cmder.clickWxBack();
SystemClock.sleep(500);
Cmder.clickWxBack();
......
......@@ -2,6 +2,7 @@ package com.xf.weixinclick.bean;
import com.google.gson.Gson;
import com.xf.weixinclick.utils.JsonKit;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
......@@ -32,15 +33,13 @@ public class ResponseBase<T> {
}
public static ResponseBase fromJson(String json, Class clazz) {
Gson gson = new Gson();
Type objectType = type(ResponseBase.class, clazz);
return gson.fromJson(json, objectType);
return JsonKit.GSON.fromJson(json, objectType);
}
public String toJson(Class<T> clazz) {
Gson gson = new Gson();
Type objectType = type(ResponseBase.class, clazz);
return gson.toJson(this, objectType);
return JsonKit.GSON.toJson(this, objectType);
}
static ParameterizedType type(final Class raw, final Type... args) {
......
package com.xf.weixinclick.core;
import android.graphics.Rect;
import android.text.TextUtils;
import android.util.Log;
import android.view.accessibility.AccessibilityNodeInfo;
import com.xf.weixinclick.agent.MotionRunner;
import java.util.ArrayList;
import java.util.List;
class UIFinderUtils {
private static final String TAG = "UIFinderUtils";
private static Rect nodeRect = new Rect();
static List<AccessibilityNodeInfo> findAccessibilityNodeInfosByDesc(AccessibilityNodeInfo node,String text,boolean exact){
List<AccessibilityNodeInfo> ret = new ArrayList<>();
findByDesc(node,text,exact,ret);
return ret;
}
private static void findByDesc(AccessibilityNodeInfo info,String text,boolean exact,List<AccessibilityNodeInfo> ret){
if (info == null){
return;
}
int childCount = info.getChildCount();
if (childCount > 0) {
for (int i = 0; i < info.getChildCount(); i++) {
findByDesc(info.getChild(i),text,exact,ret);
}
}else {
CharSequence contentDescription = info.getContentDescription();
if(!TextUtils.isEmpty(contentDescription)){
String s = contentDescription.toString();
s=s.trim();
if(exact){
if(TextUtils.equals(text,s)){
ret.add(info);
}
}else {
if(s.contains(text)){
ret.add(info);
}
}
}
}
}
static 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;
}
static 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){
return contains(child,text);
}
}
}else {
CharSequence viewText = nodeInfo.getText();
if(!TextUtils.isEmpty(viewText)){
return viewText.toString().startsWith(text);
}
}
return false;
}
static boolean clickNode(AccessibilityNodeInfo nodeInfo){
nodeRect.setEmpty();
if(nodeInfo != null){
nodeInfo.getBoundsInScreen(nodeRect);
}
if(nodeRect.isEmpty()){
return false;
}
AccessibilityNodeInfo clickableNode = null;
while (clickableNode == null){
if(nodeInfo != null){
if(nodeInfo.isClickable()){
clickableNode = nodeInfo;
}else {
nodeInfo = nodeInfo.getParent();
}
}else {
break;
}
}
boolean ret = false;
if (clickableNode != null){
ret = clickableNode.performAction(AccessibilityNodeInfo.ACTION_CLICK);
}
return ret || MotionRunner.get().tap(nodeRect.centerX(),nodeRect.centerY());
}
static 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;
}
static 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()+" "+node.getContentDescription());
}
Log.e(TAG, "printNodes --> end");
}
}
static 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;
}
static 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 static boolean isEmptyNodes(List<AccessibilityNodeInfo> nodeInfos){
return nodeInfos == null || nodeInfos.isEmpty();
}
}
package com.xf.weixinclick.core;
import android.text.TextUtils;
import android.util.Log;
import com.alibaba.sdk.android.push.noonesdk.PushServiceFactory;
import com.xf.weixinclick.http.HttpClientApi;
import com.xf.weixinclick.utils.SP;
import rx.Subscriber;
class WXLog {
static void log(String msg){
String name = (String) SP.getParam("divice", "");
if (TextUtils.isEmpty(name)){
return;
}
String device_code = PushServiceFactory.getCloudPushService().getDeviceId();
if (TextUtils.isEmpty(device_code)){
return;
}
//不管成功还是失败
HttpClientApi.uploadDeviceLog(device_code,name, msg, new Subscriber<String>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
Log.d("uploadDeviceLog",e.getMessage());
}
@Override
public void onNext(String o) {
Log.d("uploadDeviceLog",o);
}
});
}
}
......@@ -4,8 +4,10 @@ import android.accessibilityservice.AccessibilityService;
import android.support.annotation.Keep;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
import android.widget.Toast;
import com.xf.weixinclick.bean.msg.ReceiverMsg;
import com.xf.weixinclick.core.TaskSession.TaskCallback;
import com.xf.weixinclick.myApplication;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
......@@ -90,7 +92,7 @@ public class Worker {
if (currentTaskSession != null && currentTaskSession.canHandle()) {
currentTaskSession.handleEvent(service, event);
} else {
Log.e(TAG, "handleEvent --> 当前不需要处理"+LINE_SEP);
//Log.e(TAG, "handleEvent --> 当前不需要处理"+LINE_SEP);
}
}
......@@ -136,13 +138,19 @@ public class Worker {
currentTaskSession = new TaskSession(msg, new TaskCallback() {
@Override
public void onSuccess() {
Log.e(TAG, "onSuccess --> "+LINE_SEP);
Toast.makeText(myApplication.getInstence(),"点击成功!",Toast.LENGTH_SHORT).show();
Log.e(TAG, "onSuccess --> 自动点击成功!"+LINE_SEP);
taskOver();
}
@Override
public void onError(String msg) {
Toast.makeText(myApplication.getInstence(),"点击失败:"+msg,Toast.LENGTH_LONG).show();
Log.e(TAG, "onError --> " + msg+LINE_SEP);
taskOver();
......
package com.xf.weixinclick.core.logger;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import java.util.ArrayList;
import java.util.List;
public class LogDB extends SQLiteOpenHelper {
private static final String DB_NAME = "wx_log.db";
private static final String DB_TABLE = "tb_log";
private static final int DB_VER=1;
private static final String COLUMN_LOG_ID = "log_id";
private static final String COLUMN_LOG_TEXT ="log";
private static final String COLUMN_LOG_TIME ="time";
private static final String CREATE_SQL = "CREATE TABLE IF NOT EXISTS "
+DB_TABLE+" ( _id integer primary key autoincrement, "+COLUMN_LOG_ID+" text,"+COLUMN_LOG_TEXT+" text,"
+COLUMN_LOG_TIME +" int);";
public LogDB(Context context) {
super(context, DB_NAME, null, DB_VER);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_SQL);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
public void clear(){
getWritableDatabase().execSQL("DROP TABLE IF EXISTS " + DB_TABLE);
}
public void addLog(LogMsg msg){
try {
ContentValues values=new ContentValues(3);
values.put(COLUMN_LOG_ID,msg.logId);
values.put(COLUMN_LOG_TEXT,msg.log);
values.put(COLUMN_LOG_TIME,msg.time);
getWritableDatabase().insert(DB_TABLE,null,values);
} catch (Exception e) {
e.printStackTrace();
}
}
public List<LogMsg> getLogs(){
List<LogMsg> logMsgs = new ArrayList<>();
Cursor cursor = null;
try {
cursor = getReadableDatabase()
.query(DB_TABLE, new String[]{COLUMN_LOG_ID,COLUMN_LOG_TEXT,COLUMN_LOG_TIME}, null, null, null, null, COLUMN_LOG_TIME + " desc");
while (cursor.moveToNext()){
LogMsg logMsg = new LogMsg();
logMsg.logId = cursor.getString(0);
logMsg.log = cursor.getString(1);
logMsg.time = cursor.getLong(2);
logMsgs.add(logMsg);
}
}catch (Exception e){
e.printStackTrace();
}finally {
if(cursor != null){
cursor.close();
}
}
return logMsgs;
}
}
package com.xf.weixinclick.core.logger;
public class LogMsg {
public String logId;
public String log;
public long time;
}
......@@ -3,6 +3,7 @@ package com.xf.weixinclick.http;
import java.util.Map;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.POST;
import rx.Observable;
......@@ -23,4 +24,8 @@ public interface ClientApi{
Observable<String> devicesEnable(@Body Map<String, String> params);
@POST("devices/log")
Observable<String> devicesLog(@Body Map<String, String> params);
@GET("devices/get-qr")
Observable<String> getQR();
}
......@@ -5,6 +5,7 @@ import android.util.Log;
import com.google.gson.Gson;
import com.xf.weixinclick.http.stringfactory.StringConverterFactory;
import com.xf.weixinclick.utils.JsonKit;
import com.xf.weixinclick.utils.SP;
import com.xf.weixinclick.BuildConfig;
import com.xf.weixinclick.myApplication;
......@@ -33,14 +34,14 @@ import rx.schedulers.Schedulers;
* Email:liyawei@checheng.com
*/
public class HttpClientApi {
final static int DEFAULT_TIMEOUT = 30;
private final static int DEFAULT_TIMEOUT = 30;
final static Scheduler io = Schedulers.io();
final static Scheduler main = AndroidSchedulers.mainThread();
private final static Scheduler io = Schedulers.io();
private final static Scheduler main = AndroidSchedulers.mainThread();
static String TEST_URL = "http://test.mp-watch.checheng.net/api/";//"http://118.178.135.158:8080/api/";
static String REAL_URL = "http://mp-watch.checheng.net/api/";
static String BASE_URL;
private static String TEST_URL = "http://test.mp-watch.checheng.net/api/";//"http://118.178.135.158:8080/api/";
private static String REAL_URL = "http://mp-watch.checheng.net/api/";
private static String BASE_URL;
public static String getUrl() {
initBaseUrl();
......@@ -60,8 +61,8 @@ public class HttpClientApi {
}
}
static HttpClientApi httpClient = new HttpClientApi();
static Retrofit retrofit;
private static HttpClientApi httpClient = new HttpClientApi();
private static Retrofit retrofit;
private HttpClientApi() {
initBaseUrl();
......@@ -76,7 +77,7 @@ public class HttpClientApi {
String content = response.body().string();
//存入Session
if (response.code() != 200) {
ResponseBase responseBase = new Gson().fromJson(content, ResponseBase.class);
ResponseBase responseBase = JsonKit.GSON.fromJson(content, ResponseBase.class);
myApplication.showToast(responseBase.getMessage() + " "+response.code());
if (response.code() == 401) {
myApplication.startLogin();
......@@ -196,4 +197,22 @@ public class HttpClientApi {
.observeOn(io)
.subscribe(subscriber);
}
public static void uploadDeviceLog(String device_code, String name,String message, Subscriber<String> subscriber) {
Map<String, String> map = new HashMap<>();
map.put("code", device_code);
map.put("name", name);
map.put("msg",message);
getInstance().devicesLog(map)
.subscribeOn(io)
.observeOn(io)
.subscribe(subscriber);
}
public static void getQr(Subscriber<String> subscriber){
getInstance().getQR().subscribeOn(io)
.observeOn(main)
.subscribe(subscriber);;
}
}
......@@ -19,6 +19,7 @@ import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonWriter;
import com.xf.weixinclick.utils.JsonKit;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
......@@ -42,7 +43,7 @@ final class GsonRequestBodyConverter<T> implements Converter<T, RequestBody> {
@Override public RequestBody convert(T value) throws IOException {
Buffer buffer = new Buffer();
Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
JsonWriter jsonWriter = new Gson().newJsonWriter(writer);
JsonWriter jsonWriter = JsonKit.GSON.newJsonWriter(writer);
adapter.write(jsonWriter, value);
jsonWriter.close();
return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
......
......@@ -19,6 +19,7 @@ import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.reflect.TypeToken;
import com.xf.weixinclick.utils.JsonKit;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
......@@ -57,7 +58,7 @@ public final class StringConverterFactory extends Converter.Factory {
@Override
public Converter<?, RequestBody> requestBodyConverter(Type type,
Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
TypeAdapter<?> adapter = new Gson().getAdapter(TypeToken.get(type));
TypeAdapter<?> adapter = JsonKit.GSON.getAdapter(TypeToken.get(type));
return new GsonRequestBodyConverter<>(adapter);
}
}
......@@ -19,6 +19,7 @@ import com.xf.weixinclick.core.MsgSender;
import com.xf.weixinclick.myApplication;
import com.xf.weixinclick.utils.Accessibilitys;
import com.xf.weixinclick.utils.JsonKit;
import org.greenrobot.eventbus.EventBus;
import java.text.SimpleDateFormat;
......@@ -66,7 +67,7 @@ public class MyMessageReceiver extends MessageReceiver {
new Thread(new Runnable() {
@Override
public void run() {
ReceiverMsg msg = new Gson().fromJson(cPushMessage.getContent(), ReceiverMsg.class);
ReceiverMsg msg = JsonKit.GSON.fromJson(cPushMessage.getContent(), ReceiverMsg.class);
long second = System.currentTimeMillis()/1000 - msg.getPushed_at() ;
if (second < 15*60){
......
package com.xf.weixinclick.utils;
import com.google.gson.Gson;
public class JsonKit {
public static final Gson GSON = new Gson();
}
......@@ -52,6 +52,29 @@
android:text="重启网络"
android:layout_margin="4dp"
/>
<Button
android:id="@+id/btn_start_act"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="打开微信web"
android:layout_margin="4dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="@+id/btn_test_qr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="手动获取登录消息"
/>
</LinearLayout>
</LinearLayout>
\ No newline at end of file
......@@ -4,7 +4,7 @@ import java.util.regex.Pattern
def bakPath = file("${buildDir}/bakApk/")
def baseInfo = "app-1.5.5-0409-13-15-18"
def appVersionName="1.5.5"
def appVersionName="1.5.8"
def variantName = "release"
tinkerpatchSupport {
......
......@@ -9,11 +9,10 @@ buildscript {
'buildToolsVersion' : '27.0.3',
'minSdkVersion' : 21,
'targetSdkVersion' : 27,
'supportLibVersion' : '27.1.0',
'supportLibVersion' : '27.1.1',
'applicationId':'com.xf.weixinclick',
'butterknife' : '8.2.1',
'retrofit' : '2.3.0',
'kotlinVersion' : '1.2.31'
'retrofit' : '2.3.0'
]
......@@ -25,7 +24,7 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath("com.tinkerpatch.sdk:tinkerpatch-gradle-plugin:1.2.2"){ changing = true }
classpath("com.tinkerpatch.sdk:tinkerpatch-gradle-plugin:1.2.6"){ changing = true }
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment