From c12cb1ee3e8f76c7906102d1d36392afbd75d5fb Mon Sep 17 00:00:00 2001 From: BenjaminZhang000 Date: Fri, 25 Apr 2025 17:08:28 +0800 Subject: [PATCH] feat: modify ulsr wakeup logic Signed-off-by: BenjaminZhang000 --- bundle.json | 1 + .../native/include/power_state_machine_info.h | 1 + powermgr.gni | 1 + services/BUILD.gn | 4 ++++ services/native/include/power_hdi_callback.h | 7 ++++++ .../native/profile/power_wakeup_action.json | 20 +++++++++++++++++ services/native/src/power_mgr_service.cpp | 8 ++++++- .../native/src/suspend/suspend_controller.cpp | 22 ++++++++++++------- .../native/src/suspend/suspend_controller.h | 6 ++--- .../native/src/wakeup/wakeup_controller.cpp | 16 +++++++------- .../native/src/wakeup/wakeup_controller.h | 4 ++-- .../wakeup_action_controller.cpp | 2 +- .../wakeup_action/wakeup_action_controller.h | 2 +- .../wakeup_action_source_parser.cpp | 9 +++----- 14 files changed, 73 insertions(+), 30 deletions(-) diff --git a/bundle.json b/bundle.json index 27569aa0..ff9d5bbd 100644 --- a/bundle.json +++ b/bundle.json @@ -31,6 +31,7 @@ "power_manager_feature_wakeup_action", "power_manager_feature_power_dialog", "power_manager_feature_enable_s4", + "power_manager_feature_enable_ulsr", "power_manager_feature_audio_lock_unproxy", "power_manager_feature_doubleclick", "power_manager_feature_pickup", diff --git a/interfaces/inner_api/native/include/power_state_machine_info.h b/interfaces/inner_api/native/include/power_state_machine_info.h index 00924d3f..b34f9099 100644 --- a/interfaces/inner_api/native/include/power_state_machine_info.h +++ b/interfaces/inner_api/native/include/power_state_machine_info.h @@ -167,6 +167,7 @@ enum class WakeupDeviceType : uint32_t { WAKEUP_DEVICE_PLUG_CHANGE = 31, WAKEUP_DEVICE_TENT_MODE_CHANGE = 32, WAKEUP_DEVICE_END_DREAM = 33, + WAKEUP_DEVICE_FROM_ULSR = 34, WAKEUP_DEVICE_MAX }; diff --git a/powermgr.gni b/powermgr.gni index 374bd188..40d0d6cb 100644 --- a/powermgr.gni +++ b/powermgr.gni @@ -25,6 +25,7 @@ declare_args() { power_manager_feature_wakeup_action = false power_manager_feature_power_dialog = true power_manager_feature_enable_s4 = false + power_manager_feature_enable_ulsr = false power_manager_feature_audio_lock_unproxy = false power_manager_feature_screen_on_timeout_check = false power_manager_feature_doubleclick = true diff --git a/services/BUILD.gn b/services/BUILD.gn index 7fce8270..d576c460 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -215,6 +215,10 @@ ohos_shared_library("powermgrservice") { ] } + if (power_manager_feature_enable_ulsr) { + defines += [ "POWER_MANAGER_ENABLE_ULSR" ] + } + if (power_manager_feature_force_sleep_broadcast) { defines += [ "POWER_MANAGER_ENABLE_FORCE_SLEEP_BROADCAST" ] } diff --git a/services/native/include/power_hdi_callback.h b/services/native/include/power_hdi_callback.h index ac189da5..cd595946 100644 --- a/services/native/include/power_hdi_callback.h +++ b/services/native/include/power_hdi_callback.h @@ -22,6 +22,13 @@ namespace OHOS { namespace PowerMgr { using namespace OHOS::HDI::Power::V1_2; + +enum class WakeupTag : int32_t { + TAG_NONE = 0, + TAG_ULSR, + TAG_INVALID +}; + class PowerHdiCallback : public IPowerHdiCallback { public: virtual ~PowerHdiCallback() {} diff --git a/services/native/profile/power_wakeup_action.json b/services/native/profile/power_wakeup_action.json index 5778295c..3bdeedf0 100644 --- a/services/native/profile/power_wakeup_action.json +++ b/services/native/profile/power_wakeup_action.json @@ -18,5 +18,25 @@ "scene": "UlsrLowRsoc", "action": 1, "description": "(such as)56 is a wakeup reason by reading node through HDI interface(GetWakeupReason)" + }, + "71": { + "scene": "UlsrWakeupLidOpen", + "action": 0, + "description": "(such as)71 is a wakeup reason by reading node through HDI interface(GetWakeupReason)" + }, + "72": { + "scene": "UlsrWakeupACIn", + "action": 0, + "description": "(such as)72 is a wakeup reason by reading node through HDI interface(GetWakeupReason)" + }, + "73": { + "scene": "UlsrWakeupPowerKey", + "action": 0, + "description": "(such as)73 is a wakeup reason by reading node through HDI interface(GetWakeupReason)" + }, + "74": { + "scene": "UlsrWakeupNearlinkRing", + "action": 0, + "description": "(such as)74 is a wakeup reason by reading node through HDI interface(GetWakeupReason)" } } \ No newline at end of file diff --git a/services/native/src/power_mgr_service.cpp b/services/native/src/power_mgr_service.cpp index 7d1a2d21..15106863 100644 --- a/services/native/src/power_mgr_service.cpp +++ b/services/native/src/power_mgr_service.cpp @@ -856,7 +856,9 @@ static const char* UNREGISTER_EXTERNAL_CONFIG = "UnregisterExternalCallback"; using WakeupFunc = std::function; using SuspendFunc = std::function; using PowerConfigFunc = std::function; -typedef void (*FuncRegisterExternalCallback)(WakeupFunc, SuspendFunc, PowerConfigFunc, PowerConfigFunc); +using TriggerSyncSleepCallbackFunc = std::function; +typedef void (*FuncRegisterExternalCallback)(WakeupFunc, SuspendFunc, PowerConfigFunc, PowerConfigFunc, + TriggerSyncSleepCallbackFunc); typedef void (*FuncUnregisterExternalCallback)(); void PowerMgrService::RegisterExternalCallback() @@ -890,6 +892,10 @@ void PowerMgrService::RegisterExternalCallback() }, [](std::string& sceneName, std::string value) { return SystemSuspendController::GetInstance().SetPowerConfig(sceneName, value); + }, + [this](bool isWakeup) { + POWER_HILOGI(COMP_SVC, "[UL_POWER] sync sleep callback triggered, isWakeup: %{public}d", isWakeup); + suspendController_->TriggerSyncSleepCallback(isWakeup); }); POWER_HILOGI(COMP_SVC, "RegisterExternalCallback Success"); dlclose(subscriberHandler); diff --git a/services/native/src/suspend/suspend_controller.cpp b/services/native/src/suspend/suspend_controller.cpp index 20ad747b..a93da36a 100644 --- a/services/native/src/suspend/suspend_controller.cpp +++ b/services/native/src/suspend/suspend_controller.cpp @@ -692,14 +692,14 @@ void SuspendController::Reset() } #ifdef POWER_MANAGER_WAKEUP_ACTION -bool SuspendController::GetLowCapacityPowerKeyFlag() +bool SuspendController::GetWakeupReasonConfigMatchedFlag() { - return isLowCapacityPowerKey_; + return isWakeupReasonConfigMatched_; } -void SuspendController::SetLowCapacityPowerKeyFlag(bool flag) +void SuspendController::SetWakeupReasonConfigMatchedFlag(bool flag) { - isLowCapacityPowerKey_ = flag; + isWakeupReasonConfigMatched_ = flag; } #endif @@ -771,12 +771,18 @@ void PowerKeySuspendMonitor::ReceivePowerkeyCallback(std::shared_ptr wakeupController = pms->GetWakeupController(); + if (wakeupController == nullptr) { + POWER_HILOGE(FEATURE_WAKEUP, "[UL_POWER] wakeupController is nullptr"); + return; + } #if POWER_MANAGER_WAKEUP_ACTION - bool isLowCapacityPowerKey = suspendController->GetLowCapacityPowerKeyFlag(); - if (isLowCapacityPowerKey) { - POWER_HILOGI(FEATURE_SUSPEND, "[UL_POWER] skip low capacity powerkey up"); - suspendController->SetLowCapacityPowerKeyFlag(false); + bool isWakeupReasonConfigMatched = suspendController->GetWakeupReasonConfigMatchedFlag(); + if (isWakeupReasonConfigMatched + || wakeupController->IsWakeupReasonConfigMatched(WakeupDeviceType::WAKEUP_DEVICE_POWER_BUTTON)) { + POWER_HILOGI(FEATURE_SUSPEND, "[UL_POWER] wakeup reason matched config, skip powerkey up"); + suspendController->SetWakeupReasonConfigMatchedFlag(false); return; } #endif diff --git a/services/native/src/suspend/suspend_controller.h b/services/native/src/suspend/suspend_controller.h index 5c406612..1dd85c8c 100644 --- a/services/native/src/suspend/suspend_controller.h +++ b/services/native/src/suspend/suspend_controller.h @@ -94,8 +94,8 @@ public: } #endif #ifdef POWER_MANAGER_WAKEUP_ACTION - bool GetLowCapacityPowerKeyFlag(); - void SetLowCapacityPowerKeyFlag(bool flag); + bool GetWakeupReasonConfigMatchedFlag(); + void SetWakeupReasonConfigMatchedFlag(bool flag); #endif private: @@ -132,7 +132,7 @@ private: #endif sptr suspendPowerStateCallback_ {nullptr}; #ifdef POWER_MANAGER_WAKEUP_ACTION - std::atomic isLowCapacityPowerKey_ {false}; + std::atomic isWakeupReasonConfigMatched_ {false}; #endif }; diff --git a/services/native/src/wakeup/wakeup_controller.cpp b/services/native/src/wakeup/wakeup_controller.cpp index be5f59dc..8215faa9 100644 --- a/services/native/src/wakeup/wakeup_controller.cpp +++ b/services/native/src/wakeup/wakeup_controller.cpp @@ -413,7 +413,7 @@ WakeupController::SleepGuard::~SleepGuard() } #ifdef POWER_MANAGER_WAKEUP_ACTION -bool WakeupController::IsLowCapacityWakeup(WakeupDeviceType reason) +bool WakeupController::IsWakeupReasonConfigMatched(WakeupDeviceType reason) { auto pms = DelayedSpSingleton::GetInstance(); if (pms == nullptr) { @@ -426,12 +426,12 @@ bool WakeupController::IsLowCapacityWakeup(WakeupDeviceType reason) return false; } return (reason == WakeupDeviceType::WAKEUP_DEVICE_POWER_BUTTON) && - (wakeupActionController->IsLowCapacityWakeup()); + (wakeupActionController->IsWakeupReasonConfigMatched()); } -void WakeupController::ProcessLowCapacityWakeup() +void WakeupController::ProcessWakeupReason() { - POWER_HILOGI(FEATURE_WAKEUP, "[UL_POWER] processing low capacity wake up begins."); + POWER_HILOGI(FEATURE_WAKEUP, "[UL_POWER] processing wake up reason begins."); if (stateMachine_->GetState() != PowerState::SLEEP) { POWER_HILOGE(FEATURE_WAKEUP, "[UL_POWER] the current power state is not sleep."); return; @@ -893,12 +893,12 @@ void PowerkeyWakeupMonitor::ReceivePowerkeyCallback(std::shared_ptrIsLowCapacityWakeup(reason)) { - wakeupController->ProcessLowCapacityWakeup(); - suspendController->SetLowCapacityPowerKeyFlag(true); + if (wakeupController->IsWakeupReasonConfigMatched(WakeupDeviceType::WAKEUP_DEVICE_POWER_BUTTON)) { + wakeupController->ProcessWakeupReason(); + suspendController->SetWakeupReasonConfigMatchedFlag(true); return; } - suspendController->SetLowCapacityPowerKeyFlag(false); + suspendController->SetWakeupReasonConfigMatchedFlag(false); #endif bool poweroffInterrupted = false; diff --git a/services/native/src/wakeup/wakeup_controller.h b/services/native/src/wakeup/wakeup_controller.h index baa8f27e..25e91959 100644 --- a/services/native/src/wakeup/wakeup_controller.h +++ b/services/native/src/wakeup/wakeup_controller.h @@ -51,8 +51,8 @@ public: void NotifyDisplayActionDone(uint32_t event); void SetOriginSettingValue(WakeupSource& source); #ifdef POWER_MANAGER_WAKEUP_ACTION - bool IsLowCapacityWakeup(WakeupDeviceType reason); - void ProcessLowCapacityWakeup(); + bool IsWakeupReasonConfigMatched(WakeupDeviceType reason); + void ProcessWakeupReason(); #endif static int32_t SetWakeupDoubleClickSensor(bool enable); static void ChangeWakeupSourceConfig(bool updateEnable); diff --git a/services/native/src/wakeup_action/wakeup_action_controller.cpp b/services/native/src/wakeup_action/wakeup_action_controller.cpp index dcc42367..2aeffba9 100644 --- a/services/native/src/wakeup_action/wakeup_action_controller.cpp +++ b/services/native/src/wakeup_action/wakeup_action_controller.cpp @@ -45,7 +45,7 @@ void WakeupActionController::Init() } } -bool WakeupActionController::IsLowCapacityWakeup() +bool WakeupActionController::IsWakeupReasonConfigMatched() { std::string reason; SystemSuspendController::GetInstance().GetWakeupReason(reason); diff --git a/services/native/src/wakeup_action/wakeup_action_controller.h b/services/native/src/wakeup_action/wakeup_action_controller.h index 89adc334..df38fc2b 100644 --- a/services/native/src/wakeup_action/wakeup_action_controller.h +++ b/services/native/src/wakeup_action/wakeup_action_controller.h @@ -36,7 +36,7 @@ public: ~WakeupActionController(); void Init(); bool ExecuteByGetReason(); - bool IsLowCapacityWakeup(); + bool IsWakeupReasonConfigMatched(); private: void HandleAction(const std::string& reason); diff --git a/services/native/src/wakeup_action/wakeup_action_source_parser.cpp b/services/native/src/wakeup_action/wakeup_action_source_parser.cpp index 9ea26405..a7c8898d 100644 --- a/services/native/src/wakeup_action/wakeup_action_source_parser.cpp +++ b/services/native/src/wakeup_action/wakeup_action_source_parser.cpp @@ -109,7 +109,7 @@ bool WakeupActionSourceParser::ParseSourcesProc( std::shared_ptr& parseSources, Json::Value& valueObj, std::string& key) { std::string scene{""}; - uint32_t action = 0; + uint32_t action = ILLEGAL_ACTION; if (!valueObj.isNull() && valueObj.isObject()) { Json::Value sceneValue = valueObj[WakeupActionSource::SCENE_KEY]; Json::Value actionValue = valueObj[WakeupActionSource::ACTION_KEY]; @@ -125,11 +125,8 @@ bool WakeupActionSourceParser::ParseSourcesProc( } } } - - if (action != 0) { - std::shared_ptr wakeupActionSource = std::make_shared(scene, action); - parseSources->PutSource(key, wakeupActionSource); - } + std::shared_ptr wakeupActionSource = std::make_shared(scene, action); + parseSources->PutSource(key, wakeupActionSource); return true; } -- Gitee