From 532764aa1adb12469557d28b8d6450916737e9d2 Mon Sep 17 00:00:00 2001 From: walter Date: Mon, 17 Dec 2018 18:00:48 +0800 Subject: [PATCH] fix can't open packet --- app/build.gradle | 14 ++-- .../hongbao/services/HongbaoService.java | 77 ++++++++++--------- .../res/xml/accessible_service_config.xml | 1 + 3 files changed, 47 insertions(+), 45 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a83b92e5..919f3d38 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,15 +1,15 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 25 - buildToolsVersion "26.0.2" + compileSdkVersion 26 + buildToolsVersion "26.0.3" useLibrary 'org.apache.http.legacy' defaultConfig { applicationId "xyz.monkeytong.hongbao" minSdkVersion 19 - targetSdkVersion 25 - versionCode 7 - versionName "v5.0.0" + targetSdkVersion 26 + versionCode 8 + versionName "v5.0.1" ndk { //设置支持的SO库架构 abiFilters 'armeabi', 'armeabi-v7a' //, 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a' @@ -40,6 +40,6 @@ android { //其中latest.release指代最新版本号,也可以指定明确的版本号,例如1.0.1 compile 'com.tencent.bugly:nativecrashreport:latest.release' //其中latest.release指代最新版本号,也可以指定明确的版本号,例如2.2.0 - compile 'com.android.support:support-v4:25.4.0' - compile 'com.android.support:appcompat-v7:25.4.0' + compile 'com.android.support:support-v4:26.1.0' + compile 'com.android.support:appcompat-v7:26.1.0' } \ No newline at end of file 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..bac36e2d 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,41 +111,41 @@ 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; + } + private void openPacket() { - 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); + if (mUnpackCount >= 1 && (mUnpackNode != null)) { + mUnpackNode.performAction(AccessibilityNodeInfo.ACTION_CLICK); + } + }else{ + DisplayMetrics metrics = getResources().getDisplayMetrics(); + float dpi = metrics.densityDpi; + 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); } - 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); - } + @Override + public void onCancelled(GestureDescription gestureDescription) { + Log.d(TAG, "onCancelled"); + mMutex = false; + super.onCancelled(gestureDescription); + } + }, null); } } 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