blob: 2bce215b3cb0e7c518f2eff062a52fda316a7cec [file] [log] [blame]
Prabir Pradhanbaa5c822019-08-30 15:27:05 -07001/*
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 Pradhan48108662022-09-09 21:22:04 +000017#pragma once
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070018
19#define LOG_TAG "InputReader"
20
21//#define LOG_NDEBUG 0
Arthur Hungb060def2022-05-26 07:41:33 +000022#include <log/log.h>
23#include <log/log_event_list.h>
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070024
Zixuan Qufecb6062022-11-12 04:44:31 +000025#include <unordered_map>
26
Arthur Hungb060def2022-05-26 07:41:33 +000027namespace android {
Prabir Pradhan011ca3d2023-02-22 21:31:39 +000028
Arthur Hungb060def2022-05-26 07:41:33 +000029/**
30 * Log debug messages for each raw event received from the EventHub.
Prabir Pradhan011ca3d2023-02-22 21:31:39 +000031 * 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 Hungb060def2022-05-26 07:41:33 +000034 */
Prabir Pradhan011ca3d2023-02-22 21:31:39 +000035bool debugRawEvents();
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070036
Arthur Hungb060def2022-05-26 07:41:33 +000037/**
38 * Log debug messages about virtual key processing.
39 * Enable this via "adb shell setprop log.tag.InputReaderVirtualKeys DEBUG" (requires restart)
40 */
41const bool DEBUG_VIRTUAL_KEYS =
42 __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "VirtualKeys", ANDROID_LOG_INFO);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070043
Arthur Hungb060def2022-05-26 07:41:33 +000044/**
45 * Log debug messages about pointers.
46 * Enable this via "adb shell setprop log.tag.InputReaderPointers DEBUG" (requires restart)
47 */
48const bool DEBUG_POINTERS =
49 __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "Pointers", ANDROID_LOG_INFO);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070050
Arthur Hungb060def2022-05-26 07:41:33 +000051/**
52 * Log debug messages about pointer assignment calculations.
53 * Enable this via "adb shell setprop log.tag.InputReaderPointerAssignment DEBUG" (requires restart)
54 */
55const bool DEBUG_POINTER_ASSIGNMENT =
56 __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "PointerAssignment", ANDROID_LOG_INFO);
Prabir Pradhan011ca3d2023-02-22 21:31:39 +000057
Arthur Hungb060def2022-05-26 07:41:33 +000058/**
59 * Log debug messages about gesture detection.
60 * Enable this via "adb shell setprop log.tag.InputReaderGestures DEBUG" (requires restart)
61 */
62const bool DEBUG_GESTURES =
63 __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "Gestures", ANDROID_LOG_INFO);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070064
Arthur Hungb060def2022-05-26 07:41:33 +000065/**
66 * Log debug messages about the vibrator.
67 * Enable this via "adb shell setprop log.tag.InputReaderVibrator DEBUG" (requires restart)
68 */
69const bool DEBUG_VIBRATOR =
70 __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "Vibrator", ANDROID_LOG_INFO);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070071
Arthur Hungb060def2022-05-26 07:41:33 +000072/**
73 * Log debug messages about fusing stylus data.
74 * Enable this via "adb shell setprop log.tag.InputReaderStylusFusion DEBUG" (requires restart)
75 */
76const bool DEBUG_STYLUS_FUSION =
77 __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "StylusFusion", ANDROID_LOG_INFO);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070078
Arthur Hungb060def2022-05-26 07:41:33 +000079/**
80 * Log detailed debug messages about input device lights.
81 * Enable this via "adb shell setprop log.tag.InputReaderLightDetails DEBUG" (requires restart)
82 */
83const bool DEBUG_LIGHT_DETAILS =
84 __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "LightDetails", ANDROID_LOG_INFO);
Prabir Pradhan011ca3d2023-02-22 21:31:39 +000085
Arthur Hungb060def2022-05-26 07:41:33 +000086} // namespace android
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070087
88#define INDENT " "
89#define INDENT2 " "
90#define INDENT3 " "
91#define INDENT4 " "
92#define INDENT5 " "
93
94#include <input/Input.h>
95
96namespace android {
97
98// --- Static Functions ---
99
100template <typename T>
101inline static T abs(const T& value) {
102 return value < 0 ? -value : value;
103}
104
105template <typename T>
106inline static T min(const T& a, const T& b) {
107 return a < b ? a : b;
108}
109
110inline static float avg(float x, float y) {
111 return (x + y) / 2;
112}
113
114static inline const char* toString(bool value) {
115 return value ? "true" : "false";
116}
117
118static inline bool sourcesMatchMask(uint32_t sources, uint32_t sourceMask) {
119 return (sources & sourceMask & ~AINPUT_SOURCE_CLASS_MASK) != 0;
120}
121
Zixuan Qufecb6062022-11-12 04:44:31 +0000122template <typename K, typename V>
123static 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 Pradhanbaa5c822019-08-30 15:27:05 -0700132} // namespace android