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 { |
Prabir Pradhan | 011ca3d | 2023-02-22 21:31:39 +0000 | [diff] [blame] | 28 | |
Arthur Hung | b060def | 2022-05-26 07:41:33 +0000 | [diff] [blame] | 29 | /** |
| 30 | * Log debug messages for each raw event received from the EventHub. |
Prabir Pradhan | 011ca3d | 2023-02-22 21:31:39 +0000 | [diff] [blame] | 31 | * Enable this via "adb shell setprop log.tag.InputReaderRawEvents DEBUG". |
| 32 | * This requires a restart on non-debuggable (e.g. user) builds, but should take effect immediately |
| 33 | * on debuggable builds (e.g. userdebug). |
Arthur Hung | b060def | 2022-05-26 07:41:33 +0000 | [diff] [blame] | 34 | */ |
Prabir Pradhan | 011ca3d | 2023-02-22 21:31:39 +0000 | [diff] [blame] | 35 | bool debugRawEvents(); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 36 | |
Arthur Hung | b060def | 2022-05-26 07:41:33 +0000 | [diff] [blame] | 37 | /** |
| 38 | * Log debug messages about virtual key processing. |
| 39 | * Enable this via "adb shell setprop log.tag.InputReaderVirtualKeys DEBUG" (requires restart) |
| 40 | */ |
| 41 | const bool DEBUG_VIRTUAL_KEYS = |
| 42 | __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] | 43 | |
Arthur Hung | b060def | 2022-05-26 07:41:33 +0000 | [diff] [blame] | 44 | /** |
| 45 | * Log debug messages about pointers. |
| 46 | * Enable this via "adb shell setprop log.tag.InputReaderPointers DEBUG" (requires restart) |
| 47 | */ |
| 48 | const bool DEBUG_POINTERS = |
| 49 | __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] | 50 | |
Arthur Hung | b060def | 2022-05-26 07:41:33 +0000 | [diff] [blame] | 51 | /** |
| 52 | * Log debug messages about pointer assignment calculations. |
| 53 | * Enable this via "adb shell setprop log.tag.InputReaderPointerAssignment DEBUG" (requires restart) |
| 54 | */ |
| 55 | const bool DEBUG_POINTER_ASSIGNMENT = |
| 56 | __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "PointerAssignment", ANDROID_LOG_INFO); |
Prabir Pradhan | 011ca3d | 2023-02-22 21:31:39 +0000 | [diff] [blame] | 57 | |
Arthur Hung | b060def | 2022-05-26 07:41:33 +0000 | [diff] [blame] | 58 | /** |
| 59 | * Log debug messages about gesture detection. |
| 60 | * Enable this via "adb shell setprop log.tag.InputReaderGestures DEBUG" (requires restart) |
| 61 | */ |
| 62 | const bool DEBUG_GESTURES = |
| 63 | __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] | 64 | |
Arthur Hung | b060def | 2022-05-26 07:41:33 +0000 | [diff] [blame] | 65 | /** |
| 66 | * Log debug messages about the vibrator. |
| 67 | * Enable this via "adb shell setprop log.tag.InputReaderVibrator DEBUG" (requires restart) |
| 68 | */ |
| 69 | const bool DEBUG_VIBRATOR = |
| 70 | __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] | 71 | |
Arthur Hung | b060def | 2022-05-26 07:41:33 +0000 | [diff] [blame] | 72 | /** |
| 73 | * Log debug messages about fusing stylus data. |
| 74 | * Enable this via "adb shell setprop log.tag.InputReaderStylusFusion DEBUG" (requires restart) |
| 75 | */ |
| 76 | const bool DEBUG_STYLUS_FUSION = |
| 77 | __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] | 78 | |
Arthur Hung | b060def | 2022-05-26 07:41:33 +0000 | [diff] [blame] | 79 | /** |
| 80 | * Log detailed debug messages about input device lights. |
| 81 | * Enable this via "adb shell setprop log.tag.InputReaderLightDetails DEBUG" (requires restart) |
| 82 | */ |
| 83 | const bool DEBUG_LIGHT_DETAILS = |
| 84 | __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "LightDetails", ANDROID_LOG_INFO); |
Prabir Pradhan | 011ca3d | 2023-02-22 21:31:39 +0000 | [diff] [blame] | 85 | |
Arthur Hung | b060def | 2022-05-26 07:41:33 +0000 | [diff] [blame] | 86 | } // namespace android |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 87 | |
| 88 | #define INDENT " " |
| 89 | #define INDENT2 " " |
| 90 | #define INDENT3 " " |
| 91 | #define INDENT4 " " |
| 92 | #define INDENT5 " " |
| 93 | |
| 94 | #include <input/Input.h> |
| 95 | |
| 96 | namespace android { |
| 97 | |
| 98 | // --- Static Functions --- |
| 99 | |
| 100 | template <typename T> |
| 101 | inline static T abs(const T& value) { |
| 102 | return value < 0 ? -value : value; |
| 103 | } |
| 104 | |
| 105 | template <typename T> |
| 106 | inline static T min(const T& a, const T& b) { |
| 107 | return a < b ? a : b; |
| 108 | } |
| 109 | |
| 110 | inline static float avg(float x, float y) { |
| 111 | return (x + y) / 2; |
| 112 | } |
| 113 | |
| 114 | static inline const char* toString(bool value) { |
| 115 | return value ? "true" : "false"; |
| 116 | } |
| 117 | |
| 118 | static inline bool sourcesMatchMask(uint32_t sources, uint32_t sourceMask) { |
| 119 | return (sources & sourceMask & ~AINPUT_SOURCE_CLASS_MASK) != 0; |
| 120 | } |
| 121 | |
Zixuan Qu | fecb606 | 2022-11-12 04:44:31 +0000 | [diff] [blame] | 122 | template <typename K, typename V> |
| 123 | static inline std::optional<V> getValueByKey(const std::unordered_map<K, V>& map, K key) { |
| 124 | auto it = map.find(key); |
| 125 | std::optional<V> value = std::nullopt; |
| 126 | if (it != map.end()) { |
| 127 | value = it->second; |
| 128 | } |
| 129 | return value; |
| 130 | } |
| 131 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 132 | } // namespace android |