mirror of
https://gitee.com/openharmony/powermgr_power_manager
synced 2025-02-18 22:50:54 +00:00
feat: PowerState and DisplayState stability optimization
Signed-off-by: ShiJie <shijie20@huawei.com> Change-Id: I68ab85382be283809831a4f9a375c66e28bcb319
This commit is contained in:
parent
56d8bf103f
commit
a412333afb
@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
@ -36,3 +36,9 @@ SCREEN_ON_TIMEOUT:
|
||||
PACKAGE_NAME: {type: STRING, desc: package name}
|
||||
PROCESS_NAME: {type: STRING, desc: process name}
|
||||
MSG: {type: STRING, desc: screen on timeout message}
|
||||
|
||||
STATE_CORRECTION:
|
||||
__BASE: {type: FAULT, level: CRITICAL, desc: the power status is inconsistent with the display status }
|
||||
ERROR_STATE: {type: INT32, desc: the status of the current error}
|
||||
CORRECTION_STATE: {type: INT32, desc: the corrected state}
|
||||
MSG: {type: STRING, desc: correct error information}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@ -150,6 +150,8 @@ private:
|
||||
int64_t failTime_ {0};
|
||||
protected:
|
||||
bool CheckState();
|
||||
void MatchStatus(PowerState& currentState, DisplayState state);
|
||||
void CorrectionState(PowerState& currentState, PowerState correctState);
|
||||
PowerState state_;
|
||||
std::weak_ptr<PowerStateMachine> owner_;
|
||||
std::function<TransitResult(StateChangeReason)> action_;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@ -1055,11 +1055,45 @@ bool PowerStateMachine::StateController::CheckState()
|
||||
POWER_HILOGW(FEATURE_POWER_STATE, "Owner is nullptr");
|
||||
return false;
|
||||
}
|
||||
MatchStatus(owner->currentState_, owner->stateAction_->GetDisplayState());
|
||||
auto state = GetState();
|
||||
POWER_HILOGD(FEATURE_POWER_STATE, "state: %{public}u, currentState_: %{public}u", state, owner->currentState_);
|
||||
return state != owner->currentState_;
|
||||
}
|
||||
|
||||
void PowerStateMachine::StateController::CorrectionState(PowerState& currentState, PowerState correctState)
|
||||
{
|
||||
if (currentState != correctState) {
|
||||
std::string msg = "Correct power state errors ";
|
||||
msg.append(GetPowerStateString(currentState)).append(" to ").append(GetPowerStateString(correctState));
|
||||
POWER_HILOGW(FEATURE_POWER_STATE, "%{public}s", msg.c_str());
|
||||
HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::POWER, "STATE_CORRECTION",
|
||||
HiviewDFX::HiSysEvent::EventType::FAULT, "ERROR_STATE", static_cast<uint32_t>(currentState),
|
||||
"CORRECTION_STATE", static_cast<uint32_t>(correctState), "MSG", msg);
|
||||
currentState = correctState;
|
||||
}
|
||||
}
|
||||
|
||||
void PowerStateMachine::StateController::MatchStatus(PowerState& currentState, DisplayState state)
|
||||
{
|
||||
if (GetState() == PowerState::SLEEP || currentState == PowerState::SLEEP) {
|
||||
return;
|
||||
}
|
||||
// Keep the state of display consistent with the state of power
|
||||
switch (state)
|
||||
{
|
||||
case DisplayState::DISPLAY_DIM:
|
||||
case DisplayState::DISPLAY_ON:
|
||||
CorrectionState(currentState, PowerState::AWAKE);
|
||||
break;
|
||||
case DisplayState::DISPLAY_OFF:
|
||||
CorrectionState(currentState, PowerState::INACTIVE);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void PowerStateMachine::StateController::RecordFailure(PowerState from,
|
||||
StateChangeReason trigger, TransitResult failReason)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user