OpenHarmony 5.0状态栏息屏状态下充电然后亮屏会出现电量跳变情况
1.背景
在OpenHarmony 5.0中在息屏状态下充电一段时间突然亮屏,状态栏的电量会出现跳变情况
2.解决方案
是由于有一个策略导致在息屏状态下会关闭对底层的电量监听,然后在亮屏状态下在打开此监听,所以导致在亮屏状态下会有电池电量跳变情况
解决方案patch如下:
--- a/XXX/OHOS_5.0_ScreenLock/features/batterycomponent/src/main/ets/default/batteryModel.ts
+++ b/XXX/OHOS_5.0_ScreenLock/features/batterycomponent/src/main/ets/default/batteryModel.ts
@@ -60,7 +60,7 @@ export class BatteryModel {this.mBatterySoc = AppStorage.SetAndLink("batterySoc", 0);this.mBatteryCharging = AppStorage.SetAndLink("batteryCharging", false);this.mManager.subscriberCommonEvent();
- this.mManager.applyPolicy([POLICY.SCREEN_POLICY]);
+ // this.mManager.applyPolicy([POLICY.SCREEN_POLICY]);}unInitBatteryModel() {
--
GitLab
上述是对锁屏的电量跳变问题解决方案,如果想更进一步优化,在极端情况下亮屏立即打开锁屏状态栏也不会跳变的话则需要在systemui的状态栏中进行优化,如下:
--- a/xxx/OHOS_5.0_SystemUI/features/batterycomponent/src/main/ets/default/batteryModel.ets
+++ b/xxx/OHOS_5.0_SystemUI/features/batterycomponent/src/main/ets/default/batteryModel.ets
@@ -115,7 +115,7 @@ export class BatteryModel {this.mBatterySoc = AppStorage.SetAndLink("batterySoc", 0);this.mBatteryCharging = AppStorage.SetAndLink("batteryCharging", false);this.mManager.subscriberCommonEvent();
- this.mManager.applyPolicy([POLICY.SCREEN_POLICY]);
+ // this.mManager.applyPolicy([POLICY.SCREEN_POLICY]);}unInitBatteryModel() {
--