From 64bc802345e608dd2ba842fad33279d6ec4ac842 Mon Sep 17 00:00:00 2001 From: walter Date: Mon, 17 Dec 2018 17:35:31 +0800 Subject: [PATCH] fix can't open packet --- WeChatLuckyMoney.iml | 8 -- .../hongbao/services/HongbaoService.java | 78 ++++++++++--------- .../res/xml/accessible_service_config.xml | 1 + 3 files changed, 41 insertions(+), 46 deletions(-) diff --git a/WeChatLuckyMoney.iml b/WeChatLuckyMoney.iml index 41c0903e..70cb8acb 100644 --- a/WeChatLuckyMoney.iml +++ b/WeChatLuckyMoney.iml @@ -1,13 +1,5 @@ - - - - - - diff --git a/app/src/main/java/xyz/monkeytong/hongbao/services/HongbaoService.java b/app/src/main/java/xyz/monkeytong/hongbao/services/HongbaoService.java index 0ef84fad..897f17d6 100644 --- a/app/src/main/java/xyz/monkeytong/hongbao/services/HongbaoService.java +++ b/app/src/main/java/xyz/monkeytong/hongbao/services/HongbaoService.java @@ -2,25 +2,27 @@ import android.accessibilityservice.AccessibilityService; import android.accessibilityservice.GestureDescription; +import android.annotation.SuppressLint; import android.app.Notification; import android.app.PendingIntent; 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 xyz.monkeytong.hongbao.utils.HongbaoSignature; +import xyz.monkeytong.hongbao.utils.PowerUtil; + public class HongbaoService extends AccessibilityService implements SharedPreferences.OnSharedPreferenceChangeListener { private static final String TAG = "HongbaoService"; private static final String WECHAT_DETAILS_EN = "Details"; @@ -35,6 +37,7 @@ public class HongbaoService extends AccessibilityService implements SharedPrefer private static final String WECHAT_LUCKMONEY_DETAIL_ACTIVITY = "LuckyMoneyDetailUI"; private static final String WECHAT_LUCKMONEY_GENERAL_ACTIVITY = "LauncherUI"; private static final String WECHAT_LUCKMONEY_CHATTING_ACTIVITY = "ChattingUI"; + private static final String WECHAT_LUCKMONEY_RECEIVE_UI_ACTIVITY = "LuckyMoneyReceiveUI"; private String currentActivityName = WECHAT_LUCKMONEY_GENERAL_ACTIVITY; private AccessibilityNodeInfo rootNodeInfo, mReceiveNode, mUnpackNode; @@ -74,8 +77,6 @@ public void onAccessibilityEvent(AccessibilityEvent event) { private void watchChat(AccessibilityEvent event) { this.rootNodeInfo = getRootInActiveWindow(); - if (rootNodeInfo == null) return; - mReceiveNode = null; mUnpackNode = null; @@ -92,7 +93,7 @@ private void watchChat(AccessibilityEvent event) { } /* 如果戳开但还未领取 */ Log.d(TAG, "戳开红包!" + " mUnpackCount: " + mUnpackCount + " mUnpackNode: " + mUnpackNode); - if (mUnpackCount >= 1 && (mUnpackNode != null)) { + if (canOpen(event)) { int delayFlag = sharedPreferences.getInt("pref_open_delay", 0) * 1000; new android.os.Handler().postDelayed( new Runnable() { @@ -110,42 +111,43 @@ public void run() { } } + private boolean canOpen(AccessibilityEvent event) { + return event.getClassName() != null + && event.getClassName().toString().contains(WECHAT_LUCKMONEY_RECEIVE_UI_ACTIVITY) + && event.isFullScreen() + && event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED; + } + + @SuppressLint("NewApi") private void openPacket() { + if (android.os.Build.VERSION.SDK_INT <= 23) { + if (mUnpackCount >= 1 && (mUnpackNode != null)) { + mUnpackNode.performAction(AccessibilityNodeInfo.ACTION_CLICK); + } + return; + } DisplayMetrics metrics = getResources().getDisplayMetrics(); float dpi = metrics.densityDpi; - Log.d(TAG, "openPacket!" + dpi); - if (android.os.Build.VERSION.SDK_INT <= 23) { - mUnpackNode.performAction(AccessibilityNodeInfo.ACTION_CLICK); - } else { - if (android.os.Build.VERSION.SDK_INT > 23) { - Path path = new Path(); - if (640 == dpi) { //1440 - path.moveTo(720, 1575); - } else if(320 == dpi){//720p - path.moveTo(355, 780); - }else if(480 == dpi){//1080p - path.moveTo(533, 1115); - } - GestureDescription.Builder builder = new GestureDescription.Builder(); - GestureDescription gestureDescription = builder.addStroke(new GestureDescription.StrokeDescription(path, 450, 50)).build(); - dispatchGesture(gestureDescription, new GestureResultCallback() { - @Override - public void onCompleted(GestureDescription gestureDescription) { - Log.d(TAG, "onCompleted"); - mMutex = false; - super.onCompleted(gestureDescription); - } - - @Override - public void onCancelled(GestureDescription gestureDescription) { - Log.d(TAG, "onCancelled"); - mMutex = false; - super.onCancelled(gestureDescription); - } - }, null); + Log.d(TAG, "openPacket!" + dpi); + Path path = new Path(); + path.moveTo(metrics.widthPixels * 0.5f, metrics.heightPixels * 0.6f); + GestureDescription.Builder builder = new GestureDescription.Builder(); + GestureDescription gestureDescription = builder.addStroke(new GestureDescription.StrokeDescription(path, 450, 50)).build(); + dispatchGesture(gestureDescription, new GestureResultCallback() { + @Override + public void onCompleted(GestureDescription gestureDescription) { + Log.d(TAG, "onCompleted"); + mMutex = false; + super.onCompleted(gestureDescription); + } + @Override + public void onCancelled(GestureDescription gestureDescription) { + Log.d(TAG, "onCancelled"); + mMutex = false; + super.onCancelled(gestureDescription); } - } + }, null); } private void setCurrentActivityName(AccessibilityEvent event) { diff --git a/app/src/main/res/xml/accessible_service_config.xml b/app/src/main/res/xml/accessible_service_config.xml index 426c8b08..d4d8cd1c 100644 --- a/app/src/main/res/xml/accessible_service_config.xml +++ b/app/src/main/res/xml/accessible_service_config.xml @@ -6,6 +6,7 @@ android:accessibilityFeedbackType="feedbackAllMask" android:packageNames="com.tencent.mm" android:notificationTimeout="10" + android:canPerformGestures="true" android:settingsActivity="xyz.monkeytong.hongbao.activities.SettingsActivity" android:accessibilityFlags="flagDefault" android:canRetrieveWindowContent="true"/> \ No newline at end of file