1 /* 2 * Copyright (c) 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 #include "suspend_sources.h" 17 #include "power_log.h" 18 #include <string> 19 namespace OHOS { 20 namespace PowerMgr { 21 std::mutex SuspendSources::sourceKeysMutex_; 22 mapSuspendDeviceType(const std::string & key)23SuspendDeviceType SuspendSources::mapSuspendDeviceType(const std::string& key) 24 { 25 if (key == SuspendSources::POWERKEY_KEY) { 26 return SuspendDeviceType::SUSPEND_DEVICE_REASON_POWER_KEY; 27 } 28 29 if (key == SuspendSources::TIMEOUT_KEY) { 30 return SuspendDeviceType::SUSPEND_DEVICE_REASON_TIMEOUT; 31 } 32 33 if (key == SuspendSources::LID_KEY) { 34 return SuspendDeviceType::SUSPEND_DEVICE_REASON_LID; 35 } 36 37 if (key == SuspendSources::SWITCH_KEY) { 38 return SuspendDeviceType::SUSPEND_DEVICE_REASON_SWITCH; 39 } 40 41 if (key == SuspendSources::TP_COVER_KEY) { 42 return SuspendDeviceType::SUSPEND_DEVICE_REASON_TP_COVER; 43 } 44 45 return SuspendDeviceType::SUSPEND_DEVICE_REASON_MIN; 46 } 47 getSourceKeys()48std::vector<std::string> SuspendSources::getSourceKeys() 49 { 50 std::lock_guard<std::mutex> lock(sourceKeysMutex_); 51 std::vector<std::string> sourceKeys; 52 sourceKeys.push_back(SuspendSources::POWERKEY_KEY); 53 sourceKeys.push_back(SuspendSources::TIMEOUT_KEY); 54 sourceKeys.push_back(SuspendSources::LID_KEY); 55 sourceKeys.push_back(SuspendSources::SWITCH_KEY); 56 return sourceKeys; 57 } 58 PutSource(SuspendSource & source)59void SuspendSources::PutSource(SuspendSource& source) 60 { 61 std::lock_guard<std::mutex> lock(sourceListMutex_); 62 sourceList_.push_back(source); 63 } 64 GetSourceList()65std::vector<SuspendSource> SuspendSources::GetSourceList() 66 { 67 std::lock_guard<std::mutex> lock(sourceListMutex_); 68 return sourceList_; 69 } 70 71 } // namespace PowerMgr 72 } // namespace OHOS