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 "wakeup_sources.h" 17 #include "power_log.h" 18 #include <string> 19 namespace OHOS { 20 namespace PowerMgr { 21 std::mutex WakeupSources::sourceKeysMutex_; 22 mapWakeupDeviceType(const std::string & key,uint32_t click)23WakeupDeviceType WakeupSources::mapWakeupDeviceType(const std::string& key, uint32_t click) 24 { 25 if (key == WakeupSources::POWERKEY_KEY) { 26 return WakeupDeviceType::WAKEUP_DEVICE_POWER_BUTTON; 27 } 28 29 if (key == WakeupSources::MOUSE_KEY) { 30 return WakeupDeviceType::WAKEUP_DEVICE_MOUSE; 31 } 32 33 if (key == WakeupSources::KEYBOARD_KEY) { 34 return WakeupDeviceType::WAKEUP_DEVICE_KEYBOARD; 35 } 36 37 if (key == WakeupSources::PEN_KEY) { 38 return WakeupDeviceType::WAKEUP_DEVICE_PEN; 39 } 40 41 if (key == WakeupSources::TOUCHPAD_KEY) { 42 return WakeupDeviceType::WAKEUP_DEVICE_TOUCHPAD; 43 } 44 45 if (key == WakeupSources::LID_KEY) { 46 return WakeupDeviceType::WAKEUP_DEVICE_LID; 47 } 48 49 if (key == WakeupSources::SWITCH_KEY) { 50 return WakeupDeviceType::WAKEUP_DEVICE_SWITCH; 51 } 52 53 if (key == WakeupSources::TOUCHSCREEN_KEY) { 54 if (click == WakeupSources::SINGLE_CLICK) { 55 return WakeupDeviceType::WAKEUP_DEVICE_SINGLE_CLICK; 56 } 57 return WakeupDeviceType::WAKEUP_DEVICE_DOUBLE_CLICK; 58 } 59 60 return WakeupDeviceType::WAKEUP_DEVICE_UNKNOWN; 61 } 62 getSourceKeys()63std::vector<std::string> WakeupSources::getSourceKeys() 64 { 65 std::lock_guard<std::mutex> lock(sourceKeysMutex_); 66 std::vector<std::string> sourceKeys; 67 sourceKeys.push_back(WakeupSources::POWERKEY_KEY); 68 sourceKeys.push_back(WakeupSources::MOUSE_KEY); 69 sourceKeys.push_back(WakeupSources::KEYBOARD_KEY); 70 sourceKeys.push_back(WakeupSources::TOUCHSCREEN_KEY); 71 sourceKeys.push_back(WakeupSources::TOUCHPAD_KEY); 72 sourceKeys.push_back(WakeupSources::PEN_KEY); 73 sourceKeys.push_back(WakeupSources::LID_KEY); 74 sourceKeys.push_back(WakeupSources::SWITCH_KEY); 75 return sourceKeys; 76 } 77 PutSource(WakeupSource & source)78void WakeupSources::PutSource(WakeupSource& source) 79 { 80 std::lock_guard<std::mutex> lock(sourceListMutex_); 81 sourceList_.push_back(source); 82 } 83 GetSourceList()84std::vector<WakeupSource> WakeupSources::GetSourceList() 85 { 86 std::lock_guard<std::mutex> lock(sourceListMutex_); 87 return sourceList_; 88 } 89 90 } // namespace PowerMgr 91 } // namespace OHOS