From 0d3ad9cc458c3c56e03c5f2b6dc42d06090546eb Mon Sep 17 00:00:00 2001 From: Zhongyi Tong Date: Tue, 31 May 2016 21:06:30 +0800 Subject: [PATCH] Fix bugly #393 and #305. Use a new mutex to avoid concurrent conflicts, which produces NPEs. --- .idea/modules/WeChatLuckyMoney.iml | 19 ++++ .idea/modules/app/app.iml | 94 ++++++++++++++++++ .idea/runConfigurations.xml | 12 --- app/app.iml | 99 ------------------- .../hongbao/services/HongbaoService.java | 23 ++--- app/src/main/res/xml/general_preferences.xml | 2 +- 6 files changed, 123 insertions(+), 126 deletions(-) create mode 100644 .idea/modules/WeChatLuckyMoney.iml create mode 100644 .idea/modules/app/app.iml delete mode 100644 .idea/runConfigurations.xml delete mode 100644 app/app.iml diff --git a/.idea/modules/WeChatLuckyMoney.iml b/.idea/modules/WeChatLuckyMoney.iml new file mode 100644 index 00000000..6482ff12 --- /dev/null +++ b/.idea/modules/WeChatLuckyMoney.iml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/app/app.iml b/.idea/modules/app/app.iml new file mode 100644 index 00000000..5cc5f508 --- /dev/null +++ b/.idea/modules/app/app.iml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460d..00000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/app.iml b/app/app.iml deleted file mode 100644 index 3c3b1186..00000000 --- a/app/app.iml +++ /dev/null @@ -1,99 +0,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 f58b6bec..80a18db5 100644 --- a/app/src/main/java/xyz/monkeytong/hongbao/services/HongbaoService.java +++ b/app/src/main/java/xyz/monkeytong/hongbao/services/HongbaoService.java @@ -39,7 +39,7 @@ public class HongbaoService extends AccessibilityService implements SharedPrefer private AccessibilityNodeInfo rootNodeInfo, mReceiveNode, mUnpackNode; private boolean mLuckyMoneyPicked, mLuckyMoneyReceived; private int mUnpackCount = 0; - private boolean mMutex = false, mListMutex = false; + private boolean mMutex = false, mListMutex = false, mChatMutex = false; private HongbaoSignature signature = new HongbaoSignature(); private PowerUtil powerUtil; @@ -63,7 +63,11 @@ public void onAccessibilityEvent(AccessibilityEvent event) { mListMutex = false; } - if (sharedPreferences.getBoolean("pref_watch_chat", false)) watchChat(event); + if (!mChatMutex) { + mChatMutex = true; + if (sharedPreferences.getBoolean("pref_watch_chat", false)) watchChat(event); + mChatMutex = false; + } } private void watchChat(AccessibilityEvent event) { @@ -134,6 +138,7 @@ private boolean watchList(AccessibilityEvent event) { //避免当订阅号中出现标题为“[微信红包]拜年红包”(其实并非红包)的信息时误判 if (!nodes.isEmpty() && currentActivityName.contains(WECHAT_LUCKMONEY_GENERAL_ACTIVITY)) { AccessibilityNodeInfo nodeToClick = nodes.get(0); + if (nodeToClick == null) return false; CharSequence contentDescription = nodeToClick.getContentDescription(); if (contentDescription != null && !signature.getContentDescription().equals(contentDescription)) { nodeToClick.performAction(AccessibilityNodeInfo.ACTION_CLICK); @@ -173,9 +178,6 @@ public void onInterrupt() { } - /** - * 红包 钮 - */ private AccessibilityNodeInfo findOpenButton(AccessibilityNodeInfo node) { if (node == null) return null; @@ -197,9 +199,6 @@ private AccessibilityNodeInfo findOpenButton(AccessibilityNodeInfo node) { return null; } - /** - * 节 信 - */ private void checkNodeInfo(int eventType) { if (this.rootNodeInfo == null) return; @@ -257,7 +256,7 @@ private void sendComment() { nodeToInput.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, arguments); } } catch (Exception e) { - // Not support + // Not supported } } @@ -289,11 +288,7 @@ private AccessibilityNodeInfo getTheLastNode(String... texts) { if (bounds.bottom > bottom) { bottom = bounds.bottom; lastNode = node; - if (text.equals(WECHAT_VIEW_OTHERS_CH)) { - signature.others = true; - } else { - signature.others = false; - } + signature.others = text.equals(WECHAT_VIEW_OTHERS_CH); } } } diff --git a/app/src/main/res/xml/general_preferences.xml b/app/src/main/res/xml/general_preferences.xml index 6ab0eef9..84ff046d 100644 --- a/app/src/main/res/xml/general_preferences.xml +++ b/app/src/main/res/xml/general_preferences.xml @@ -54,7 +54,7 @@