• 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 #ifndef UPDATER_UI_KEYS_INPUT_DEVICE_H
16 #define UPDATER_UI_KEYS_INPUT_DEVICE_H
17 
18 #include <atomic>
19 #include <linux/input.h>
20 #include <string>
21 #include "macros_updater.h"
22 #include "dock/key_input_device.h"
23 #include "events/key_event.h"
24 
25 namespace Updater {
26 constexpr auto LONG_PRESS_POWER_ONLY_TYPE = "power";
27 class KeysInputDevice : public OHOS::KeyInputDevice {
28     DISALLOW_COPY_MOVE(KeysInputDevice);
29 public:
30     KeysInputDevice() = default;
31     virtual ~KeysInputDevice() = default;
32     static KeysInputDevice &GetInstance();
33     bool Read(OHOS::DeviceData &data) override;
34     int HandleKeyEvent(const input_event &ev, uint32_t type);
35     void SetLongPressType(const std::string &type);
36 private:
37     void PowerVolumeDownPress(const input_event &ev);
38     void PowerDownPress(const input_event &ev);
39     void OnLongKeyPressUp();
40     void OnLongKeyPressDown();
41     /* for KeysInputDevice */
42     uint16_t lastKeyId_ { 0 };
43     uint16_t keyState_ = OHOS::INVALID_KEY_STATE;
44     std::atomic<bool> timerStop_ {false};
45     std::string type_;
46 };
47 } // namespace Updater
48 #endif // UPDATER_UI_KEYS_INPUT_DEVICE_H
49