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