Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Prabir Pradhan | 4810866 | 2022-09-09 21:22:04 +0000 | [diff] [blame] | 17 | #pragma once |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 18 | |
| 19 | #define LOG_TAG "InputReader" |
| 20 | |
| 21 | //#define LOG_NDEBUG 0 |
Arthur Hung | b060def | 2022-05-26 07:41:33 +0000 | [diff] [blame] | 22 | #include <log/log.h> |
| 23 | #include <log/log_event_list.h> |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 24 | |
Zixuan Qu | fecb606 | 2022-11-12 04:44:31 +0000 | [diff] [blame] | 25 | #include <unordered_map> |
| 26 | |
Arthur Hung | b060def | 2022-05-26 07:41:33 +0000 | [diff] [blame] | 27 | namespace android { |
| 28 | /** |
| 29 | * Log debug messages for each raw event received from the EventHub. |
| 30 | * Enable this via "adb shell setprop log.tag.InputReaderRawEvents DEBUG" (requires restart) |
| 31 | */ |
| 32 | const bool DEBUG_RAW_EVENTS = |
| 33 | __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "RawEvents", ANDROID_LOG_INFO); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 34 | |
Arthur Hung | b060def | 2022-05-26 07:41:33 +0000 | [diff] [blame] | 35 | /** |
| 36 | * Log debug messages about virtual key processing. |
| 37 | * Enable this via "adb shell setprop log.tag.InputReaderVirtualKeys DEBUG" (requires restart) |
| 38 | */ |
| 39 | const bool DEBUG_VIRTUAL_KEYS = |
| 40 | __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "VirtualKeys", ANDROID_LOG_INFO); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 41 | |
Arthur Hung | b060def | 2022-05-26 07:41:33 +0000 | [diff] [blame] | 42 | /** |
| 43 | * Log debug messages about pointers. |
| 44 | * Enable this via "adb shell setprop log.tag.InputReaderPointers DEBUG" (requires restart) |
| 45 | */ |
| 46 | const bool DEBUG_POINTERS = |
| 47 | __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "Pointers", ANDROID_LOG_INFO); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 48 | |
Arthur Hung | b060def | 2022-05-26 07:41:33 +0000 | [diff] [blame] | 49 | /** |
| 50 | * Log debug messages about pointer assignment calculations. |
| 51 | * Enable this via "adb shell setprop log.tag.InputReaderPointerAssignment DEBUG" (requires restart) |
| 52 | */ |
| 53 | const bool DEBUG_POINTER_ASSIGNMENT = |
| 54 | __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "PointerAssignment", ANDROID_LOG_INFO); |
| 55 | /** |
| 56 | * Log debug messages about gesture detection. |
| 57 | * Enable this via "adb shell setprop log.tag.InputReaderGestures DEBUG" (requires restart) |
| 58 | */ |
| 59 | const bool DEBUG_GESTURES = |
| 60 | __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "Gestures", ANDROID_LOG_INFO); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 61 | |
Arthur Hung | b060def | 2022-05-26 07:41:33 +0000 | [diff] [blame] | 62 | /** |
| 63 | * Log debug messages about the vibrator. |
| 64 | * Enable this via "adb shell setprop log.tag.InputReaderVibrator DEBUG" (requires restart) |
| 65 | */ |
| 66 | const bool DEBUG_VIBRATOR = |
| 67 | __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "Vibrator", ANDROID_LOG_INFO); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 68 | |
Arthur Hung | b060def | 2022-05-26 07:41:33 +0000 | [diff] [blame] | 69 | /** |
| 70 | * Log debug messages about fusing stylus data. |
| 71 | * Enable this via "adb shell setprop log.tag.InputReaderStylusFusion DEBUG" (requires restart) |
| 72 | */ |
| 73 | const bool DEBUG_STYLUS_FUSION = |
| 74 | __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "StylusFusion", ANDROID_LOG_INFO); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 75 | |
Arthur Hung | b060def | 2022-05-26 07:41:33 +0000 | [diff] [blame] | 76 | /** |
| 77 | * Log detailed debug messages about input device lights. |
| 78 | * Enable this via "adb shell setprop log.tag.InputReaderLightDetails DEBUG" (requires restart) |
| 79 | */ |
| 80 | const bool DEBUG_LIGHT_DETAILS = |
| 81 | __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "LightDetails", ANDROID_LOG_INFO); |
| 82 | } // namespace android |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 83 | |
| 84 | #define INDENT " " |
| 85 | #define INDENT2 " " |
| 86 | #define INDENT3 " " |
| 87 | #define INDENT4 " " |
| 88 | #define INDENT5 " " |
| 89 | |
| 90 | #include <input/Input.h> |
| 91 | |
| 92 | namespace android { |
| 93 | |
| 94 | // --- Static Functions --- |
| 95 | |
| 96 | template <typename T> |
| 97 | inline static T abs(const T& value) { |
| 98 | return value < 0 ? -value : value; |
| 99 | } |
| 100 | |
| 101 | template <typename T> |
| 102 | inline static T min(const T& a, const T& b) { |
| 103 | return a < b ? a : b; |
| 104 | } |
| 105 | |
| 106 | inline static float avg(float x, float y) { |
| 107 | return (x + y) / 2; |
| 108 | } |
| 109 | |
| 110 | static inline const char* toString(bool value) { |
| 111 | return value ? "true" : "false"; |
| 112 | } |
| 113 | |
| 114 | static inline bool sourcesMatchMask(uint32_t sources, uint32_t sourceMask) { |
| 115 | return (sources & sourceMask & ~AINPUT_SOURCE_CLASS_MASK) != 0; |
| 116 | } |
| 117 | |
Zixuan Qu | fecb606 | 2022-11-12 04:44:31 +0000 | [diff] [blame] | 118 | template <typename K, typename V> |
| 119 | static inline std::optional<V> getValueByKey(const std::unordered_map<K, V>& map, K key) { |
| 120 | auto it = map.find(key); |
| 121 | std::optional<V> value = std::nullopt; |
| 122 | if (it != map.end()) { |
| 123 | value = it->second; |
| 124 | } |
| 125 | return value; |
| 126 | } |
| 127 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 128 | } // namespace android |