调整电量消息频率以及消息内容。

This commit is contained in:
2025-12-20 16:30:34 +08:00
parent 6af2096b30
commit 65acbfcd04
4 changed files with 68 additions and 70 deletions

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle #Created by .winboll/winboll_app_build.gradle
#Sat Dec 20 07:53:57 GMT 2025 #Sat Dec 20 08:27:44 GMT 2025
stageCount=10 stageCount=10
libraryProject= libraryProject=
baseVersion=15.14 baseVersion=15.14
publishVersion=15.14.9 publishVersion=15.14.9
buildCount=61 buildCount=70
baseBetaVersion=15.14.10 baseBetaVersion=15.14.10

View File

@@ -29,8 +29,8 @@ public class ControlCenterServiceHandler extends Handler {
// 通知文案常量(抽离魔法值,便于统一修改) // 通知文案常量(抽离魔法值,便于统一修改)
private static final String CHARGE_REMIND_TITLE = "充电提醒"; private static final String CHARGE_REMIND_TITLE = "充电提醒";
private static final String USAGE_REMIND_TITLE = "耗电提醒"; private static final String USAGE_REMIND_TITLE = "耗电提醒";
private static final String CHARGE_REMIND_CONTENT_FORMAT = "(+) 当前电量%d%%%s,已达标建议及时断电,保护电池寿命~"; private static final String CHARGE_REMIND_CONTENT_FORMAT = "(+)电量已达额定值。当前电量%d%%%s";
private static final String USAGE_REMIND_CONTENT_FORMAT = "(-) 当前电量%d%%%s,已偏低建议及时充电,避免设备关机~"; private static final String USAGE_REMIND_CONTENT_FORMAT = "(-)电量低于指定值。当前电量%d%%%s";
private static final String CHARGE_STATE_CHARGING = "充电中"; private static final String CHARGE_STATE_CHARGING = "充电中";
private static final String CHARGE_STATE_NOT_CHARGING = "未充电"; private static final String CHARGE_STATE_NOT_CHARGING = "未充电";

View File

@@ -29,7 +29,7 @@ public class AppConfigBean extends BaseBean implements Serializable, Parcelable
int reminderIntervalTime = 5000; // 铃声提醒间隔ms原有 int reminderIntervalTime = 5000; // 铃声提醒间隔ms原有
boolean isCharging = false; // 是否充电(状态字段,原有) boolean isCharging = false; // 是否充电(状态字段,原有)
int currentBatteryValue = -1; // 修正统一命名为「currentBatteryValue」原 currentValue int currentBatteryValue = -1; // 修正统一命名为「currentBatteryValue」原 currentValue
int batteryDetectInterval = 1000; // 新增电量检测间隔ms适配 RemindThread int batteryDetectInterval = 2000; // 新增电量检测间隔ms适配 RemindThread
// 构造方法:初始化默认配置(同步修正字段名,统一默认值) // 构造方法:初始化默认配置(同步修正字段名,统一默认值)
public AppConfigBean() { public AppConfigBean() {

View File

@@ -18,8 +18,7 @@ public class RemindThread extends Thread {
public static final String TAG = "RemindThread"; public static final String TAG = "RemindThread";
// 时间常量 (ms) // 时间常量 (ms)
private static final int MIN_SLEEP_TIME = 500; private static final int MIN_SLEEP_TIME = 2000;
private static final int DEFAULT_SLEEP_TIME = 1000;
private static final long THREAD_JOIN_TIMEOUT = 1000L; private static final long THREAD_JOIN_TIMEOUT = 1000L;
// 状态常量 // 状态常量
@@ -53,7 +52,7 @@ public class RemindThread extends Thread {
private volatile boolean isCharging; private volatile boolean isCharging;
// 并发安全锁(保护线程状态变更) // 并发安全锁(保护线程状态变更)
private final Object mLock = new Object(); private final static Object sRemindLock = new Object();
// ================================== 私有构造器(单例专用,禁止外部实例化)================================= // ================================== 私有构造器(单例专用,禁止外部实例化)=================================
private RemindThread(Context context, ControlCenterServiceHandler handler) { private RemindThread(Context context, ControlCenterServiceHandler handler) {
@@ -93,31 +92,33 @@ public class RemindThread extends Thread {
*/ */
public static boolean startRemindThreadWithAppConfig(Context context, ControlCenterServiceHandler handler, AppConfigBean config) { public static boolean startRemindThreadWithAppConfig(Context context, ControlCenterServiceHandler handler, AppConfigBean config) {
LogUtils.d(TAG, "startRemindThreadWithAppConfig执行 | context=" + context + " | handler=" + handler + " | config=" + config); LogUtils.d(TAG, "startRemindThreadWithAppConfig执行 | context=" + context + " | handler=" + handler + " | config=" + config);
// 入参严格校验 synchronized (RemindThread.class) {
if (context == null || handler == null || config == null) { // 入参严格校验
LogUtils.e(TAG, "启动失败:入参为空 | context=" + context + " | handler=" + handler + " | config=" + config); if (context == null || handler == null || config == null) {
return false; LogUtils.e(TAG, "启动失败:入参为空 | context=" + context + " | handler=" + handler + " | config=" + config);
} return false;
}
RemindThread instance = getInstance(context, handler); RemindThread instance = getInstance(context, handler);
// 已在提醒状态,仅同步配置 // 已在提醒状态,仅同步配置
if (instance.isReminding) { if (instance.isReminding) {
instance.setAppConfigBean(config); instance.setAppConfigBean(config);
LogUtils.d(TAG, "线程已在运行,同步最新配置 | threadId=" + instance.getId()); LogUtils.d(TAG, "线程已在运行,同步最新配置 | threadId=" + instance.getId());
return true; return true;
} }
// 同步配置并启动线程 // 同步配置并启动线程
instance.setAppConfigBean(config); instance.setAppConfigBean(config);
if (!instance.isRunning()) { if (!instance.isRunning()) {
instance.isExist = false; instance.isExist = false;
instance.start(); instance.start();
LogUtils.d(TAG, "线程启动成功 | threadId=" + instance.getId()); LogUtils.d(TAG, "线程启动成功 | threadId=" + instance.getId());
return true; return true;
} else { } else {
LogUtils.d(TAG, "线程已在运行状态 | threadId=" + instance.getId()); LogUtils.d(TAG, "线程已在运行状态 | threadId=" + instance.getId());
return true; return true;
} }
}
} }
/** /**
@@ -130,33 +131,35 @@ public class RemindThread extends Thread {
*/ */
public static boolean startRemindThreadWithBatteryInfo(Context context, ControlCenterServiceHandler handler, boolean isCharging, int lastBatteryLevel) { public static boolean startRemindThreadWithBatteryInfo(Context context, ControlCenterServiceHandler handler, boolean isCharging, int lastBatteryLevel) {
LogUtils.d(TAG, "startRemindThreadWithBatteryInfo执行 | context=" + context + " | handler=" + handler + " | isCharging=" + isCharging + " | lastBatteryLevel=" + lastBatteryLevel); LogUtils.d(TAG, "startRemindThreadWithBatteryInfo执行 | context=" + context + " | handler=" + handler + " | isCharging=" + isCharging + " | lastBatteryLevel=" + lastBatteryLevel);
// 入参严格校验 synchronized (RemindThread.class) {
if (context == null || handler == null) { // 入参严格校验
LogUtils.e(TAG, "启动失败:入参为空 | context=" + context + " | handler=" + handler); if (context == null || handler == null) {
return false; LogUtils.e(TAG, "启动失败:入参为空 | context=" + context + " | handler=" + handler);
} return false;
}
RemindThread instance = getInstance(context, handler); RemindThread instance = getInstance(context, handler);
// 已在提醒状态,仅同步电池信息 // 已在提醒状态,仅同步电池信息
if (instance.isReminding) { if (instance.isReminding) {
instance.isCharging = isCharging; instance.isCharging = isCharging;
instance.quantityOfElectricity = lastBatteryLevel; instance.quantityOfElectricity = lastBatteryLevel;
LogUtils.d(TAG, "线程已在运行,同步电池信息 | threadId=" + instance.getId() + " | isCharging=" + isCharging + " | lastBatteryLevel=" + lastBatteryLevel); LogUtils.d(TAG, "线程已在运行,同步电池信息 | threadId=" + instance.getId() + " | isCharging=" + isCharging + " | lastBatteryLevel=" + lastBatteryLevel);
return true; return true;
} }
// 同步电池信息并启动线程 // 同步电池信息并启动线程
instance.isCharging = isCharging; instance.isCharging = isCharging;
instance.quantityOfElectricity = lastBatteryLevel; instance.quantityOfElectricity = lastBatteryLevel;
if (!instance.isRunning()) { if (!instance.isRunning()) {
instance.isExist = false; instance.isExist = false;
instance.start(); instance.start();
LogUtils.d(TAG, "线程启动成功 | threadId=" + instance.getId()); LogUtils.d(TAG, "线程启动成功 | threadId=" + instance.getId());
return true; return true;
} else { } else {
LogUtils.d(TAG, "线程已在运行状态 | threadId=" + instance.getId()); LogUtils.d(TAG, "线程已在运行状态 | threadId=" + instance.getId());
return true; return true;
} }
}
} }
/** /**
@@ -223,15 +226,11 @@ public class RemindThread extends Thread {
LogUtils.d(TAG, "run执行 | threadId=" + getId() + " | 状态=" + getState()); LogUtils.d(TAG, "run执行 | threadId=" + getId() + " | 状态=" + getState());
// 初始化提醒状态(加锁保护,避免多线程竞争) // 初始化提醒状态(加锁保护,避免多线程竞争)
synchronized (mLock) { synchronized (sRemindLock) {
if (!isExist && !isReminding) { if (isReminding) {
isReminding = true;
LogUtils.d(TAG, "提醒状态初始化成功 | isReminding=true");
} else {
LogUtils.d(TAG, "线程退出条件满足 | isExist=" + isExist + " | isReminding=" + isReminding);
cleanThreadStateInternal();
return; return;
} }
isReminding = true;
} }
// 核心电量检测循环 // 核心电量检测循环
@@ -241,11 +240,10 @@ public class RemindThread extends Thread {
// 快速退出判断 // 快速退出判断
if (isExist) break; if (isExist) break;
// 电量有效性校验非0-100视为无效 // 电量有效性校验非0-100视为无效,退出电量提醒线程
if (quantityOfElectricity < BATTERY_LEVEL_MIN || quantityOfElectricity > BATTERY_LEVEL_MAX) { if (quantityOfElectricity < BATTERY_LEVEL_MIN || quantityOfElectricity > BATTERY_LEVEL_MAX) {
LogUtils.w(TAG, "电量无效,跳过本次检测 | 当前电量=" + quantityOfElectricity); LogUtils.w(TAG, "电量无效,退出电量提醒线程 | 当前电量=" + quantityOfElectricity);
safeSleepInternal(sleepTime); break;
continue;
} }
// 充电提醒触发逻辑 // 充电提醒触发逻辑
@@ -260,8 +258,8 @@ public class RemindThread extends Thread {
// 安全休眠,保留中断标记 // 安全休眠,保留中断标记
safeSleepInternal(sleepTime); safeSleepInternal(sleepTime);
} catch (Exception e) { } catch (Exception e) {
LogUtils.e(TAG, "循环运行异常,休眠重试", e); LogUtils.e(TAG, "循环运行异常,退出电量提醒线程 | 当前电量=" + quantityOfElectricity);
safeSleepInternal(sleepTime); break;
} }
} }
@@ -333,7 +331,7 @@ public class RemindThread extends Thread {
// 配置参数初始化 // 配置参数初始化
isEnableChargeReminder = false; isEnableChargeReminder = false;
isEnableUsageReminder = false; isEnableUsageReminder = false;
sleepTime = DEFAULT_SLEEP_TIME; sleepTime = MIN_SLEEP_TIME;
chargeReminderValue = -1; chargeReminderValue = -1;
usageReminderValue = -1; usageReminderValue = -1;
quantityOfElectricity = INVALID_BATTERY_VALUE; quantityOfElectricity = INVALID_BATTERY_VALUE;