修复TTS语音服务在应用重启时,会播放的问题,TTS语音服务设定在充电状态与放电状态切换时播放。

This commit is contained in:
2025-12-30 18:45:10 +08:00
parent 10348d2c8d
commit 2f42334f19
2 changed files with 6 additions and 4 deletions

View File

@@ -36,9 +36,10 @@ public class ControlCenterServiceReceiver extends BroadcastReceiver {
private static final int BROADCAST_PRIORITY = IntentFilter.SYSTEM_HIGH_PRIORITY - 10;
private static final int BATTERY_LEVEL_MIN = 0;
private static final int BATTERY_LEVEL_MAX = 100;
private static final int INVALID_BATTERY = -1; // 无效电量标识
// ====================== 静态状态标记volatile保证多线程可见性 ======================
private static volatile int sLastBatteryLevel = -1; // 上次电量(多线程可见)
private static volatile int sLastBatteryLevel = INVALID_BATTERY; // 上次电量(多线程可见)
private static volatile boolean sIsCharging = false; // 上次充电状态(多线程可见)
// ====================== 成员变量区(弱引用防泄漏,按功能分层) ======================
@@ -113,7 +114,8 @@ public class ControlCenterServiceReceiver extends BroadcastReceiver {
}
// 在插拔充电线时,执行贴心服务
if(currentCharging != sIsCharging) {
if(currentCharging != sIsCharging && sLastBatteryLevel != INVALID_BATTERY) {
//App.notifyMessage(TAG, String.format("sLastBatteryLevel %d", sLastBatteryLevel));
if(currentCharging) {
ThoughtfulService.startServiceWithType(service, ThoughtfulService.ServiceType.CHARGE_STATE);
} else {