15ccb8f90Sopenharmony_ci/* 25ccb8f90Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 35ccb8f90Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 45ccb8f90Sopenharmony_ci * you may not use this file except in compliance with the License. 55ccb8f90Sopenharmony_ci * You may obtain a copy of the License at 65ccb8f90Sopenharmony_ci * 75ccb8f90Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 85ccb8f90Sopenharmony_ci * 95ccb8f90Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 105ccb8f90Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 115ccb8f90Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 125ccb8f90Sopenharmony_ci * See the License for the specific language governing permissions and 135ccb8f90Sopenharmony_ci * limitations under the License. 145ccb8f90Sopenharmony_ci */ 155ccb8f90Sopenharmony_ci 165ccb8f90Sopenharmony_ci#include "suspend_sources.h" 175ccb8f90Sopenharmony_ci#include "power_log.h" 185ccb8f90Sopenharmony_ci#include <string> 195ccb8f90Sopenharmony_cinamespace OHOS { 205ccb8f90Sopenharmony_cinamespace PowerMgr { 215ccb8f90Sopenharmony_cistd::mutex SuspendSources::sourceKeysMutex_; 225ccb8f90Sopenharmony_ci 235ccb8f90Sopenharmony_ciSuspendDeviceType SuspendSources::mapSuspendDeviceType(const std::string& key) 245ccb8f90Sopenharmony_ci{ 255ccb8f90Sopenharmony_ci if (key == SuspendSources::POWERKEY_KEY) { 265ccb8f90Sopenharmony_ci return SuspendDeviceType::SUSPEND_DEVICE_REASON_POWER_KEY; 275ccb8f90Sopenharmony_ci } 285ccb8f90Sopenharmony_ci 295ccb8f90Sopenharmony_ci if (key == SuspendSources::TIMEOUT_KEY) { 305ccb8f90Sopenharmony_ci return SuspendDeviceType::SUSPEND_DEVICE_REASON_TIMEOUT; 315ccb8f90Sopenharmony_ci } 325ccb8f90Sopenharmony_ci 335ccb8f90Sopenharmony_ci if (key == SuspendSources::LID_KEY) { 345ccb8f90Sopenharmony_ci return SuspendDeviceType::SUSPEND_DEVICE_REASON_LID; 355ccb8f90Sopenharmony_ci } 365ccb8f90Sopenharmony_ci 375ccb8f90Sopenharmony_ci if (key == SuspendSources::SWITCH_KEY) { 385ccb8f90Sopenharmony_ci return SuspendDeviceType::SUSPEND_DEVICE_REASON_SWITCH; 395ccb8f90Sopenharmony_ci } 405ccb8f90Sopenharmony_ci 415ccb8f90Sopenharmony_ci return SuspendDeviceType::SUSPEND_DEVICE_REASON_MIN; 425ccb8f90Sopenharmony_ci} 435ccb8f90Sopenharmony_ci 445ccb8f90Sopenharmony_cistd::vector<std::string> SuspendSources::getSourceKeys() 455ccb8f90Sopenharmony_ci{ 465ccb8f90Sopenharmony_ci std::lock_guard<std::mutex> lock(sourceKeysMutex_); 475ccb8f90Sopenharmony_ci std::vector<std::string> sourceKeys; 485ccb8f90Sopenharmony_ci sourceKeys.push_back(SuspendSources::POWERKEY_KEY); 495ccb8f90Sopenharmony_ci sourceKeys.push_back(SuspendSources::TIMEOUT_KEY); 505ccb8f90Sopenharmony_ci sourceKeys.push_back(SuspendSources::LID_KEY); 515ccb8f90Sopenharmony_ci sourceKeys.push_back(SuspendSources::SWITCH_KEY); 525ccb8f90Sopenharmony_ci return sourceKeys; 535ccb8f90Sopenharmony_ci} 545ccb8f90Sopenharmony_ci 555ccb8f90Sopenharmony_civoid SuspendSources::PutSource(SuspendSource& source) 565ccb8f90Sopenharmony_ci{ 575ccb8f90Sopenharmony_ci std::lock_guard<std::mutex> lock(sourceListMutex_); 585ccb8f90Sopenharmony_ci sourceList_.push_back(source); 595ccb8f90Sopenharmony_ci} 605ccb8f90Sopenharmony_ci 615ccb8f90Sopenharmony_cistd::vector<SuspendSource> SuspendSources::GetSourceList() 625ccb8f90Sopenharmony_ci{ 635ccb8f90Sopenharmony_ci std::lock_guard<std::mutex> lock(sourceListMutex_); 645ccb8f90Sopenharmony_ci return sourceList_; 655ccb8f90Sopenharmony_ci} 665ccb8f90Sopenharmony_ci 675ccb8f90Sopenharmony_ci} // namespace PowerMgr 685ccb8f90Sopenharmony_ci} // namespace OHOS