blob: d2a7ced864352e7e9c26503e4ddb97eed5502ee2 [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 {
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 */
32const bool DEBUG_RAW_EVENTS =
33 __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "RawEvents", ANDROID_LOG_INFO);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070034
Arthur Hungb060def2022-05-26 07:41:33 +000035/**
36 * Log debug messages about virtual key processing.
37 * Enable this via "adb shell setprop log.tag.InputReaderVirtualKeys DEBUG" (requires restart)
38 */
39const bool DEBUG_VIRTUAL_KEYS =
40 __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "VirtualKeys", ANDROID_LOG_INFO);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070041
Arthur Hungb060def2022-05-26 07:41:33 +000042/**
43 * Log debug messages about pointers.
44 * Enable this via "adb shell setprop log.tag.InputReaderPointers DEBUG" (requires restart)
45 */
46const bool DEBUG_POINTERS =
47 __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "Pointers", ANDROID_LOG_INFO);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070048
Arthur Hungb060def2022-05-26 07:41:33 +000049/**
50 * Log debug messages about pointer assignment calculations.
51 * Enable this via "adb shell setprop log.tag.InputReaderPointerAssignment DEBUG" (requires restart)
52 */
53const 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 */
59const bool DEBUG_GESTURES =
60 __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "Gestures", ANDROID_LOG_INFO);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070061
Arthur Hungb060def2022-05-26 07:41:33 +000062/**
63 * Log debug messages about the vibrator.
64 * Enable this via "adb shell setprop log.tag.InputReaderVibrator DEBUG" (requires restart)
65 */
66const bool DEBUG_VIBRATOR =
67 __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "Vibrator", ANDROID_LOG_INFO);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070068
Arthur Hungb060def2022-05-26 07:41:33 +000069/**
70 * Log debug messages about fusing stylus data.
71 * Enable this via "adb shell setprop log.tag.InputReaderStylusFusion DEBUG" (requires restart)
72 */
73const bool DEBUG_STYLUS_FUSION =
74 __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "StylusFusion", ANDROID_LOG_INFO);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070075
Arthur Hungb060def2022-05-26 07:41:33 +000076/**
77 * Log detailed debug messages about input device lights.
78 * Enable this via "adb shell setprop log.tag.InputReaderLightDetails DEBUG" (requires restart)
79 */
80const bool DEBUG_LIGHT_DETAILS =
81 __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "LightDetails", ANDROID_LOG_INFO);
82} // namespace android
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070083
84#define INDENT " "
85#define INDENT2 " "
86#define INDENT3 " "
87#define INDENT4 " "
88#define INDENT5 " "
89
90#include <input/Input.h>
91
92namespace android {
93
94// --- Static Functions ---
95
96template <typename T>
97inline static T abs(const T& value) {
98 return value < 0 ? -value : value;
99}
100
101template <typename T>
102inline static T min(const T& a, const T& b) {
103 return a < b ? a : b;
104}
105
106inline static float avg(float x, float y) {
107 return (x + y) / 2;
108}
109
110static inline const char* toString(bool value) {
111 return value ? "true" : "false";
112}
113
114static inline bool sourcesMatchMask(uint32_t sources, uint32_t sourceMask) {
115 return (sources & sourceMask & ~AINPUT_SOURCE_CLASS_MASK) != 0;
116}
117
Zixuan Qufecb6062022-11-12 04:44:31 +0000118template <typename K, typename V>
119static 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 Pradhanbaa5c822019-08-30 15:27:05 -0700128} // namespace android