Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonQS committed Apr 12, 2018
1 parent 89cbc08 commit e49344c
Show file tree
Hide file tree
Showing 22 changed files with 110 additions and 181 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
applicationId "com.qsboy.antirecall"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionCode 4
versionName '1.0'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".MainActivity"
android:name=".ui.MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity android:name="com.qsboy.antirecall.LaunchActivity">
<activity android:name="com.qsboy.antirecall.ui.LaunchActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/com/qsboy/antirecall/access/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void findRecalls(AccessibilityNodeInfo root, AccessibilityEvent event) {
CharSequence cs = event.getSource().getText();
if (cs == null)
return;
String string = cs.toString();
String string = cs + "";
if (!string.contains(RECALL))
return;

Expand All @@ -93,7 +93,7 @@ void findRecalls(AccessibilityNodeInfo root, AccessibilityEvent event) {

initContext(event);

Log.w(TAG, "findRecalls: unknownRecalls: " + unknownRecalls + " prevMsg: " + prevMessage + " nextMsg: " + nextMessage);
Log.w(TAG, "findRecalls: \nunknown Recalls: " + unknownRecalls + " \nprev Msg: " + prevMessage + " \nnext Msg: " + nextMessage);
if (prevMessage == null && nextMessage == null) {
XToast.build(context, "不能全屏撤回哦").show();
return;
Expand Down Expand Up @@ -152,6 +152,7 @@ void findRecalls(AccessibilityNodeInfo root, AccessibilityEvent event) {
* @return 是否要继续找
*/
private boolean findRecallByPrev(boolean force) {
Log.i(TAG, "findRecallByPrev");
Messages messages;
int maxID = dao.getMaxID(title, isWX);
for (int i = 0; i < unknownRecalls; i++) {
Expand Down Expand Up @@ -181,6 +182,7 @@ private boolean findRecallByPrev(boolean force) {
}

private void findRecallByNext() {
Log.i(TAG, "findRecallByNext");
Messages messages;
for (int i = unknownRecalls - 1; i >= 0; i--) {
while (true) {
Expand Down Expand Up @@ -309,9 +311,7 @@ public void onNotificationChanged(AccessibilityEvent event) {
if (texts.isEmpty() || texts.size() == 0)
return;
for (CharSequence text : texts) {
if (text == null)
return;
String string = text.toString();
String string = text + "";
Log.w(TAG, "Notification text: " + string);
if (string.equals("你的帐号在电脑登录"))
return;
Expand Down Expand Up @@ -343,7 +343,7 @@ public void onNotificationChanged(AccessibilityEvent event) {
* 判断是否是在其他人的聊天界面收到了消息
*/
private void onOtherMsg() {
String string = otherMsgNode.getText().toString();
String string = otherMsgNode.getText() + "";
Log.i(TAG, "onOtherMsg: " + string);
int i = string.indexOf(":");
int k = string.lastIndexOf("-");
Expand Down
108 changes: 66 additions & 42 deletions app/src/main/java/com/qsboy/antirecall/access/MainService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package com.qsboy.antirecall.access;

import android.accessibilityservice.AccessibilityService;
import android.app.Notification;
import android.os.Parcelable;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
Expand All @@ -23,6 +25,7 @@ public class MainService extends AccessibilityService {
final String pknTim = "com.tencent.tim";
final String pknQQ = "com.tencent.mobileqq";
final String pknWX = "com.tencent.mm";
WXAutoLogin autoLogin;

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
Expand All @@ -31,11 +34,9 @@ public void onAccessibilityEvent(AccessibilityEvent event) {
Log.d(TAG, "onAccessibilityEvent: package name is null, return");
return;
}
packageName = event.getPackageName().toString();
packageName = event.getPackageName() + "";

// if (!packageName.equals(pknTim) &&
// !packageName.equals(pknQQ) &&
// !packageName.equals(pknWX))
// if (!(packageName.equals(pknTim) || packageName.equals(pknQQ) || packageName.equals(pknWX)))
// return;

root = getRootInActiveWindow();
Expand All @@ -54,37 +55,18 @@ public void onAccessibilityEvent(AccessibilityEvent event) {
onNotification(event);
break;
case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED:
autoLogin.autoLoginWX();
onContentChanged(event);
break;
case AccessibilityEvent.TYPE_VIEW_CLICKED:
autoLogin.autoLoginWX();
onClick(event);
break;

}

}

private void onNotification(AccessibilityEvent event) {
List<CharSequence> texts = event.getText();
if (texts.isEmpty() || texts.size() == 0) {
NodesInfo.show(root, TAG);
//微信的登录通知的 text 是 null
autoLoginWX();
return;
}
Log.i(TAG, "onNotification: " + packageName + " | " + texts);
switch (packageName) {
case pknTim:
// new TimClient(this).onContentChanged(root);
new TimClient(this).onNotificationChanged(event);
break;
case pknQQ:
// new QQClient(this).onContentChanged(root);
new QQClient(this).onNotificationChanged(event);
break;
}
}

private void onContentChanged(AccessibilityEvent event) {
if (root == null)
return;
Expand Down Expand Up @@ -123,24 +105,66 @@ private void onClick(AccessibilityEvent event) {
}
}

private void autoLoginWX() {
// TODO: 06/04/2018 生成标志位 在之后的10次 content change都去检查微信登录
Log.v(TAG, "autoLoginWX");
if (root.getChildCount() != 1)
return;
AccessibilityNodeInfo node = root.getChild(0);
if (node.getChildCount() != 5)
return;
//不直接判断字符串是因为多语言适应
AccessibilityNodeInfo loginBtn = node.getChild(3);
if (!loginBtn.isClickable())
return;
if (!node.getChild(0).isClickable())
return;
if (!node.getChild(4).isClickable())
private void onNotification(AccessibilityEvent event) {
List<CharSequence> texts = event.getText();
if (texts.isEmpty() || texts.size() == 0) {
NodesInfo.show(root, TAG);
//微信的登录通知的 text 是 null
autoLogin.flagEnable();
return;
loginBtn.performAction(AccessibilityNodeInfo.ACTION_CLICK);
Log.i(TAG, "autoLoginWX: click");
}
Log.i(TAG, "onNotification: " + packageName + " | " + texts);
switch (packageName) {
case pknTim:
// new TimClient(this).onContentChanged(root);
new TimClient(this).onNotificationChanged(event);
break;
case pknQQ:
// new QQClient(this).onContentChanged(root);
new QQClient(this).onNotificationChanged(event);
break;
}
}

/**
* 在检测到空通知体的时候 enable flag
* 在之后的10次 onContentChange 都去检查微信登录
*/
private class WXAutoLogin {
private int time = 0;

public void flagEnable() {
time = 10;
}

private void autoLoginWX() {
while (time > 0) {
time--;
Log.v(TAG, "autoLoginWX");
if (root.getChildCount() != 1)
return;
AccessibilityNodeInfo node = root.getChild(0);
if (node.getChildCount() != 5)
return;
//不直接判断字符串是因为多语言适应
AccessibilityNodeInfo loginBtn = node.getChild(3);
if (!loginBtn.isClickable())
return;
if (!node.getChild(0).isClickable())
return;
if (!node.getChild(4).isClickable())
return;
loginBtn.performAction(AccessibilityNodeInfo.ACTION_CLICK);
Log.i(TAG, "autoLoginWX: click");
time = 0;
}
}
}

@Override
protected void onServiceConnected() {
super.onServiceConnected();
autoLogin = new WXAutoLogin();
}

@Override
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/com/qsboy/antirecall/access/QQClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected boolean init(AccessibilityNodeInfo root) {
Log.d(TAG, "init: name is null,return");
return false;
}
title = titleNode.getText().toString();
title = titleNode.getText() + "";

chatGroupViewNode = root.getChild(0);
if (chatGroupViewNode == null) {
Expand Down Expand Up @@ -125,7 +125,7 @@ protected void parser(AccessibilityNodeInfo group) {
headIconPos = j;
break;
case IdChatItem:
switch (child.getClassName().toString()) {
switch (child.getClassName() + "") {
case "android.widget.RelativeLayout":
if (child.getChildCount() != 0) {
if (child.getContentDescription() != null) {
Expand All @@ -147,27 +147,27 @@ protected void parser(AccessibilityNodeInfo group) {
if ("android.widget.RelativeLayout".equals(child1.getClassName())) {
if ("android.widget.TextView".equals(child2.getClassName())) {
// message = "回复 " + child1.getText() + ": \n" + child2.getText();
message = child2.getText().toString();
message = child2.getText() + "";
}
}
}
Log.d(TAG, "content_layout: 回复消息");
}
break;
case "android.widget.TextView": {
message = child.getText().toString();
message = child.getText() + "";
Log.v(TAG, "content_layout: 普通文本");
}
break;
}
messagePos = j;
break;
case IdNickName:
subName = child.getText().toString();
subName = child.getText() + "";
break;
case IdGrayBar:
if (!child.isClickable() && !child.isFocusable()) {
message = child.getText().toString();
message = child.getText() + "";
int indexOfRecall = message.indexOf(RECALL);
if (indexOfRecall >= 0) {
isRecalledMsg = true;
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/com/qsboy/antirecall/access/TimClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected boolean init(AccessibilityNodeInfo root) {
Log.d(TAG, "init: name is null,return");
return false;
}
title = titleNode.getText().toString();
title = titleNode.getText() + "";

for (int i = 4; i < 7; i++) {
AccessibilityNodeInfo child = root.getChild(i);
Expand Down Expand Up @@ -137,7 +137,7 @@ protected void parser(AccessibilityNodeInfo group) {
headIconPos = j;
break;
case IdChatItem:
switch (child.getClassName().toString()) {
switch (child.getClassName() + "") {
case "android.widget.RelativeLayout":
if (child.getChildCount() != 0) {
if (child.getContentDescription() != null) {
Expand All @@ -159,7 +159,7 @@ protected void parser(AccessibilityNodeInfo group) {
if ("android.widget.TextView".equals(child2.getClassName())) {
// TODO: 这里去掉回复 只留下内容 和通知栏一样
// message = "回复 " + child1.getText() + ": \n" + child2.getText();
message = child2.getText().toString();
message = child2.getText() + "";
}
}
}
Expand All @@ -168,7 +168,7 @@ protected void parser(AccessibilityNodeInfo group) {
}
break;
case "android.widget.TextView": {
message = child.getText().toString();
message = child.getText() + "";
Log.v(TAG, "content_layout: 普通文本");
}
break;
Expand All @@ -177,15 +177,15 @@ protected void parser(AccessibilityNodeInfo group) {
break;
case IdNickName:
//群聊头像上面的群昵称最后有一个冒号
subName = child.getText().toString();
subName = child.getText() + "";
subName = subName.substring(0, subName.length() - 1);
break;
case IdGrayBar:
// 撤回消息或者是有人加入
// 撤回消息的是不可点击的
// 接收文件和撤回消息一样
if (!child.isClickable() && !child.isFocusable()) {
message = child.getText().toString();
message = child.getText() + "";
int indexOfRecall = message.indexOf(RECALL);
if (indexOfRecall >= 0) {
isRecalledMsg = true;
Expand Down
Loading

0 comments on commit e49344c

Please sign in to comment.