1 /* 2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef POWERMGR_SYSTEM_SUSPEND_CONTROLLER_H 17 #define POWERMGR_SYSTEM_SUSPEND_CONTROLLER_H 18 19 #include <memory> 20 #include <mutex> 21 22 #include <singleton.h> 23 24 #include "actions/running_lock_action_info.h" 25 #include "hdi_service_status_listener.h" 26 #include "suspend/irunning_lock_hub.h" 27 #include "suspend/isuspend_controller.h" 28 #include "power_hdi_callback.h" 29 #include "v1_1/ipower_interface.h" 30 #include "ffrt_utils.h" 31 32 namespace OHOS { 33 namespace PowerMgr { 34 class SystemSuspendController : public DelayedRefSingleton<SystemSuspendController> { 35 public: 36 void Suspend(const std::function<void()>& onSuspend, const std::function<void()>& onWakeup, bool force); 37 void Wakeup(); 38 int32_t AcquireRunningLock(const RunningLockParam& param); 39 int32_t ReleaseRunningLock(const RunningLockParam& param); 40 void Dump(std::string& info); 41 void GetWakeupReason(std::string& reason); 42 void RegisterHdiStatusListener(); 43 void RegisterPowerHdiCallback(); 44 void UnRegisterPowerHdiCallback(); 45 46 private: 47 DECLARE_DELAYED_REF_SINGLETON(SystemSuspendController); 48 49 inline static constexpr const char* WAKEUP_HOLDER = "OHOSPowerMgr.WakeupHolder"; 50 class PowerHdfCallback : public OHOS::HDI::Power::V1_1::IPowerHdiCallback { 51 public: 52 PowerHdfCallback() = default; 53 ~PowerHdfCallback() = default; 54 int32_t OnSuspend() override; 55 int32_t OnWakeup() override; 56 void SetListener(std::function<void()>& suspend, std::function<void()>& wakeup); 57 private: 58 std::function<void()> onSuspend_; 59 std::function<void()> onWakeup_; 60 }; 61 OHOS::HDI::Power::V1_1::RunningLockInfo FillRunningLockInfo(const RunningLockParam& param); 62 std::mutex mutex_; 63 std::shared_ptr<Suspend::ISuspendController> sc_; 64 sptr<OHOS::HDI::Power::V1_1::IPowerInterface> powerInterface_ { nullptr }; 65 sptr<OHOS::HDI::ServiceManager::V1_0::IServiceManager> hdiServiceMgr_ { nullptr }; 66 sptr<HdiServiceStatusListener::IServStatListener> hdiServStatListener_ { nullptr }; 67 FFRTQueue queue_ {"power_system_suspend_controller"}; 68 }; 69 } // namespace PowerMgr 70 } // namespace OHOS 71 #endif // POWERMGR_SYSTEM_SUSPEND_CONTROLLER_H 72