From 44d7fe941a0e4b9732a2a963618a69960acc4975 Mon Sep 17 00:00:00 2001 From: wangyantian Date: Thu, 10 Apr 2025 17:58:15 +0800 Subject: [PATCH] feat: power state callback adds reason param Signed-off-by: wangyantian --- .../include/bundle_active_power_state_callback_service.h | 4 +++- .../src/bundle_active_power_state_callback_service.cpp | 4 +++- .../bundleactivepowerstatecallbackproxy_fuzzer.cpp | 3 ++- test/unittest/bundle_active_total_test.cpp | 6 +++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/services/common/include/bundle_active_power_state_callback_service.h b/services/common/include/bundle_active_power_state_callback_service.h index 06d9335..ed48265 100644 --- a/services/common/include/bundle_active_power_state_callback_service.h +++ b/services/common/include/bundle_active_power_state_callback_service.h @@ -22,11 +22,13 @@ namespace OHOS { namespace DeviceUsageStats { using OHOS::PowerMgr::PowerState; +using OHOS::PowerMgr::StateChangeReason; class BundleActivePowerStateCallbackService : public PowerMgr::PowerStateCallbackStub { public: BundleActivePowerStateCallbackService(std::shared_ptr bundleActiveCore); virtual ~BundleActivePowerStateCallbackService() {} - void OnPowerStateChanged(PowerState state) override; + void OnPowerStateChanged(PowerState state, StateChangeReason __attribute__((unused)) reason) override; + private: std::shared_ptr bundleActiveCore_; }; diff --git a/services/common/src/bundle_active_power_state_callback_service.cpp b/services/common/src/bundle_active_power_state_callback_service.cpp index 77d36f4..76f496f 100644 --- a/services/common/src/bundle_active_power_state_callback_service.cpp +++ b/services/common/src/bundle_active_power_state_callback_service.cpp @@ -20,6 +20,7 @@ namespace OHOS { namespace DeviceUsageStats { using OHOS::PowerMgr::PowerState; +using OHOS::PowerMgr::StateChangeReason; BundleActivePowerStateCallbackService::BundleActivePowerStateCallbackService( std::shared_ptr bundleActiveCore) { @@ -28,7 +29,8 @@ BundleActivePowerStateCallbackService::BundleActivePowerStateCallbackService( } } -void BundleActivePowerStateCallbackService::OnPowerStateChanged(PowerState state) +void BundleActivePowerStateCallbackService::OnPowerStateChanged( + PowerState state, StateChangeReason __attribute__((unused)) reason) { int32_t eventId; BUNDLE_ACTIVE_LOGD("BundleActDvePowerStateCallbackService::OnPowerStateChanged power state is %{public}u", state); diff --git a/test/fuzztest/bundleactivepowerstatecallbackproxy_fuzzer/bundleactivepowerstatecallbackproxy_fuzzer.cpp b/test/fuzztest/bundleactivepowerstatecallbackproxy_fuzzer/bundleactivepowerstatecallbackproxy_fuzzer.cpp index 0a3488e..dba21c2 100644 --- a/test/fuzztest/bundleactivepowerstatecallbackproxy_fuzzer/bundleactivepowerstatecallbackproxy_fuzzer.cpp +++ b/test/fuzztest/bundleactivepowerstatecallbackproxy_fuzzer/bundleactivepowerstatecallbackproxy_fuzzer.cpp @@ -91,7 +91,8 @@ namespace DeviceUsageStats { PowerMgr::PowerState state = static_cast(code); auto bundleActiveCore = std::make_shared(); BundleActivePowerStateCallbackService BundleActivePowerStateCallbackService(bundleActiveCore); - BundleActivePowerStateCallbackService.OnPowerStateChanged(state); + BundleActivePowerStateCallbackService.OnPowerStateChanged( + state, PowerMgr::StateChangeReason::STATE_CHANGE_REASON_APPLICATION); return true; } diff --git a/test/unittest/bundle_active_total_test.cpp b/test/unittest/bundle_active_total_test.cpp index 3f8c01e..9a0a6c1 100644 --- a/test/unittest/bundle_active_total_test.cpp +++ b/test/unittest/bundle_active_total_test.cpp @@ -327,10 +327,10 @@ HWTEST_F(BundleActiveTotalTest, BundleActivePowerStateCallbackServiceTest_001, F std::shared_ptr bundleActiveCore = std::make_shared(); BundleActivePowerStateCallbackService test2(bundleActiveCore); - - test2.OnPowerStateChanged(PowerState::AWAKE); + + test2.OnPowerStateChanged(PowerState::AWAKE, PowerMgr::StateChangeReason::STATE_CHANGE_REASON_APPLICATION); SUCCEED(); - test2.OnPowerStateChanged(PowerState::SLEEP); + test2.OnPowerStateChanged(PowerState::SLEEP, PowerMgr::StateChangeReason::STATE_CHANGE_REASON_APPLICATION); EXPECT_TRUE(test2.bundleActiveCore_ != nullptr); #endif } -- Gitee