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 31 namespace OHOS { 32 namespace PowerMgr { 33 class SystemSuspendController : public DelayedRefSingleton<SystemSuspendController> { 34 public: 35 void Suspend(const std::function<void()>& onSuspend, const std::function<void()>& onWakeup, bool force); 36 void Wakeup(); 37 int32_t AcquireRunningLock(const RunningLockParam& param); 38 int32_t ReleaseRunningLock(const RunningLockParam& param); 39 void Dump(std::string& info); 40 void RegisterHdiStatusListener(); 41 void RegisterPowerHdiCallback(); 42 void UnRegisterPowerHdiCallback(); 43 44 private: 45 DECLARE_DELAYED_REF_SINGLETON(SystemSuspendController); 46 47 inline static constexpr const char* WAKEUP_HOLDER = "OHOSPowerMgr.WakeupHolder"; 48 class PowerHdfCallback : public OHOS::HDI::Power::V1_1::IPowerHdiCallback { 49 public: 50 PowerHdfCallback() = default; 51 ~PowerHdfCallback() = default; 52 int32_t OnSuspend() override; 53 int32_t OnWakeup() override; 54 void SetListener(std::function<void()>& suspend, std::function<void()>& wakeup); 55 private: 56 std::function<void()> onSuspend_; 57 std::function<void()> onWakeup_; 58 }; 59 OHOS::HDI::Power::V1_1::RunningLockInfo FillRunningLockInfo(const RunningLockParam& param); 60 std::mutex mutex_; 61 std::shared_ptr<Suspend::ISuspendController> sc_; 62 sptr<OHOS::HDI::Power::V1_1::IPowerInterface> powerInterface_ { nullptr }; 63 sptr<OHOS::HDI::ServiceManager::V1_0::IServiceManager> hdiServiceMgr_ { nullptr }; 64 sptr<HdiServiceStatusListener::IServStatListener> hdiServStatListener_ { nullptr }; 65 }; 66 } // namespace PowerMgr 67 } // namespace OHOS 68 #endif // POWERMGR_SYSTEM_SUSPEND_CONTROLLER_H 69