• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)23 WakeupDeviceType 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     if (key == WakeupSources::PICKUP_KEY) {
61         return WakeupDeviceType::WAKEUP_DEVICE_PICKUP;
62     }
63 
64     if (key == WakeupSources::TP_TOUCH_KEY) {
65         return WakeupDeviceType::WAKEUP_DEVICE_TP_TOUCH;
66     }
67 
68     return WakeupDeviceType::WAKEUP_DEVICE_UNKNOWN;
69 }
70 
getSourceKeys()71 std::vector<std::string> WakeupSources::getSourceKeys()
72 {
73     std::lock_guard<std::mutex> lock(sourceKeysMutex_);
74     std::vector<std::string> sourceKeys;
75     sourceKeys.push_back(WakeupSources::POWERKEY_KEY);
76     sourceKeys.push_back(WakeupSources::MOUSE_KEY);
77     sourceKeys.push_back(WakeupSources::KEYBOARD_KEY);
78     sourceKeys.push_back(WakeupSources::TOUCHSCREEN_KEY);
79     sourceKeys.push_back(WakeupSources::TOUCHPAD_KEY);
80     sourceKeys.push_back(WakeupSources::PEN_KEY);
81     sourceKeys.push_back(WakeupSources::LID_KEY);
82     sourceKeys.push_back(WakeupSources::SWITCH_KEY);
83     sourceKeys.push_back(WakeupSources::PICKUP_KEY);
84     return sourceKeys;
85 }
86 
PutSource(WakeupSource & source)87 void WakeupSources::PutSource(WakeupSource& source)
88 {
89     std::lock_guard<std::mutex> lock(sourceListMutex_);
90     sourceList_.push_back(source);
91 }
92 
GetSourceList()93 std::vector<WakeupSource> WakeupSources::GetSourceList()
94 {
95     std::lock_guard<std::mutex> lock(sourceListMutex_);
96     return sourceList_;
97 }
98 
99 } // namespace PowerMgr
100 } // namespace OHOS