Compare commits
20 Commits
f0a49ef542
...
system
| Author | SHA1 | Date | |
|---|---|---|---|
| 4e8f666802 | |||
| 884aefc366 | |||
| 2c84258ae2 | |||
| 7297b8f1c4 | |||
| 48be0900e1 | |||
| 620235c089 | |||
| b3752e4716 | |||
| ffc88920db | |||
| 492cafb51a | |||
| bfc5e4905a | |||
| e55cba4b63 | |||
| 59eae71d70 | |||
| 4463c24107 | |||
| c416971d67 | |||
| 21dc14ba5f | |||
| b4b02d0b1c | |||
| 443b41fde6 | |||
| 09908fcdc7 | |||
| 10b7fc57c1 | |||
| 55b181cba7 |
22
.gitignore
vendored
22
.gitignore
vendored
@@ -2,4 +2,24 @@
|
||||
.idea
|
||||
.DS_Store
|
||||
local.properties
|
||||
app/debug/app-debug.apk
|
||||
# Built application files
|
||||
*.apk
|
||||
*.ap_
|
||||
|
||||
# Generated files
|
||||
bin/
|
||||
gen/
|
||||
out/
|
||||
|
||||
# Gradle files
|
||||
build/
|
||||
|
||||
# Keystore files
|
||||
*.jks
|
||||
*.keystore
|
||||
|
||||
app/release
|
||||
app/release/*
|
||||
app/debug
|
||||
app/debug/*
|
||||
app/debug/output-metadata.json
|
||||
|
||||
@@ -43,6 +43,6 @@ dependencies {
|
||||
implementation 'com.google.android.material:material:1.3.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
{
|
||||
"version": 3,
|
||||
"artifactType": {
|
||||
"type": "APK",
|
||||
"kind": "Directory"
|
||||
},
|
||||
"applicationId": "com.nbee.echolink",
|
||||
"variantName": "debug",
|
||||
"elements": [
|
||||
{
|
||||
"type": "SINGLE",
|
||||
"filters": [],
|
||||
"attributes": [],
|
||||
"versionCode": 1,
|
||||
"versionName": "1.0.1",
|
||||
"outputFile": "app-debug.apk"
|
||||
}
|
||||
],
|
||||
"elementType": "File"
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.nbee.echolink"
|
||||
android:sharedUserId="android.uid.system"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.ACTION_NOTIFICATION_LISTENER_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
|
||||
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS" />
|
||||
@@ -20,6 +23,7 @@
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
|
||||
|
||||
|
||||
<application
|
||||
android:name=".EchoLink"
|
||||
android:allowBackup="true"
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.nbee.echolink;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
|
||||
public class EchoLink extends Application {
|
||||
@Override
|
||||
public void onCreate() {
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.nbee.echolink;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import timber.log.Timber;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.nbee.echolink.async.BatteryOptimizationTask;
|
||||
import com.nbee.echolink.service.MonitorService;
|
||||
import com.nbee.echolink.service.NotificationListener;
|
||||
import com.nbee.echolink.utils.BatteryOptimizationUtil;
|
||||
import com.nbee.echolink.utils.DeviceInfoUtils;
|
||||
import com.nbee.echolink.utils.PermissionUtils;
|
||||
import com.nbee.echolink.utils.SharedPreferencesManager;
|
||||
import com.nbee.echolink.utils.ShellUtils;
|
||||
@@ -60,6 +61,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
if (isFirstRun()) {
|
||||
setupInitialDataAsync(); // 异步设置初始数据
|
||||
spManager.putBoolean("isFirstRun", false); // 标记不再首次运行
|
||||
Timber.i("首次运行,设置初始数据...");
|
||||
Timber.d("android_ID: " + DeviceInfoUtils.getAndroidID(this));
|
||||
}
|
||||
|
||||
// 请求忽略电池优化设置
|
||||
|
||||
@@ -21,7 +21,7 @@ import okhttp3.RequestBody;
|
||||
import timber.log.Timber;
|
||||
|
||||
public class HeartbeatAlarmReceiver extends BroadcastReceiver {
|
||||
private Context context;
|
||||
private Context thisContext;
|
||||
private String accessToken;
|
||||
private String SN;
|
||||
|
||||
@@ -33,10 +33,12 @@ public class HeartbeatAlarmReceiver extends BroadcastReceiver {
|
||||
*/
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
// 初始化上下文对象,为后续操作提供context
|
||||
thisContext = context;
|
||||
// 执行发送心跳信号的逻辑
|
||||
sendHeartbeatSignal();
|
||||
// 在发送心跳后,重新设置下一次心跳发送的时间
|
||||
MonitorService.scheduleHeartbeat(context);
|
||||
MonitorService.scheduleHeartbeat(thisContext);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +49,7 @@ public class HeartbeatAlarmReceiver extends BroadcastReceiver {
|
||||
*/
|
||||
private void sendHeartbeatSignal() {
|
||||
// 获取心跳请求的URL
|
||||
String heartBeatURL = context.getResources().getString(R.string.heart_beat_url);
|
||||
String heartBeatURL = thisContext.getResources().getString(R.string.heart_beat_url);
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
Request request = buildRequest(heartBeatURL);
|
||||
|
||||
@@ -103,8 +105,9 @@ public class HeartbeatAlarmReceiver extends BroadcastReceiver {
|
||||
*/
|
||||
private <T> Request buildRequest(String apiUrl) {
|
||||
// 从资源文件中读取序列号和访问令牌
|
||||
SN = context.getResources().getString(R.string.SN);
|
||||
accessToken = context.getResources().getString(R.string.access_token);
|
||||
//SN = thisContext.getResources().getString(R.string.SN);
|
||||
SN = DeviceInfoUtils.getAndroidID(thisContext);
|
||||
accessToken = thisContext.getResources().getString(R.string.access_token);
|
||||
// 创建设备信息对象并设置设备相关属性
|
||||
DeviceInfo deviceInfo = new DeviceInfo();
|
||||
deviceInfo.setDeviceBrand(DeviceInfoUtils.getDeviceBrand());
|
||||
|
||||
@@ -216,8 +216,16 @@ public class MonitorService extends Service {
|
||||
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
||||
// 创建一个意图,指定当闹钟触发时要执行的广播接收器
|
||||
Intent intent = new Intent(context, HeartbeatAlarmReceiver.class);
|
||||
// 根据意图和标志位创建一个唯一的PendingIntent,系统通过这个PendingIntent触发广播
|
||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
|
||||
|
||||
// 根据Android版本选择合适的标志位创建一个唯一的PendingIntent
|
||||
PendingIntent pendingIntent = null;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
// Android 12及以上版本需要指定FLAG_IMMUTABLE或FLAG_MUTABLE
|
||||
pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_IMMUTABLE);
|
||||
} else {
|
||||
// 早期版本不需要指定这些标志
|
||||
pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
|
||||
}
|
||||
|
||||
// 计算心跳事件的触发间隔,单位为毫秒
|
||||
long intervalMillis = HEARTBEAT_INTERVAL_MINUTES * 60 * 1000; // 10分钟的毫秒数
|
||||
@@ -235,4 +243,5 @@ public class MonitorService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.nbee.echolink.model.WeChatMsg;
|
||||
import com.nbee.echolink.utils.HandleNoticeUtils;
|
||||
import com.nbee.echolink.utils.NetworkUtils;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
@@ -27,6 +28,7 @@ public class NotificationListener extends NotificationListenerService {
|
||||
private static final List<String> notAllowList = Arrays.asList("com.github.kr328.clash","com.google.android.dialer",
|
||||
"com.google.android.apps.messaging");
|
||||
private HandleNoticeUtils handleNoticeUtils;
|
||||
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
|
||||
private NetworkUtils networkUtil;
|
||||
private final HashMap<String, Long> recentLogs = new HashMap<>();
|
||||
private final Handler logCleanerHandler = new Handler(Looper.getMainLooper());
|
||||
@@ -46,39 +48,52 @@ public class NotificationListener extends NotificationListenerService {
|
||||
}
|
||||
|
||||
Bundle extras = sbn.getNotification().extras;
|
||||
String title = extras.getString(Notification.EXTRA_TITLE);
|
||||
String content = extras.getString(Notification.EXTRA_TEXT);
|
||||
String title = getNotificationText(extras, Notification.EXTRA_TITLE);
|
||||
String content = getNotificationText(extras, Notification.EXTRA_TEXT);
|
||||
String tickerText = sbn.getNotification().tickerText != null ? sbn.getNotification().tickerText.toString() : "";
|
||||
String logMessage = String.format("packageName: %s, title: %s, content: %s, tickerText: %s", packageName, title, content, tickerText);
|
||||
String appName = handleNoticeUtils.messageHandle(packageName);
|
||||
|
||||
if ("微信".equals(appName) && tickerText.contains(":")) {
|
||||
if (!shouldPrintLog(logMessage)) {
|
||||
return; // 如果在30秒内已打印过,则跳过
|
||||
}
|
||||
|
||||
String appName = handleNoticeUtils.messageHandle(packageName);
|
||||
if ("微信".equals(appName)) {
|
||||
handleWeChatNotification(packageName, title, tickerText);
|
||||
}
|
||||
|
||||
Timber.d(logMessage);
|
||||
}
|
||||
|
||||
private String getNotificationText(Bundle extras, String key) {
|
||||
CharSequence charSequence = extras.getCharSequence(key);
|
||||
return charSequence != null ? charSequence.toString() : "";
|
||||
}
|
||||
|
||||
private void handleWeChatNotification(String packageName, String title, String tickerText) {
|
||||
if (tickerText.contains(":")) {
|
||||
String[] parts = tickerText.split(":", 2);
|
||||
String sender = parts[0].trim(); // 去除两端的空格
|
||||
String message = parts.length > 1 ? parts[1].trim() : ""; // 同样去除两端的空格
|
||||
if (parts.length < 2) return; // 安全检查,确保不会因数组越界而崩溃
|
||||
|
||||
String sender = parts[0].trim();
|
||||
String message = parts[1].trim();
|
||||
WeChatMsg weChatMsg = new WeChatMsg();
|
||||
weChatMsg.setPackageName(packageName);
|
||||
weChatMsg.setSender(sender);
|
||||
weChatMsg.setMessage(message);
|
||||
weChatMsg.setTitle(title);
|
||||
weChatMsg.setAppName(appName);
|
||||
weChatMsg.setCurrentTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(new Date()));
|
||||
weChatMsg.setAppName("微信");
|
||||
weChatMsg.setCurrentTime(DATE_FORMAT.format(new Date()));
|
||||
|
||||
Timber.d("准备发送微信消息: %s", weChatMsg);
|
||||
// 异步执行网络请求
|
||||
try {
|
||||
Timber.d("准备将接受的微信通知转发: %s", weChatMsg);
|
||||
networkUtil.postRequest(weChatMsg);
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
Timber.e(e, "转发送微信通知失败");
|
||||
}
|
||||
|
||||
// 检查是否在30秒内已打印过相同内容
|
||||
if (!shouldPrintLog(logMessage)) {
|
||||
return; // 如果在30秒内已打印过,则跳过
|
||||
}
|
||||
|
||||
// Timber.d(logMessage);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onNotificationRemoved(StatusBarNotification sbn) {
|
||||
// 当通知被移除时调用
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
package com.nbee.echolink.utils;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.Log;
|
||||
|
||||
public class DeviceInfoUtils {
|
||||
/**
|
||||
* 获取设备宽度(px)
|
||||
*
|
||||
*/
|
||||
public static int getDeviceWidth(Context context) {
|
||||
return context.getResources().getDisplayMetrics().widthPixels;
|
||||
@@ -20,6 +22,7 @@ public class DeviceInfoUtils {
|
||||
public static int getDeviceHeight(Context context) {
|
||||
return context.getResources().getDisplayMetrics().heightPixels;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取厂商名
|
||||
**/
|
||||
@@ -63,8 +66,6 @@ public class DeviceInfoUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* fingerprit 信息
|
||||
**/
|
||||
public static String getDeviceFubgerprint() {
|
||||
@@ -73,7 +74,6 @@ public class DeviceInfoUtils {
|
||||
|
||||
/**
|
||||
* 硬件名
|
||||
*
|
||||
**/
|
||||
public static String getDeviceHardware() {
|
||||
return android.os.Build.HARDWARE;
|
||||
@@ -81,14 +81,12 @@ public class DeviceInfoUtils {
|
||||
|
||||
/**
|
||||
* 主机
|
||||
*
|
||||
**/
|
||||
public static String getDeviceHost() {
|
||||
return android.os.Build.HOST;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 显示ID
|
||||
**/
|
||||
public static String getDeviceDisplay() {
|
||||
@@ -97,15 +95,24 @@ public class DeviceInfoUtils {
|
||||
|
||||
/**
|
||||
* ID
|
||||
*
|
||||
**/
|
||||
public static String getDeviceId() {
|
||||
return android.os.Build.ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取手机用户名
|
||||
* 获取设备的Android ID。
|
||||
*
|
||||
* @param context 上下文对象,用于访问应用特定的资源和类。
|
||||
* @return 设备唯一的Android ID,是一个64位的十进制字符串。
|
||||
*/
|
||||
public static String getAndroidID(Context context) {
|
||||
// 通过Settings.Secure.getString获取设备的Android ID
|
||||
return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取手机用户名
|
||||
**/
|
||||
public static String getDeviceUser() {
|
||||
return android.os.Build.USER;
|
||||
@@ -115,9 +122,10 @@ public class DeviceInfoUtils {
|
||||
* 获取手机 硬件序列号
|
||||
**/
|
||||
public static String getDeviceSerial() {
|
||||
return android.os.Build.SERIAL;
|
||||
return "89KX0ARVK";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取手机Android 系统SDK
|
||||
*
|
||||
@@ -143,21 +151,4 @@ public class DeviceInfoUtils {
|
||||
return Locale.getDefault().getLanguage();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前系统上的语言列表(Locale列表)
|
||||
*/
|
||||
public static String getDeviceSupportLanguage() {
|
||||
Log.e("wangjie", "Local:" + Locale.GERMAN);
|
||||
Log.e("wangjie", "Local:" + Locale.ENGLISH);
|
||||
Log.e("wangjie", "Local:" + Locale.US);
|
||||
Log.e("wangjie", "Local:" + Locale.CHINESE);
|
||||
Log.e("wangjie", "Local:" + Locale.TAIWAN);
|
||||
Log.e("wangjie", "Local:" + Locale.FRANCE);
|
||||
Log.e("wangjie", "Local:" + Locale.FRENCH);
|
||||
Log.e("wangjie", "Local:" + Locale.GERMANY);
|
||||
Log.e("wangjie", "Local:" + Locale.ITALIAN);
|
||||
Log.e("wangjie", "Local:" + Locale.JAPAN);
|
||||
Log.e("wangjie", "Local:" + Locale.JAPANESE);
|
||||
return Locale.getAvailableLocales().toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user