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
17 #pragma once
18
19 #define LOG_TAG "InputReader"
20
21 //#define LOG_NDEBUG 0
22 #include <log/log.h>
23 #include <log/log_event_list.h>
24
25 #include <unordered_map>
26
27 namespace android {
28
29 /**
30 * Log debug messages for each raw event received from the EventHub.
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).
34 */
35 bool debugRawEvents();
36
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);
43
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);
50
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);
57
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);
64
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);
71
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);
78
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);
85
86 } // namespace android
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>
abs(const T & value)101 inline static T abs(const T& value) {
102 return value < 0 ? -value : value;
103 }
104
105 template <typename T>
min(const T & a,const T & b)106 inline static T min(const T& a, const T& b) {
107 return a < b ? a : b;
108 }
109
avg(float x,float y)110 inline static float avg(float x, float y) {
111 return (x + y) / 2;
112 }
113
toString(bool value)114 static inline const char* toString(bool value) {
115 return value ? "true" : "false";
116 }
117
sourcesMatchMask(uint32_t sources,uint32_t sourceMask)118 static inline bool sourcesMatchMask(uint32_t sources, uint32_t sourceMask) {
119 return (sources & sourceMask & ~AINPUT_SOURCE_CLASS_MASK) != 0;
120 }
121
122 template <typename K, typename V>
getValueByKey(const std::unordered_map<K,V> & map,K key)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
132 } // namespace android
133