1 /* 2 * Copyright (c) 2024 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 #ifndef FINGERPRINT_EVENT_PROCESSOR_H 17 #define FINGERPRINT_EVENT_PROCESSOR_H 18 19 #include <map> 20 #include <memory> 21 22 #include "libinput.h" 23 #include "singleton.h" 24 25 namespace OHOS { 26 namespace MMI { 27 #ifdef OHOS_BUILD_ENABLE_FINGERPRINT 28 29 struct SmartKeySwitch { 30 std::string keyString { "" }; 31 std::string valueString { "1" }; 32 }; 33 34 class FingerprintEventProcessor { 35 DECLARE_DELAYED_SINGLETON(FingerprintEventProcessor); 36 37 public: 38 DISALLOW_COPY_AND_MOVE(FingerprintEventProcessor); 39 bool IsFingerprintEvent(struct libinput_event* event); 40 int32_t HandleFingerprintEvent(struct libinput_event* event); 41 void SetPowerAndVolumeKeyState(struct libinput_event* event); 42 void SetScreenState(struct libinput_event* event); 43 void SetPowerKeyState(struct libinput_event* event); 44 45 static constexpr int32_t FINGERPRINT_CODE_DOWN { 121 }; 46 static constexpr int32_t FINGERPRINT_CODE_UP { 122 }; 47 static constexpr int32_t FINGERPRINT_CODE_CLICK { 123 }; 48 static constexpr int32_t FINGERPRINT_CODE_RETOUCH { 124 }; 49 static constexpr int32_t FINGERPRINT_CODE_CANCEL { 125 }; 50 51 static constexpr int32_t KEY_VOLUME_DOWN { 114 }; 52 static constexpr int32_t KEY_VOLUME_UP { 115 }; 53 static constexpr int32_t KEY_POWER { 116 }; 54 55 private: 56 int32_t AnalyseKeyEvent(struct libinput_event* event); 57 int32_t AnalysePointEvent(struct libinput_event *event); 58 int32_t SendFingerprintCancelEvent(); 59 void ChangeScreenMissTouchFlag(bool screenState, bool cancel); 60 bool CheckMisTouchState(); 61 bool CheckScreenMisTouchState(); 62 bool CheckKeyMisTouchState(); 63 template <class T> 64 void CreateStatusConfigObserver(T& item); 65 void StartSmartKeyIfNeeded(); 66 void StartSmartKey(bool isShowDialog); 67 void ProcessSlideEvent(); 68 void ProcessClickEvent(); 69 void ReportResSched(uint32_t resType, int64_t value); 70 71 const std::string FINGERPRINT_SOURCE_KEY { "fingerprint" }; 72 const std::string FINGERPRINT_SOURCE_POINT { "hw_fingerprint_mouse" }; 73 74 using keyTimeMap = std::pair<int32_t, std::chrono::time_point<std::chrono::steady_clock>>; 75 std::map<int32_t, keyTimeMap> keyStateMap_ { 76 { 77 114, {0, std::chrono::high_resolution_clock::now()}, 78 }, 79 { 80 115, {0, std::chrono::high_resolution_clock::now()}, 81 }, 82 { 83 116, {0, std::chrono::high_resolution_clock::now()}, 84 }, 85 }; 86 std::atomic_bool screenState_ { false }; 87 std::atomic_bool cancelState_ { false }; 88 std::atomic_bool fingerprintFlag_ {false}; 89 std::atomic_bool screenMissTouchFlag_ { false }; 90 std::atomic_bool isStartedSmartKeyBySlide_ { false }; 91 std::atomic_bool isStartedSmartKey_ { false }; 92 std::atomic_bool isCreatedObserver_ { false }; 93 std::mutex mutex_; 94 struct SmartKeySwitch smartKeySwitch_; 95 }; 96 #define FingerprintEventHdr ::OHOS::DelayedSingleton<FingerprintEventProcessor>::GetInstance() 97 #endif // OHOS_BUILD_ENABLE_FINGERPRINT 98 } // namespace MMI 99 } // namespace OHOS 100 #endif // FINGERPRINT_EVENT_PROCESSOR_H