fix: Adapt system level sleep level and sleep framework

Signed-off-by: yangziyong <nsyangziyong@huawei.com>
Change-Id: I086ba81e75f92c7f32fa5c87cc681aa6f9020a5b
This commit is contained in:
yangziyong 2023-03-17 16:34:21 +08:00
parent abdffa76c8
commit 7698c39cee
8 changed files with 268 additions and 1 deletions

View File

@ -57,7 +57,7 @@ enum class PowerState : uint32_t {
AWAKE = 0,
/**
* Power State: screen on or off and some background user processes are frozen.
* Power State: screen on or active and some background user processes are frozen.
*/
FREEZE,

View File

@ -43,3 +43,7 @@ STATE_CORRECTION:
CORRECTION_STATE: {type: INT32, desc: the corrected state}
DISPLAY_STATE: {type: INT32, desc: the display state}
MSG: {type: STRING, desc: correct error information}
STATE:
__BASE: {type: STATISTIC, level: MINOR, tag: PowerStats, desc: power state}
STATE: {type: INT32, desc: power state}

View File

@ -527,10 +527,20 @@ static const std::string GetPowerStateString(PowerState state)
switch (state) {
case PowerState::AWAKE:
return std::string("AWAKE");
case PowerState::FREEZE:
return std::string("FREEZE");
case PowerState::INACTIVE:
return std::string("INACTIVE");
case PowerState::STAND_BY:
return std::string("STAND_BY");
case PowerState::DOZE:
return std::string("DOZE");
case PowerState::SLEEP:
return std::string("SLEEP");
case PowerState::HIBERNATE:
return std::string("HIBERNATE");
case PowerState::SHUTDOWN:
return std::string("SHUTDOWN");
case PowerState::UNKNOWN:
return std::string("UNKNOWN");
default:
@ -596,6 +606,8 @@ void PowerStateMachine::NotifyPowerStateChanged(PowerState state)
{
POWER_HILOGI(FEATURE_POWER_STATE, "state = %{public}u, listeners.size = %{public}zu",
state, powerStateListeners_.size());
HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::POWER, "STATE",
HiviewDFX::HiSysEvent::EventType::STATISTIC, "STATE", static_cast<uint32_t>(state));
std::lock_guard lock(mutex_);
int64_t now = GetTickCount();
// Send Notification event

View File

@ -309,6 +309,9 @@ ohos_unittest("ces_system") {
ohos_unittest("test_power_state_level_framework") {
module_out_path = module_output_path
resource_config_file =
"${powermgr_service_path}/native/test/unittest/resources/ohos_test.xml"
sources = [ "src/power_state_level_framework_test.cpp" ]
configs = [

View File

@ -30,6 +30,8 @@ constexpr uint32_t HIBERNATE = 6;
constexpr uint32_t SHUTDOWN = 7;
class PowerStateLevelFrameworkTest : public testing::Test {
public:
static void SetUpTestCase();
};
} // namespace PowerMgr
} // namespace OHOS

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 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
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<configuration ver="2.0">
<target name="test_power_state_level_framework">
<preparer>
<option name="shell" value="mkdir /vendor/etc/power_config" src="res"/>
<option name="push" value="push_xml/power_mode_config.xml -> /vendor/etc/power_config/" src="res"/>
</preparer>
</target>
</configuration>

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright (c) 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
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!--
Power Mode Definitions:
MODE_NORMAL = 600,
MODE_POWER_SAVE = 601,
MODE_PERFORMANCE = 602,
MODE_EXTREME_POWER_SAVE = 603,
-->
<!--
Action Definitions:
DisplayOffTime = 101,
SystemAutoSleepTime = 102,
AutoAdjustBrightness = 103,
AutoWindowRotation = 107,
SystemBrightness = 115,
VibratorsState = 120,
-->
<switch_proxy version="1">
<proxy id="600">
<switch id="101" value="30000" recover_flag="0"/>
<switch id="102" value="30000" recover_flag="0"/>
<switch id="103" value="-1" recover_flag="0"/>
<switch id="107" value="1" recover_flag="0"/>
<switch id="115" value="102" recover_flag="0"/>
<switch id="120" value="1" recover_flag="0"/>
</proxy>
<proxy id="601">
<switch id="101" value="10000" recover_flag="0"/>
<switch id="102" value="5000" recover_flag="0"/>
<switch id="103" value="-1" recover_flag="0"/>
<switch id="107" value="-1" recover_flag="0"/>
<switch id="115" value="50" recover_flag="0"/>
<switch id="120" value="-1" recover_flag="0"/>
</proxy>
<proxy id="602">
<switch id="101" value="-1" recover_flag="0"/>
<switch id="102" value="-1" recover_flag="0"/>
<switch id="103" value="-1" recover_flag="0"/>
<switch id="107" value="1" recover_flag="0"/>
<switch id="115" value="255" recover_flag="0"/>
<switch id="120" value="1" recover_flag="0"/>
</proxy>
<proxy id="603">
<switch id="101" value="5000" recover_flag="0"/>
<switch id="102" value="1000" recover_flag="0"/>
<switch id="103" value="-1" recover_flag="0"/>
<switch id="107" value="-1" recover_flag="0"/>
<switch id="115" value="25" recover_flag="0"/>
<switch id="120" value="-1" recover_flag="0"/>
</proxy>
</switch_proxy>

View File

@ -20,6 +20,8 @@
#include <gtest/gtest.h>
#include <string_ex.h>
#include "power_mgr_service.h"
#include "power_state_machine.h"
#include "power_state_machine_info.h"
using namespace testing::ext;
@ -27,6 +29,17 @@ using namespace OHOS::PowerMgr;
using namespace OHOS;
using namespace std;
sptr<PowerMgrService> g_pmsTest;
std::shared_ptr<PowerStateMachine> g_stateMachineTest;
void PowerStateLevelFrameworkTest::SetUpTestCase()
{
g_pmsTest = DelayedSpSingleton<PowerMgrService>::GetInstance();
EXPECT_TRUE(g_pmsTest != nullptr) << "PowerMgrService02 fail to get PowerMgrService";
g_pmsTest->OnStart();
g_stateMachineTest = g_pmsTest->GetPowerStateMachine();
}
namespace {
/**
* @tc.name: PowerStateLevelFramework001
@ -47,4 +60,148 @@ HWTEST_F (PowerStateLevelFrameworkTest, PowerStateLevelFramework001, TestSize.Le
EXPECT_TRUE(static_cast<uint32_t>(PowerState::SHUTDOWN) == SHUTDOWN) << "PowerState HIBERNATE correct";
GTEST_LOG_(INFO) << "PowerStateLevelFramework001: test system-level sleep level enumeration is end";
}
/**
* @tc.name: PowerStateLevelFramework002
* @tc.desc: test the conversion between power states
* @tc.type: FUNC
* @tc.require: issueI6OM1F
*/
HWTEST_F (PowerStateLevelFrameworkTest, PowerStateLevelFramework002, TestSize.Level0)
{
GTEST_LOG_(INFO) << "PowerStateLevelFramework002: power state replacement is start";
auto ret = g_stateMachineTest->SetState(PowerState::AWAKE, StateChangeReason::STATE_CHANGE_REASON_INIT);
EXPECT_TRUE(ret);
EXPECT_TRUE(g_stateMachineTest->GetState() == PowerState::AWAKE);
GTEST_LOG_(INFO) << "PowerStateLevelFramework002: power state replacement is end";
}
/**
* @tc.name: PowerStateLevelFramework003
* @tc.desc: test the conversion between power states
* @tc.type: FUNC
* @tc.require: issueI6OM1F
*/
HWTEST_F (PowerStateLevelFrameworkTest, PowerStateLevelFramework003, TestSize.Level0)
{
GTEST_LOG_(INFO) << "PowerStateLevelFramework003: power state replacement is start";
auto ret = g_stateMachineTest->SetState(PowerState::FREEZE, StateChangeReason::STATE_CHANGE_REASON_INIT);
EXPECT_TRUE(ret);
EXPECT_TRUE(g_stateMachineTest->GetState() == PowerState::FREEZE);
GTEST_LOG_(INFO) << "PowerStateLevelFramework003: power state replacement is end";
}
/**
* @tc.name: PowerStateLevelFramework004
* @tc.desc: test the conversion between power states
* @tc.type: FUNC
* @tc.require: issueI6OM1F
*/
HWTEST_F (PowerStateLevelFrameworkTest, PowerStateLevelFramework004, TestSize.Level0)
{
GTEST_LOG_(INFO) << "PowerStateLevelFramework004: power state replacement is start";
auto ret = g_stateMachineTest->SetState(PowerState::INACTIVE, StateChangeReason::STATE_CHANGE_REASON_INIT);
EXPECT_TRUE(ret);
EXPECT_TRUE(g_stateMachineTest->GetState() == PowerState::INACTIVE);
GTEST_LOG_(INFO) << "PowerStateLevelFramework004: power state replacement is end";
}
/**
* @tc.name: PowerStateLevelFramework005
* @tc.desc: test the conversion between power states
* @tc.type: FUNC
* @tc.require: issueI6OM1F
*/
HWTEST_F (PowerStateLevelFrameworkTest, PowerStateLevelFramework005, TestSize.Level0)
{
GTEST_LOG_(INFO) << "PowerStateLevelFramework005: power state replacement is start";
auto ret = g_stateMachineTest->SetState(PowerState::STAND_BY, StateChangeReason::STATE_CHANGE_REASON_INIT);
EXPECT_TRUE(ret);
EXPECT_TRUE(g_stateMachineTest->GetState() == PowerState::STAND_BY);
GTEST_LOG_(INFO) << "PowerStateLevelFramework005: power state replacement is end";
}
/**
* @tc.name: PowerStateLevelFramework006
* @tc.desc: test the conversion between power states
* @tc.type: FUNC
* @tc.require: issueI6OM1F
*/
HWTEST_F (PowerStateLevelFrameworkTest, PowerStateLevelFramework006, TestSize.Level0)
{
GTEST_LOG_(INFO) << "PowerStateLevelFramework006: power state replacement is start";
auto ret = g_stateMachineTest->SetState(PowerState::DOZE, StateChangeReason::STATE_CHANGE_REASON_INIT);
EXPECT_TRUE(ret);
EXPECT_TRUE(g_stateMachineTest->GetState() == PowerState::DOZE);
GTEST_LOG_(INFO) << "PowerStateLevelFramework006: power state replacement is end";
}
/**
* @tc.name: PowerStateLevelFramework007
* @tc.desc: test the conversion between power states
* @tc.type: FUNC
* @tc.require: issueI6OM1F
*/
HWTEST_F (PowerStateLevelFrameworkTest, PowerStateLevelFramework007, TestSize.Level0)
{
GTEST_LOG_(INFO) << "PowerStateLevelFramework007: power state replacement is start";
auto ret = g_stateMachineTest->SetState(PowerState::SLEEP, StateChangeReason::STATE_CHANGE_REASON_INIT);
EXPECT_TRUE(ret);
EXPECT_TRUE(g_stateMachineTest->GetState() == PowerState::SLEEP);
GTEST_LOG_(INFO) << "PowerStateLevelFramework007: power state replacement is end";
}
/**
* @tc.name: PowerStateLevelFramework008
* @tc.desc: test the conversion between power states
* @tc.type: FUNC
* @tc.require: issueI6OM1F
*/
HWTEST_F (PowerStateLevelFrameworkTest, PowerStateLevelFramework008, TestSize.Level0)
{
GTEST_LOG_(INFO) << "PowerStateLevelFramework008: power state replacement is start";
auto ret = g_stateMachineTest->SetState(PowerState::HIBERNATE, StateChangeReason::STATE_CHANGE_REASON_INIT);
EXPECT_TRUE(ret);
EXPECT_TRUE(g_stateMachineTest->GetState() == PowerState::HIBERNATE);
GTEST_LOG_(INFO) << "PowerStateLevelFramework008: power state replacement is end";
}
/**
* @tc.name: PowerStateLevelFramework009
* @tc.desc: test the conversion between power states
* @tc.type: FUNC
* @tc.require: issueI6OM1F
*/
HWTEST_F (PowerStateLevelFrameworkTest, PowerStateLevelFramework009, TestSize.Level0)
{
GTEST_LOG_(INFO) << "PowerStateLevelFramework009: power state replacement is start";
auto ret = g_stateMachineTest->SetState(PowerState::SHUTDOWN, StateChangeReason::STATE_CHANGE_REASON_INIT);
EXPECT_TRUE(ret);
EXPECT_TRUE(g_stateMachineTest->GetState() == PowerState::SHUTDOWN);
GTEST_LOG_(INFO) << "PowerStateLevelFramework009: power state replacement is end";
}
/**
* @tc.name: PowerStateLevelFramework010
* @tc.desc: test the conversion between power states
* @tc.type: FUNC
* @tc.require: issueI6OM1F
*/
HWTEST_F (PowerStateLevelFrameworkTest, PowerStateLevelFramework010, TestSize.Level0)
{
GTEST_LOG_(INFO) << "PowerStateLevelFramework010: power state replacement is start";
std::string result;
g_stateMachineTest->DumpInfo(result);
EXPECT_TRUE(!result.empty());
EXPECT_TRUE(result.find("AWAKE") != 0);
EXPECT_TRUE(result.find("FREEZE") != 0);
EXPECT_TRUE(result.find("INACTIVE") != 0);
EXPECT_TRUE(result.find("STAND_BY") != 0);
EXPECT_TRUE(result.find("DOZE") != 0);
EXPECT_TRUE(result.find("SLEEP") != 0);
EXPECT_TRUE(result.find("HIBERNATE") != 0);
EXPECT_TRUE(result.find("SHUTDOWN") != 0);
GTEST_LOG_(INFO) << "dumpinfo:" << result;
GTEST_LOG_(INFO) << "PowerStateLevelFramework010: power state replacement is end";
}
}