diff --git a/bundle.json b/bundle.json index e862c37e0d002c7b4b2e80b12c432dd2c0554233..5f2e09a34e3443ef0e380e8fb8cdd5bf06280ef9 100644 --- a/bundle.json +++ b/bundle.json @@ -32,6 +32,7 @@ "power_manager_feature_power_dialog", "power_manager_feature_enable_s4", "power_manager_feature_enable_suspend_with_tag", + "power_manager_feature_enable_ulsr", "power_manager_feature_audio_lock_unproxy", "power_manager_feature_disable_auto_displayoff", "power_manager_feature_doubleclick", 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 00924d3fdc0ec143be59777dd2f7d91008a43666..b34f909928f5e8b344c2512342c6b03639124db0 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 3671e9f2872f99b67b9cee8863087822e1d81919..29c26ad501edc410f49b72014f8f40191d305fe9 100644 --- a/powermgr.gni +++ b/powermgr.gni @@ -26,6 +26,7 @@ declare_args() { power_manager_feature_power_dialog = true power_manager_feature_enable_s4 = false power_manager_feature_enable_suspend_with_tag = 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_disable_auto_displayoff = false diff --git a/services/BUILD.gn b/services/BUILD.gn index c1495f03bdc426aee8679f3a5327bc4840913886..66d7b7a2664580edc35b99d70973f1cd029899e6 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -220,6 +220,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/profile/power_wakeup_action.json b/services/native/profile/power_wakeup_action.json index 5778295c9af456b634154fa43938f66879b6ea12..bfc9a1f0927287965216ce0b4eec7115fc33685a 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_hdi_callback.cpp b/services/native/src/power_hdi_callback.cpp index 65556b1ccb7d60631ce772bcdae1cf34575f14e9..b02a525a43c95ec5e5e44979d7d6fcd29411c914 100644 --- a/services/native/src/power_hdi_callback.cpp +++ b/services/native/src/power_hdi_callback.cpp @@ -43,6 +43,15 @@ int32_t PowerHdiCallbackExt::OnSuspendWithTag(const std::string& tag) int32_t PowerHdiCallbackExt::OnWakeupWithTag(const std::string& tag) { POWER_HILOGD(FEATURE_WAKEUP, "OnWakeupWithTag, tag:%{public}s", tag.c_str()); +#ifdef POWER_MANAGER_ENABLE_ULSR + if (tag == "ulsr") { + int ret = HookMgrExecute( + GetPowerHookMgr(), static_cast(PowerHookStage::POWER_HDI_CALLBACK_WAKEUP), nullptr, nullptr); + POWER_HILOGI(FEATURE_WAKEUP, + "OnWakeupWithTag, HookMgrExecute GetPowerHookMgr, stage: %{public}d, ret: %{public}d", + PowerHookStage::POWER_HDI_CALLBACK_WAKEUP, ret); + } +#endif return HDF_SUCCESS; } } // OHOS diff --git a/services/native/src/power_mgr_service.cpp b/services/native/src/power_mgr_service.cpp index 2935287b42e9fec9cdd235a01b5b7b8785266535..566da7b625ff628db0f7d6bb2657481f92e3b842 100644 --- a/services/native/src/power_mgr_service.cpp +++ b/services/native/src/power_mgr_service.cpp @@ -858,7 +858,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() @@ -892,7 +894,12 @@ 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); subscriberHandler = nullptr; diff --git a/services/native/src/suspend/suspend_controller.cpp b/services/native/src/suspend/suspend_controller.cpp index 20ad747b75155de319e1ceef0022d7373c365e55..ecbceed12fe99e701891e152f6431abdf0f0149d 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_HILOGE(FEATURE_WAKEUP, "[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 5c406612a4459b1707e9a7bd04b083638ff85689..1dd85c8c713a60ad31f80e1a75405bfcbf6bb433 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 bb2e2a1f76e0f8482a8db036cb753ae2ba2badd2..52d3745620b221d1043e6ffb6df01a48cec6c3c2 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; @@ -894,12 +894,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 baa8f27eb49b752c6540f187ec27fdccd55ce816..25e91959b4836a95fe13e46a2a02d37cea7fe6ad 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 dcc4236771d618cd306c8ae47aeddb8803f1b671..2aeffba98bb0e713c3fe91e737aab32d34bfb5ac 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 89adc3347c16fa324735865e3687a0dfa7a84e03..df38fc2b1d90f6fbdc60627c8fe936848594411c 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 9ea264050c9ac487b4908a579fb281395cc354b1..f55b5d145b4c938f79394633b29ee4592b0b76cb 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]; @@ -126,10 +126,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; }