调整电量消息频率以及消息内容。
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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 = "未充电";
|
||||||
|
|
||||||
|
|||||||
@@ -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() {
|
||||||
|
|||||||
@@ -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,6 +92,7 @@ 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) {
|
if (context == null || handler == null || config == null) {
|
||||||
LogUtils.e(TAG, "启动失败:入参为空 | context=" + context + " | handler=" + handler + " | config=" + config);
|
LogUtils.e(TAG, "启动失败:入参为空 | context=" + context + " | handler=" + handler + " | config=" + config);
|
||||||
@@ -119,6 +119,7 @@ public class RemindThread extends Thread {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动提醒线程,同步电池信息
|
* 启动提醒线程,同步电池信息
|
||||||
@@ -130,6 +131,7 @@ 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) {
|
if (context == null || handler == null) {
|
||||||
LogUtils.e(TAG, "启动失败:入参为空 | context=" + context + " | handler=" + handler);
|
LogUtils.e(TAG, "启动失败:入参为空 | context=" + context + " | handler=" + handler);
|
||||||
@@ -158,6 +160,7 @@ public class RemindThread extends Thread {
|
|||||||
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user