1 /* 2 * Copyright (c) 2024 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 #include "hibernate_controller.h" 17 #include "system_suspend_controller.h" 18 19 namespace OHOS { 20 namespace PowerMgr { Hibernate(bool clearMemory)21bool HibernateController::Hibernate(bool clearMemory) 22 { 23 return SystemSuspendController::GetInstance().Hibernate(); 24 } 25 RegisterSyncHibernateCallback(const sptr<ISyncHibernateCallback>& cb)26void HibernateController::RegisterSyncHibernateCallback(const sptr<ISyncHibernateCallback>& cb) 27 { 28 std::lock_guard<std::mutex> lock(mutex_); 29 callbacks_.insert(cb); 30 } 31 UnregisterSyncHibernateCallback(const sptr<ISyncHibernateCallback>& cb)32void HibernateController::UnregisterSyncHibernateCallback(const sptr<ISyncHibernateCallback>& cb) 33 { 34 std::lock_guard<std::mutex> lock(mutex_); 35 callbacks_.erase(cb); 36 } 37 PreHibernate() const38void HibernateController::PreHibernate() const 39 { 40 for (const auto &cb : callbacks_) { 41 if (cb != nullptr) { 42 cb->OnSyncHibernate(); 43 } 44 } 45 } 46 PostHibernate(bool hibernateResult) const47void HibernateController::PostHibernate(bool hibernateResult) const 48 { 49 for (const auto &cb : callbacks_) { 50 if (cb != nullptr) { 51 cb->OnSyncWakeup(hibernateResult); 52 } 53 } 54 } 55 } // namespace PowerMgr 56 } // namespace OHOS 57