Commit 972d8d8b by jeffrey

1.3 逻辑优化

parent 09ff24fa
...@@ -22,8 +22,8 @@ android { ...@@ -22,8 +22,8 @@ android {
applicationId "com.xf.weixinclick" applicationId "com.xf.weixinclick"
minSdkVersion 16 minSdkVersion 16
targetSdkVersion 25 targetSdkVersion 25
versionCode 3 versionCode 4
versionName "1.2" versionName "1.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild { externalNativeBuild {
cmake { cmake {
......
...@@ -66,6 +66,7 @@ ...@@ -66,6 +66,7 @@
android:name=".NewService" android:name=".NewService"
android:enabled="true" android:enabled="true"
android:exported="true" android:exported="true"
android:process=":remote"
android:label="@string/app_name" android:label="@string/app_name"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"> android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter> <intent-filter>
......
...@@ -61,7 +61,7 @@ public class MainActivity extends BaseActivity { ...@@ -61,7 +61,7 @@ public class MainActivity extends BaseActivity {
@Override @Override
void initAction() { void initAction() {
Log.d("fei","测试下魅族log");
HeartBeatAction.get().start(); HeartBeatAction.get().start();
...@@ -119,14 +119,14 @@ public class MainActivity extends BaseActivity { ...@@ -119,14 +119,14 @@ public class MainActivity extends BaseActivity {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
// WeChatStatus.receiverMsg(); // WeChatStatus.receiverMsg();
Intent intent = new Intent(); // Intent intent = new Intent();
//// 报名该有activity // //// 报名该有activity
ComponentName cmp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI"); // ComponentName cmp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI");
intent.setAction(Intent.ACTION_MAIN); // intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER); // intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setComponent(cmp); // intent.setComponent(cmp);
startActivity(intent); // startActivity(intent);
new Thread(new Runnable() { new Thread(new Runnable() {
...@@ -142,7 +142,9 @@ public class MainActivity extends BaseActivity { ...@@ -142,7 +142,9 @@ public class MainActivity extends BaseActivity {
// msg.setQr_addr("https://weapp-dev.wangjia.com/qr.jpg?dd=1"); // msg.setQr_addr("https://weapp-dev.wangjia.com/qr.jpg?dd=1");
msg.setUnique_id("1111111111111"); 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(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);
startWorkService(MainActivity.this,msg);
} }
}).start(); }).start();
...@@ -151,6 +153,13 @@ public class MainActivity extends BaseActivity { ...@@ -151,6 +153,13 @@ public class MainActivity extends BaseActivity {
} }
public static void startWorkService(Context context,ReceiverMsg msg){
Intent intent = new Intent(context,NewService.class);
intent.putExtra(NewService.PARAMS_MSG,msg);
context.startService(intent);
}
public static String getLocalVersionName(Context ctx) { public static String getLocalVersionName(Context ctx) {
String localVersion = ""; String localVersion = "";
try { try {
......
...@@ -2,10 +2,12 @@ package com.xf.weixinclick; ...@@ -2,10 +2,12 @@ package com.xf.weixinclick;
import android.accessibilityservice.AccessibilityService; import android.accessibilityservice.AccessibilityService;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.KeyguardManager;
import android.content.ClipData; import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils; import android.text.TextUtils;
...@@ -21,9 +23,7 @@ import com.xf.weixinclick.bean.msg.ReceiverMsg; ...@@ -21,9 +23,7 @@ import com.xf.weixinclick.bean.msg.ReceiverMsg;
import com.xf.weixinclick.http.HttpClientApi; import com.xf.weixinclick.http.HttpClientApi;
import com.xf.weixinclick.http.HttpSubscriber; import com.xf.weixinclick.http.HttpSubscriber;
import com.xf.weixinclick.receiver.WeChatStatus; import com.xf.weixinclick.receiver.WeChatStatus;
import com.xf.weixinclick.utils.NotificationUtils;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
...@@ -42,7 +42,6 @@ import static com.xf.weixinclick.receiver.WeChatStatus.needClick; ...@@ -42,7 +42,6 @@ import static com.xf.weixinclick.receiver.WeChatStatus.needClick;
import static com.xf.weixinclick.receiver.WeChatStatus.needClick2; import static com.xf.weixinclick.receiver.WeChatStatus.needClick2;
import static com.xf.weixinclick.receiver.WeChatStatus.needClick3; import static com.xf.weixinclick.receiver.WeChatStatus.needClick3;
import static com.xf.weixinclick.receiver.WeChatStatus.needClick4; import static com.xf.weixinclick.receiver.WeChatStatus.needClick4;
import static com.xf.weixinclick.receiver.WeChatStatus.status;
/** /**
* 创建日期:2018/2/24 on 15:44 * 创建日期:2018/2/24 on 15:44
...@@ -51,207 +50,313 @@ import static com.xf.weixinclick.receiver.WeChatStatus.status; ...@@ -51,207 +50,313 @@ import static com.xf.weixinclick.receiver.WeChatStatus.status;
*/ */
public class NewService extends AccessibilityService { public class NewService extends AccessibilityService {
private static final String TAG = NewService.class.getSimpleName();
private final String WeChatUi = "com.tencent.mm.ui.LauncherUI"; private final String WeChatUi = "com.tencent.mm.ui.LauncherUI";
private final String WeChatWebView = "com.tencent.mm.plugin.webview.ui.tools.WebViewUI"; private final String WeChatWebView = "com.tencent.mm.plugin.webview.ui.tools.WebViewUI";
private final String WeChatAlert = "com.tencent.mm.ui.base.m"; private final String WeChatAlert = "com.tencent.mm.ui.base.m";
private final static String MM_PNAME = "com.tencent.mm"; private final static String MM_PNAME = "com.tencent.mm";
public static final String PARAMS_MSG = "msg";
int isSuccess = 1; int isSuccess = 1;
int isFalse = 0; int isFalse = 0;
boolean locked = false;
private KeyguardManager.KeyguardLock kl;
private String Url = "https://weapp-dev.wangjia.com/qr.jpg?dd=1"; private String Url = "https://weapp-dev.wangjia.com/qr.jpg?dd=1";
private String message_id = "123"; private String message_id = "123";
private DelayBean delayBean; private DelayBean delayBean;
private ReceiverMsg taskMsg;
/**
* 当前任务的步骤,完成一步+1
*/
private int step;
long times = 0; long times = 0;
int tempX = 50;
int tempY = 50;
boolean clickDone = false; boolean clickDone = false;
@Subscribe
public void receiverMsg(final ReceiverMsg msg) {
Log.d("fei ", "receiverMsg");
if (!isHome()){
Log.d("fei ", "当前页不是首页");
showToast(getApplicationContext(),"当前页不是首页");
turnBack(isFalse,2);
return;
}
//收到消息后 打开文件传输助手
Log.d("fei ", "点击文件传输助手");
delayBean = msg.getTime_config();
if (delayBean == null){
Log.d("fei ", "delayBean 是空");
}
execShellCmd("input tap 220 200");
//发送触发的消息给service,难道微信没有触发?
delayDeal(delayBean.getAfter_open_weixin_file_helper_delay(), new IDelayMethord() {
@Override
public void delayMethord() {
clickDone = true;
// showToast(getApplicationContext(),"消息的 unique_id 是 " + msg.getUnique_id());
Log.d("fei ", "receiverMsg里面触发下页面消息 unique_id " + msg.getUnique_id()); @Override
WeChatStatus.receiverMsg(); public int onStartCommand(Intent intent, int flags, int startId) {
Url = msg.getQr_addr();
Log.d("fei ", "receiverMsg里面触发下页面消息 Url " + Url);
message_id = msg.getUnique_id();
AccessibilityEvent accessibilityEvent = AccessibilityEvent.obtain(32);
accessibilityEvent.setClassName(WeChatUi);
onAccessibilityEvent(accessibilityEvent);
}
});
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;
// delayDeal(500, new MyAccessibilityService.IDelayMethord() { awakeWechat(getApplicationContext());
// @Override }
// public void delayMethord() {
// execShellCmd("input tap 150 200");
// }
// });
// delayDeal(2000, new MyAccessibilityService.IDelayMethord() {
// @Override
// public void delayMethord() {
// WeChatStatus.receiverMsg();
// Url = msg.getQr_addr();
// message_id = msg.getUnique_id();
// AccessibilityEvent accessibilityEvent = AccessibilityEvent.obtain(32);
// accessibilityEvent.setClassName(WeChatUi);
// onAccessibilityEvent(accessibilityEvent);
// }
// });
//当service因为低内存被杀掉后,等内存足够时可以重启
return START_STICKY;
} }
// @Subscribe
// public void receiverMsg(final ReceiverMsg msg) {
// Log.d("fei ", "receiverMsg");
// if (!isHome()){
// Log.d("fei ", "当前页不是首页");
// showToast(getApplicationContext(),"当前页不是首页");
// turnBack(isFalse,2);
// return;
// }
// //收到消息后 打开文件传输助手
// Log.d("fei ", "点击文件传输助手");
// delayBean = msg.getTime_config();
// if (delayBean == null){
// Log.d("fei ", "delayBean 是空");
// }
//
// execShellCmd("input tap 220 200");
//
//
//
// //发送触发的消息给service,难道微信没有触发?
// delayDeal(delayBean.getAfter_open_weixin_file_helper_delay(), new IDelayMethord() {
// @Override
// public void delayMethord() {
//
// clickDone = true;
//// showToast(getApplicationContext(),"消息的 unique_id 是 " + msg.getUnique_id());
//
// Log.d("fei ", "receiverMsg里面触发下页面消息 unique_id " + msg.getUnique_id());
// WeChatStatus.receiverMsg();
// Url = msg.getQr_addr();
// Log.d("fei ", "receiverMsg里面触发下页面消息 Url " + Url);
// message_id = msg.getUnique_id();
// AccessibilityEvent accessibilityEvent = AccessibilityEvent.obtain(32);
// accessibilityEvent.setClassName(WeChatUi);
// onAccessibilityEvent(accessibilityEvent);
// }
// });
//
//
// }
@Override @Override
public void onAccessibilityEvent(AccessibilityEvent event) { public void onAccessibilityEvent(AccessibilityEvent event) {
Log.d("fei", "NewService onAccessibilityEvent"); Log.d("fei", "NewService onAccessibilityEvent");
if (!EventBus.getDefault().isRegistered(this)) {
EventBus.getDefault().register(this);
}
int eventType = event.getEventType(); int eventType = event.getEventType();
String className = event.getClassName().toString(); String className = event.getClassName().toString();
Log.d(TAG, "get event = " + eventType + " class " + className + " step " + step);
if (!className.contains(MM_PNAME)) { if (!className.contains(MM_PNAME)) {
return; return;
} }
Log.d("maptrix ", "get event = " + eventType + " class " + className);
Log.d(" maptrix", "status " + status[0] + status[1] + status[2] + status[3]); if (taskMsg == null){
if (eventType == 32 && className.contains("WebviewScanImageActivity")) { Log.d(TAG, "NewService but taskMsg is null");
return; return;
} }
if (WeChatStatus.isClose()) { // if (eventType == 32 && className.contains("WebviewScanImageActivity")) {
return; // return;
// }
// if (WeChatStatus.isClose()) {
// return;
// }
if (step == 0&& !findNodeByTexts(this,"微信","通讯录","发现","我")){
Log.d(TAG, "是在第一步,但不是在首页,重新进入再来");
resetAll();
showToast(getApplicationContext(),"当前页不是首页");
turnBack(isFalse,2);
} }
switch (eventType) { if (step == 0 && findNodeByTexts(this,"微信","通讯录","发现","我")){
//点击事件 //点击文件传输助手的位置
case 32: //最好还是找到文字然后点击位置
switch (className) { //没办法 首页打印出来的是通讯录的布局,所以坐标是错误的
case WeChatUi: execShellCmd("input tap 220 200");
if (clickDone){ // clickHomeWJCSZS();
Log.d("fei ", "点击过了文件传输助手 ,准备下一步"); step++;
}
delayDeal(1000, new IDelayMethord() {
@Override if (step == 1 ){
public void delayMethord() { printAllNode();
if (WeChatStatus.status[0] ) { }
Log.d("fei ", "进入文件传输详情页面"); // && findNodeByTexts(this,"文件传输助手")
if (fill()) { if (step == 1 ){
step++;
//填充完了 有时候发送不出现,那就再点击下文字 ,点完了要变下空白区域 让输入框消失 Log.d(TAG, "文件传输详情页面_填充_准备");
execShellCmd("input tap " + dip2px(130) + " " + dip2px(600)); delayDeal(5000, new IDelayMethord() {
execShellCmd("input tap " + dip2px(10) + " " + dip2px(200)); @Override
Log.d("fei ", "文件传输详情页面_填充成功准备发送"); public void delayMethord() {
delayDeal(delayBean.getAfter_paste_message_delay(), new IDelayMethord() { Log.d(TAG, "文件传输详情页面_填充");
@Override printAllNode();
public void delayMethord() {
Log.d("fei ", "文件传输详情页面_发送"); if(fill()){
Log.d(TAG, "文件传输详情页面_填充_完成");
send(); send();
} clickMsg(getRootInActiveWindow());
});
delayDeal(delayBean.getAfter_paste_message_delay()+delayBean.getAfter_send_message_delay()+2000, new IDelayMethord() { step++;
@Override }else{
public void delayMethord() { Log.d(TAG, "文件传输详情页面_填充_失败");
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", "点击识别二维码");
pressImg();
}
});
}
break;
default:
break;
}
break;
default:
break;
} }
});
}
// 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++;
// }
if (step == 3 && 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 == 5 && className.equals(WeChatAlert)){
Log.d(TAG, "开始点击确认二维码");
step++;
delayDeal(delayBean.getLong_press_qrcode_delay(), new IDelayMethord() {
@Override
public void delayMethord() {
pressRecognitionImg();
step++;
}
});
}
if (step == 7 && className.equals(WeChatWebView)){
Log.d(TAG, "开始点击确认登录");
pressSure();
resetAll();
}
// 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;
// }
} }
@Override @Override
public void onInterrupt () { public void onInterrupt () {
Log.d("fei", "NewService onInterrupt"); Log.d("fei", "NewService onInterrupt");
if (EventBus.getDefault().isRegistered(this)) { // if (EventBus.getDefault().isRegistered(this)) {
EventBus.getDefault().unregister(this); // EventBus.getDefault().unregister(this);
} // }
} }
...@@ -273,7 +378,7 @@ public class NewService extends AccessibilityService { ...@@ -273,7 +378,7 @@ public class NewService extends AccessibilityService {
/** /**
* 点击识别图中二维码 * 点击识别图中二维码
*/ */
void pressImg() { void pressRecognitionImg() {
List<AccessibilityNodeInfo> allData = getRootInActiveWindow() List<AccessibilityNodeInfo> allData = getRootInActiveWindow()
.findAccessibilityNodeInfosByText(needClick); .findAccessibilityNodeInfosByText(needClick);
...@@ -377,6 +482,41 @@ public class NewService extends AccessibilityService { ...@@ -377,6 +482,41 @@ 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() { void isPassTime() {
...@@ -668,38 +808,95 @@ public class NewService extends AccessibilityService { ...@@ -668,38 +808,95 @@ public class NewService extends AccessibilityService {
} }
} }
public boolean isHome(){ // public boolean isHome(){
int count = getRootInActiveWindow().getChildCount(); // int count = getRootInActiveWindow().getChildCount();
for (int i = 0 ; i < count ; i++){ // for (int i = 0 ; i < count ; i++){
AccessibilityNodeInfo nodeInfo = getRootInActiveWindow().getChild(i); // AccessibilityNodeInfo nodeInfo = getRootInActiveWindow().getChild(i);
boolean isFind = recycle(nodeInfo,"通讯录"); // boolean isFind = recycle(nodeInfo,"通讯录");
if (isFind){ // if (isFind){
return true; // return true;
} // }
} // }
return false; // return false;
} // }
public boolean recycle(AccessibilityNodeInfo info,String searchText) { public AccessibilityNodeInfo recycle(AccessibilityNodeInfo info,String searchText) {
if (info.getChildCount() == 0) { if (info.getChildCount() == 0) {
// Log.i("fei ", "child widget----------------------------" + info.getClassName()); // Log.i("fei ", "child widget----------------------------" + info.getClassName());
// Log.i("fei ", "showDialog:" + info.canOpenPopup()); // Log.i("fei ", "showDialog:" + info.canOpenPopup());
// Log.i("fei ", "Text:" + info.getText()); // Log.i("fei ", "Text:" + info.getText());
// Log.i("fei ", "windowId:" + info.getWindowId()); // Log.i("fei ", "windowId:" + info.getWindowId());
if (!TextUtils.isEmpty(info.getText()) && searchText.equals(info.getText())){ if (!TextUtils.isEmpty(info.getText()) && searchText.equals(info.getText())){
return true; return info;
} }
} else { } else {
for (int i = 0; i < info.getChildCount(); i++) { for (int i = 0; i < info.getChildCount(); i++) {
if(info.getChild(i)!=null){ if(info.getChild(i)!=null){
boolean result = recycle(info.getChild(i),searchText); AccessibilityNodeInfo node = recycle(info.getChild(i),searchText);
if (result){ if (node != null){
return true; return node;
} }
} }
} }
} }
return false; return null;
}
public void printAllNode(){
AccessibilityNodeInfo root = getRootInActiveWindow();
if (root == null){
return;
}
int count = root.getChildCount();
for (int i = 0 ; i < count ; i++){
AccessibilityNodeInfo nodeInfo = root.getChild(i);
recycle(nodeInfo);
}
}
public void recycle(AccessibilityNodeInfo info) {
if (info == null){
return;
}
if (info.getChildCount() == 0) {
Log.i(TAG, "child widget----------------------------" + info.getClassName());
Log.i(TAG, "Text:" + info.getText());
Log.i(TAG, "windowId:" + info.getWindowId());
} else {
for (int i = 0; i < info.getChildCount(); i++) {
recycle(info.getChild(i));
}
}
}
public static boolean findNodeByTexts(AccessibilityService service,String ... text){
boolean isFind = true;
for (String oneText : text){
boolean oneFind = findNodeByText(service,oneText);
if (!oneFind){
isFind = false;
Log.d(TAG,"findNodeByTexts not find " + oneText );
break;
}
}
return isFind;
}
public static boolean findNodeByText(AccessibilityService service,String text){
AccessibilityNodeInfo nodeInfo = service.getRootInActiveWindow();
if (service == null || nodeInfo == null){
return false;
}
List<AccessibilityNodeInfo> node = nodeInfo.findAccessibilityNodeInfosByText(text);
if (node == null || node.size() == 0){
return false;
}
return true;
} }
public static void showToast(final Context context, final String msg){ public static void showToast(final Context context, final String msg){
...@@ -718,4 +915,18 @@ public class NewService extends AccessibilityService { ...@@ -718,4 +915,18 @@ public class NewService extends AccessibilityService {
} }
}); });
} }
public static void awakeWechat(Context context){
Intent intent = new Intent(Intent.ACTION_MAIN);
//启动第三方重点是加这个
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
ComponentName cn = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI");
intent.setComponent(cn);
if (context.getPackageManager().resolveActivity(intent, PackageManager.MATCH_ALL)== null){
showToast(context,"未安装微信");
}else {
context.startActivity(intent);
}
}
} }
package com.xf.weixinclick.bean; package com.xf.weixinclick.bean;
import java.io.Serializable;
/** /**
* 创建日期:2018/3/6 on 15:20 * 创建日期:2018/3/6 on 15:20
* 描述: * 描述:
...@@ -25,7 +27,7 @@ package com.xf.weixinclick.bean; ...@@ -25,7 +27,7 @@ package com.xf.weixinclick.bean;
//// 点击确定登录按钮延迟,单位毫秒,备注:等待加载公众号登录成功界面,此时发送回调通知公众号登录成功 //// 点击确定登录按钮延迟,单位毫秒,备注:等待加载公众号登录成功界面,此时发送回调通知公众号登录成功
// 'after_click_confirm_button_delay' => 3000, // 'after_click_confirm_button_delay' => 3000,
public class DelayBean { public class DelayBean implements Serializable {
int qrcode_timeout; int qrcode_timeout;
int after_open_weixin_index_delay; int after_open_weixin_index_delay;
int after_open_weixin_file_helper_delay; int after_open_weixin_file_helper_delay;
......
...@@ -11,6 +11,7 @@ import android.util.Log; ...@@ -11,6 +11,7 @@ import android.util.Log;
import com.alibaba.sdk.android.push.MessageReceiver; import com.alibaba.sdk.android.push.MessageReceiver;
import com.alibaba.sdk.android.push.notification.CPushMessage; import com.alibaba.sdk.android.push.notification.CPushMessage;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.xf.weixinclick.MainActivity;
import com.xf.weixinclick.NewService; import com.xf.weixinclick.NewService;
import com.xf.weixinclick.R; import com.xf.weixinclick.R;
import com.xf.weixinclick.bean.msg.ReceiverMsg; import com.xf.weixinclick.bean.msg.ReceiverMsg;
...@@ -47,39 +48,34 @@ public class MyMessageReceiver extends MessageReceiver { ...@@ -47,39 +48,34 @@ public class MyMessageReceiver extends MessageReceiver {
@Override @Override
public void onMessage(final Context context, final CPushMessage cPushMessage) { public void onMessage(final Context context, final CPushMessage cPushMessage) {
Log.e("MyMessageReceiver", "onMessageaaa "+cPushMessage.getAppId()); Log.e("MyMessageReceiver", "onMessageaaa " + cPushMessage.getAppId());
Log.e("MyMessageReceiver", "onMessageaaa "+cPushMessage.getTraceInfo().toString()); Log.e("MyMessageReceiver", "onMessageaaa " + cPushMessage.getTraceInfo().toString());
Log.e("MyMessageReceiver", "onMessage, messageId: " + cPushMessage.getMessageId() Log.e("MyMessageReceiver", "onMessage, messageId: " + cPushMessage.getMessageId()
+ ", title: " + cPushMessage.getTitle() + ", title: " + cPushMessage.getTitle()
+ ", content:" + cPushMessage.getContent()); + ", content:" + cPushMessage.getContent());
Intent intent = new Intent(); // Intent intent = new Intent();
ComponentName cmp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI");// 报名该有activity // ComponentName cmp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI");// 报名该有activity
intent.setAction(Intent.ACTION_MAIN); // intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER); // intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setComponent(cmp); // intent.setComponent(cmp);
myApplication.getInstence().startActivity(intent); // myApplication.getInstence().startActivity(intent);
new Thread(new Runnable() { ReceiverMsg msg = new Gson().fromJson(cPushMessage.getContent(), ReceiverMsg.class);
@Override
public void run() { long second = System.currentTimeMillis() / 1000 - msg.getPushed_at();
ReceiverMsg msg = new Gson().fromJson(cPushMessage.getContent(), ReceiverMsg.class); if (second < msg.getTime_config().getQrcode_timeout()) {
try {
long second = System.currentTimeMillis()/1000 - msg.getPushed_at() ; Thread.sleep(msg.getTime_config().getAfter_open_weixin_index_delay());
if (second < msg.getTime_config().getQrcode_timeout()){ } catch (InterruptedException e) {
try { e.printStackTrace();
Thread.sleep(msg.getTime_config().getAfter_open_weixin_index_delay());
} catch (InterruptedException e) {
e.printStackTrace();
}
NewService.showToast(context,String.format("接收到消息,时间:%d秒前",second));
EventBus.getDefault().post(msg);
}else {
NewService.showToast(context,String.format("接收到消息,任务超时,时间:%d秒前",second));
}
NewService.showToast(context,String.format("origin_id:%s,unique_id:%s",msg.getOrigin_id(),msg.getUnique_id()));
} }
}).start(); NewService.showToast(context, String.format("接收到消息,时间:%d秒前", second));
// EventBus.getDefault().post(msg);
MainActivity.startWorkService(context, msg);
} else {
NewService.showToast(context, String.format("接收到消息,任务超时,时间:%d秒前", second));
}
NewService.showToast(context, String.format("origin_id:%s,unique_id:%s", msg.getOrigin_id(), msg.getUnique_id()));
// showNotify(context); // showNotify(context);
...@@ -109,7 +105,7 @@ public class MyMessageReceiver extends MessageReceiver { ...@@ -109,7 +105,7 @@ public class MyMessageReceiver extends MessageReceiver {
} }
private void showNotify(Context context){ private void showNotify(Context context) {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
String strTime = df.format(calendar.getTime()); String strTime = df.format(calendar.getTime());
...@@ -117,10 +113,10 @@ public class MyMessageReceiver extends MessageReceiver { ...@@ -117,10 +113,10 @@ public class MyMessageReceiver extends MessageReceiver {
Notification notification = new NotificationCompat.Builder(context) Notification notification = new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher) .setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("微信click 有新消息") .setContentTitle("微信click 有新消息")
.setContentText( "时间 " + strTime ) .setContentText("时间 " + strTime)
.build(); .build();
NotificationManager notifyManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager notifyManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notifyManager.notify(1,notification); notifyManager.notify(1, notification);
} }
......
package com.xf.weixinclick.utils;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import com.xf.weixinclick.MainActivity;
import com.xf.weixinclick.R;
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
/**
* 创建日期:2018/3/28 on 9:52
* 描述:
* 作者:Li
*/
public class NotificationUtils {
public static final int FOREGROUND_NOTIFICATION_ID = 88;
public static void foreground(Context context, Service service){
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
//设置小图标
.setSmallIcon(R.mipmap.ic_launcher)
//设置通知标题
.setContentTitle("我正在运行")
.setContentIntent(PendingIntent.getActivity(context,1,new Intent(context, MainActivity.class),FLAG_UPDATE_CURRENT))
//设置通知内容
.setContentText("有这个说明正在运行");
Notification notification = builder.build();
service.startForeground(FOREGROUND_NOTIFICATION_ID,notification);
}
}
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