Skip to content

Commit

Permalink
Merge remote-tracking branch 'stream/stable' into feature/unpack
Browse files Browse the repository at this point in the history
  • Loading branch information
larryxiao625 committed Jan 27, 2018
2 parents b271d1d + bea1e4d commit cdfef11
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
8 changes: 0 additions & 8 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,13 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/animated-vector-drawable/25.1.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/25.1.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-compat/25.1.0/jars" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@
import android.content.ComponentName;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Path;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Parcelable;
import android.graphics.Path;
import android.preference.PreferenceManager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.util.DisplayMetrics;
import xyz.monkeytong.hongbao.utils.HongbaoSignature;
import xyz.monkeytong.hongbao.utils.PowerUtil;

import java.util.List;
import java.util.Random;

import xyz.monkeytong.hongbao.utils.HongbaoSignature;
import xyz.monkeytong.hongbao.utils.PowerUtil;

public class HongbaoService extends AccessibilityService implements SharedPreferences.OnSharedPreferenceChangeListener {
private static final String WECHAT_DETAILS_EN = "Details";
Expand Down Expand Up @@ -55,15 +57,18 @@ public void onAccessibilityEvent(AccessibilityEvent event) {
if (sharedPreferences == null) return;

setCurrentActivityName(event);
Log.i("tone", "onAccessibilityEvent:检测到.. ");

/* 检测通知消息 */
if (!mMutex) {
Log.i("tone", "onAccessibilityEvent:检测到-》通知 ");
if (sharedPreferences.getBoolean("pref_watch_notification", false) && watchNotifications(event)) return;
if (sharedPreferences.getBoolean("pref_watch_list", false) && watchList(event)) return;
mListMutex = false;
}

if (!mChatMutex) {
Log.i("tone", "onAccessibilityEvent:检测到-》聊天 ");
mChatMutex = true;
if (sharedPreferences.getBoolean("pref_watch_chat", false)) watchChat(event);
mChatMutex = false;
Expand All @@ -79,18 +84,26 @@ private void watchChat(AccessibilityEvent event) {
mUnpackNode = null;

checkNodeInfo(event.getEventType());

/* 如果已经接收到红包并且还没有戳开 */
Log.i("tone", "watchChat: 查找控件1-" + mLuckyMoneyReceived + mLuckyMoneyPicked + mReceiveNode);
//Log.i("tone", "watchChat: 查找控件");
if (mLuckyMoneyReceived && !mLuckyMoneyPicked && (mReceiveNode != null)) {
mMutex = true;

Log.i("tone", "watchChat: 准备戳开红包");
mReceiveNode.getParent().performAction(AccessibilityNodeInfo.ACTION_CLICK);
mLuckyMoneyReceived = false;
mLuckyMoneyPicked = true;
}
Log.i("tone", "watchChat: 查找控件2-" + mUnpackCount + mUnpackNode);
/* 如果戳开但还未领取 */
if (mUnpackCount == 1 && (mUnpackNode != null)) {
int delayFlag = sharedPreferences.getInt("pref_open_delay", 0) * 1000;
//int delayFlag = sharedPreferences.getInt("pref_open_delay", 0) * 1000;
int max = 500;
int min = 10;
//int delayFlag = (int)(Math.random() * 1000);
Random random = new Random();
int delayFlag = random.nextInt(max) % (max - min + 1) + min;
Log.i("tone", "watchChat: 准备领取红包-" + delayFlag);
//Log.d("delay", "delay:" + delayFlag);
new android.os.Handler().postDelayed(
new Runnable() {
public void run() {
Expand All @@ -112,28 +125,30 @@ private void openPacket() {
float dpi = metrics.density;
if (android.os.Build.VERSION.SDK_INT <= 23) {
mUnpackNode.performAction(AccessibilityNodeInfo.ACTION_CLICK);
Log.i("tone", "watchChat: <=23");
} else {
if (android.os.Build.VERSION.SDK_INT > 23) {

Log.i("tone", "watchChat: >23");
Path path = new Path();
if (640 == dpi) {
path.moveTo(720, 1575);
} else {
path.moveTo(540, 1060);
}
GestureDescription.Builder builder = new GestureDescription.Builder();
GestureDescription gestureDescription = builder.addStroke(new GestureDescription.StrokeDescription(path, 450, 50)).build();
GestureDescription gestureDescription = builder.addStroke(new GestureDescription.StrokeDescription
(path, 450, 50)).build();
dispatchGesture(gestureDescription, new GestureResultCallback() {
@Override
public void onCompleted(GestureDescription gestureDescription) {
Log.d("test", "onCompleted");
Log.i("tone", "onCompleted");
mMutex = false;
super.onCompleted(gestureDescription);
}

@Override
public void onCancelled(GestureDescription gestureDescription) {
Log.d("test", "onCancelled");
Log.i("tone", "onCancelled");
mMutex = false;
super.onCancelled(gestureDescription);
}
Expand All @@ -159,6 +174,8 @@ private void setCurrentActivityName(AccessibilityEvent event) {
} catch (PackageManager.NameNotFoundException e) {
currentActivityName = WECHAT_LUCKMONEY_GENERAL_ACTIVITY;
}

Log.i("tone", "setCurrentActivityName: " + currentActivityName);
}

private boolean watchList(AccessibilityEvent event) {
Expand Down Expand Up @@ -246,7 +263,8 @@ private void checkNodeInfo(int eventType) {

/* 聊天会话窗口,遍历节点匹配“领取红包”和"查看红包" */
AccessibilityNodeInfo node1 = (sharedPreferences.getBoolean("pref_watch_self", false)) ?
this.getTheLastNode(WECHAT_VIEW_OTHERS_CH, WECHAT_VIEW_SELF_CH) : this.getTheLastNode(WECHAT_VIEW_OTHERS_CH);
this.getTheLastNode(WECHAT_VIEW_OTHERS_CH, WECHAT_VIEW_SELF_CH) : this.getTheLastNode
(WECHAT_VIEW_OTHERS_CH);
if (node1 != null &&
(currentActivityName.contains(WECHAT_LUCKMONEY_CHATTING_ACTIVITY)
|| currentActivityName.contains(WECHAT_LUCKMONEY_GENERAL_ACTIVITY))) {
Expand All @@ -261,7 +279,9 @@ private void checkNodeInfo(int eventType) {

/* 戳开红包,红包还没抢完,遍历节点匹配“拆红包” */
AccessibilityNodeInfo node2 = findOpenButton(this.rootNodeInfo);
if (node2 != null && "android.widget.Button".equals(node2.getClassName()) && currentActivityName.contains(WECHAT_LUCKMONEY_RECEIVE_ACTIVITY)) {

if (node2 != null && "android.widget.Button".equals(node2.getClassName()) && currentActivityName.contains
(WECHAT_LUCKMONEY_RECEIVE_ACTIVITY)) {
mUnpackNode = node2;
mUnpackCount += 1;
return;
Expand Down

0 comments on commit cdfef11

Please sign in to comment.