添加 Hook 消息接收与本地调试模式,便于 LSPosed/Telegram 联调。
新增 HookMessageReceiver 与通知服务 Hook 上报链路,支持未登录本地监听;补充 build/install 脚本并忽略 platform-tools 与 xposed 构建产物。
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package com.miraclegarden.smsmessage.service;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.miraclegarden.smsmessage.Activity.NotificationActivity;
|
||||
import com.miraclegarden.smsmessage.App;
|
||||
import com.miraclegarden.smsmessage.MessageInfo;
|
||||
|
||||
/**
|
||||
* 接收 Xposed 模块转发的消息(前台 Hook 通道)。
|
||||
*/
|
||||
public class HookMessageReceiver extends BroadcastReceiver {
|
||||
|
||||
public static final String ACTION_HOOK_MESSAGE = "com.miraclegarden.smsmessage.action.HOOK_MESSAGE";
|
||||
public static final String EXTRA_PACKAGE_NAME = "packageName";
|
||||
public static final String EXTRA_TITLE = "title";
|
||||
public static final String EXTRA_CONTENT = "content";
|
||||
public static final String EXTRA_TIMESTAMP = "timestamp";
|
||||
public static final String EXTRA_SOURCE = "source";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent == null || !ACTION_HOOK_MESSAGE.equals(intent.getAction())) {
|
||||
return;
|
||||
}
|
||||
|
||||
String packageName = intent.getStringExtra(EXTRA_PACKAGE_NAME);
|
||||
String title = intent.getStringExtra(EXTRA_TITLE);
|
||||
String content = intent.getStringExtra(EXTRA_CONTENT);
|
||||
long timestamp = intent.getLongExtra(EXTRA_TIMESTAMP, System.currentTimeMillis());
|
||||
String source = intent.getStringExtra(EXTRA_SOURCE);
|
||||
|
||||
if (TextUtils.isEmpty(packageName) || TextUtils.isEmpty(content)) {
|
||||
return;
|
||||
}
|
||||
|
||||
MessageInfo messageInfo = App.getMessageByNotiList(context, packageName);
|
||||
if (messageInfo == null) {
|
||||
NotificationActivity.sendMessage("[Hook] 未配置监听: " + packageName);
|
||||
return;
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(title)) {
|
||||
title = messageInfo.getAppName();
|
||||
}
|
||||
|
||||
NotificationActivity.sendMessage("[Hook/" + source + "] " + title + " " + content);
|
||||
NotificationService.submitFromHook(context, messageInfo, title, content, timestamp);
|
||||
}
|
||||
}
|
||||
@@ -86,15 +86,46 @@ public class NotificationService extends NotificationListenerService {
|
||||
retryManager.restoreFromPersistence();
|
||||
}
|
||||
|
||||
private static final String ACTION_HOOK_MESSAGE = "ACTION_HOOK_MESSAGE";
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
if (intent != null && "ACTION_START_MONITORING".equals(intent.getAction())) {
|
||||
startMonitoring();
|
||||
if (intent != null) {
|
||||
if ("ACTION_START_MONITORING".equals(intent.getAction())) {
|
||||
startMonitoring();
|
||||
} else if (ACTION_HOOK_MESSAGE.equals(intent.getAction())) {
|
||||
handleHookMessageIntent(intent);
|
||||
}
|
||||
}
|
||||
NotificationActivity.sendMessage("监听服务成功!");
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
public static void submitFromHook(Context context, MessageInfo messageInfo,
|
||||
String title, String content, long timestamp) {
|
||||
Intent intent = new Intent(context, NotificationService.class);
|
||||
intent.setAction(ACTION_HOOK_MESSAGE);
|
||||
intent.putExtra("hook_package", messageInfo.getPackageName());
|
||||
intent.putExtra("hook_title", title);
|
||||
intent.putExtra("hook_content", content);
|
||||
intent.putExtra("hook_timestamp", timestamp);
|
||||
context.startService(intent);
|
||||
}
|
||||
|
||||
private void handleHookMessageIntent(Intent intent) {
|
||||
String packageName = intent.getStringExtra("hook_package");
|
||||
MessageInfo messageInfo = App.getMessageByNotiList(this, packageName);
|
||||
if (messageInfo == null) {
|
||||
return;
|
||||
}
|
||||
NotificationExtractor.Result result = new NotificationExtractor.Result(
|
||||
intent.getStringExtra("hook_title"),
|
||||
intent.getStringExtra("hook_content"),
|
||||
intent.getLongExtra("hook_timestamp", System.currentTimeMillis())
|
||||
);
|
||||
submitNotification(messageInfo, result);
|
||||
}
|
||||
|
||||
public static boolean isMonitoring() {
|
||||
return isMonitoring;
|
||||
}
|
||||
@@ -167,17 +198,17 @@ public class NotificationService extends NotificationListenerService {
|
||||
}
|
||||
|
||||
private void submitNotification(MessageInfo messageInfo, NotificationExtractor.Result result) {
|
||||
// 检查是否已登录
|
||||
if (!tokenManager.isLoggedIn()) {
|
||||
NotificationActivity.sendMessage("未登录,请先登录");
|
||||
return;
|
||||
}
|
||||
// 调试用:暂时跳过登录检查
|
||||
// if (!tokenManager.isLoggedIn()) {
|
||||
// NotificationActivity.sendMessage("未登录,请先登录");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// 检查是否关联了银行账户
|
||||
if (TextUtils.isEmpty(messageInfo.getBankInfoId())) {
|
||||
NotificationActivity.sendMessage("该应用未关联银行账户,请先配置");
|
||||
return;
|
||||
}
|
||||
// 调试用:本地模式可不绑定服务器银行账户
|
||||
// if (TextUtils.isEmpty(messageInfo.getBankInfoId())) {
|
||||
// NotificationActivity.sendMessage("该应用未关联银行账户,请先配置");
|
||||
// return;
|
||||
// }
|
||||
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
|
||||
Reference in New Issue
Block a user