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 AnalyseMsdpPointEvent(struct libinput_event *event); 59 int32_t SendFingerprintCancelEvent(); 60 void ChangeScreenMissTouchFlag(bool screenState, bool cancel); 61 bool CheckMisTouchState(); 62 bool CheckScreenMisTouchState(); 63 bool CheckKeyMisTouchState(); 64 template <class T> 65 void CreateStatusConfigObserver(T& item); 66 void StartSmartKeyIfNeeded(); 67 void StartSmartKey(bool isShowDialog); 68 void ProcessSlideEvent(); 69 void ProcessClickEvent(); 70 void ReportResSched(uint32_t resType, int64_t value); 71 72 const std::string FINGERPRINT_SOURCE_KEY { "fingerprint" }; 73 const std::string FINGERPRINT_SOURCE_POINT { "hw_fingerprint_mouse" }; 74 75 using keyTimeMap = std::pair<int32_t, std::chrono::time_point<std::chrono::steady_clock>>; 76 std::map<int32_t, keyTimeMap> keyStateMap_ { 77 { 78 114, {0, std::chrono::high_resolution_clock::now()}, 79 }, 80 { 81 115, {0, std::chrono::high_resolution_clock::now()}, 82 }, 83 { 84 116, {0, std::chrono::high_resolution_clock::now()}, 85 }, 86 }; 87 std::atomic_bool screenState_ { false }; 88 std::atomic_bool cancelState_ { false }; 89 std::atomic_bool fingerprintFlag_ {false}; 90 std::atomic_bool screenMissTouchFlag_ { false }; 91 std::atomic_bool isStartedSmartKeyBySlide_ { false }; 92 std::atomic_bool isStartedSmartKey_ { false }; 93 std::atomic_bool isCreatedObserver_ { false }; 94 std::mutex mutex_; 95 struct SmartKeySwitch smartKeySwitch_; 96 }; 97 #define FingerprintEventHdr ::OHOS::DelayedSingleton<FingerprintEventProcessor>::GetInstance() 98 #endif // OHOS_BUILD_ENABLE_FINGERPRINT 99 } // namespace MMI 100 } // namespace OHOS 101 #endif // FINGERPRINT_EVENT_PROCESSOR_H