blob: 6093c91e34008ff677ff47d10c2e6636da942dcf [file] [log] [blame]
Prabir Pradhan29c95332018-11-14 20:14:11 -08001/*
2 * Copyright (C) 2018 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 Pradhan29c95332018-11-14 20:14:11 -080018
Christine Franks46d8a1e2022-01-05 16:11:48 -080019#include <android/os/IInputConstants.h>
Prabir Pradhan28efc192019-11-05 01:10:04 +000020#include <input/DisplayViewport.h>
Prabir Pradhan29c95332018-11-14 20:14:11 -080021#include <input/Input.h>
22#include <input/InputDevice.h>
Prabir Pradhan29c95332018-11-14 20:14:11 -080023#include <input/VelocityControl.h>
24#include <input/VelocityTracker.h>
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +000025#include <stddef.h>
Michael Wrighta9cf4192022-12-01 23:46:39 +000026#include <ui/Rotation.h>
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +000027#include <unistd.h>
Prabir Pradhan28efc192019-11-05 01:10:04 +000028#include <utils/Errors.h>
Prabir Pradhan29c95332018-11-14 20:14:11 -080029#include <utils/RefBase.h>
Prabir Pradhan29c95332018-11-14 20:14:11 -080030
Siarhei Vishniakouc6f61192019-07-23 18:12:31 +000031#include <optional>
32#include <set>
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -070033#include <unordered_map>
Prabir Pradhan29c95332018-11-14 20:14:11 -080034#include <vector>
35
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +000036#include "PointerControllerInterface.h"
Abdelrahman Awadalla8c4160d2024-08-05 16:26:10 +000037#include "TouchpadHardwareState.h"
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +000038#include "VibrationElement.h"
Omar Abdelmonem5e70e962024-08-06 09:38:42 +000039#include "include/gestures.h"
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +000040
Prabir Pradhan29c95332018-11-14 20:14:11 -080041// Maximum supported size of a vibration pattern.
42// Must be at least 2.
43#define MAX_VIBRATE_PATTERN_SIZE 100
44
Prabir Pradhan29c95332018-11-14 20:14:11 -080045namespace android {
46
Prabir Pradhan28efc192019-11-05 01:10:04 +000047// --- InputReaderConfiguration ---
Prabir Pradhan29c95332018-11-14 20:14:11 -080048
49/*
50 * Input reader configuration.
51 *
52 * Specifies various options that modify the behavior of the input reader.
53 */
54struct InputReaderConfiguration {
55 // Describes changes that have occurred.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000056 enum class Change : uint32_t {
Harry Cuttsa546ba82023-01-13 17:21:00 +000057 // The mouse pointer speed changed.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000058 POINTER_SPEED = 1u << 0,
Prabir Pradhan29c95332018-11-14 20:14:11 -080059
60 // The pointer gesture control changed.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000061 POINTER_GESTURE_ENABLEMENT = 1u << 1,
Prabir Pradhan29c95332018-11-14 20:14:11 -080062
63 // The display size or orientation changed.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000064 DISPLAY_INFO = 1u << 2,
Prabir Pradhan29c95332018-11-14 20:14:11 -080065
Prabir Pradhan29c95332018-11-14 20:14:11 -080066 // The keyboard layouts must be reloaded.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000067 KEYBOARD_LAYOUTS = 1u << 4,
Prabir Pradhan29c95332018-11-14 20:14:11 -080068
69 // The device name alias supplied by the may have changed for some devices.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000070 DEVICE_ALIAS = 1u << 5,
Prabir Pradhan29c95332018-11-14 20:14:11 -080071
72 // The location calibration matrix changed.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000073 TOUCH_AFFINE_TRANSFORMATION = 1u << 6,
Prabir Pradhan29c95332018-11-14 20:14:11 -080074
75 // The presence of an external stylus has changed.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000076 EXTERNAL_STYLUS_PRESENCE = 1u << 7,
Prabir Pradhan29c95332018-11-14 20:14:11 -080077
78 // The pointer capture mode has changed.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000079 POINTER_CAPTURE = 1u << 8,
Prabir Pradhan29c95332018-11-14 20:14:11 -080080
81 // The set of disabled input devices (disabledDevices) has changed.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000082 ENABLED_STATE = 1u << 9,
Prabir Pradhan29c95332018-11-14 20:14:11 -080083
Ambrus Weisz7bc23bf2022-10-04 13:13:07 +000084 // The device type has been updated.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000085 DEVICE_TYPE = 1u << 10,
Ambrus Weisz7bc23bf2022-10-04 13:13:07 +000086
Zixuan Qufecb6062022-11-12 04:44:31 +000087 // The keyboard layout association has changed.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000088 KEYBOARD_LAYOUT_ASSOCIATION = 1u << 11,
Zixuan Qufecb6062022-11-12 04:44:31 +000089
Prabir Pradhan7aa7ff02022-12-21 21:05:38 +000090 // The stylus button reporting configurations has changed.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000091 STYLUS_BUTTON_REPORTING = 1u << 12,
Prabir Pradhan7aa7ff02022-12-21 21:05:38 +000092
Harry Cuttsa546ba82023-01-13 17:21:00 +000093 // The touchpad settings changed.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000094 TOUCHPAD_SETTINGS = 1u << 13,
Harry Cuttsa546ba82023-01-13 17:21:00 +000095
Linnan Lie5657f22024-09-13 21:54:37 +080096 // The key remapping has changed.
97 KEY_REMAPPING = 1u << 14,
98
Jimmyd77178e2024-09-18 22:55:45 +000099 // The mouse settings changed, this includes mouse reverse vertical scrolling and swap
100 // primary button.
Jimmy2ac7e812024-09-13 19:17:25 +0000101 MOUSE_SETTINGS = 1u << 15,
102
Prabir Pradhan29c95332018-11-14 20:14:11 -0800103 // All devices must be reopened.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +0000104 MUST_REOPEN = 1u << 31,
Prabir Pradhan29c95332018-11-14 20:14:11 -0800105 };
106
107 // Gets the amount of time to disable virtual keys after the screen is touched
108 // in order to filter out accidental virtual key presses due to swiping gestures
109 // or taps near the edge of the display. May be 0 to disable the feature.
110 nsecs_t virtualKeyQuietTime;
111
112 // The excluded device names for the platform.
113 // Devices with these names will be ignored.
114 std::vector<std::string> excludedDeviceNames;
115
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -0700116 // The associations between input ports and display ports.
117 // Used to determine which DisplayViewport should be tied to which InputDevice.
Mayank Garg60b45622024-05-05 20:23:56 -0700118 std::unordered_map<std::string, uint8_t> inputPortToDisplayPortAssociations;
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -0700119
Antonio Kantek0ac5e092024-04-22 17:10:27 +0000120 // The associations between input device ports and display unique ids.
Christine Franks1ba71cc2021-04-07 14:37:42 -0700121 // Used to determine which DisplayViewport should be tied to which InputDevice.
Mayank Garg60b45622024-05-05 20:23:56 -0700122 std::unordered_map<std::string, std::string> inputPortToDisplayUniqueIdAssociations;
Antonio Kantek0ac5e092024-04-22 17:10:27 +0000123
124 // The associations between input device descriptor and display unique ids.
125 // Used to determine which DisplayViewport should be tied to which InputDevice.
Mayank Garg60b45622024-05-05 20:23:56 -0700126 std::unordered_map<std::string, std::string> inputDeviceDescriptorToDisplayUniqueIdAssociations;
Christine Franks1ba71cc2021-04-07 14:37:42 -0700127
Ambrus Weisz7bc23bf2022-10-04 13:13:07 +0000128 // The associations between input device ports device types.
129 // This is used to determine which device type and source should be tied to which InputDevice.
130 std::unordered_map<std::string, std::string> deviceTypeAssociations;
131
Zixuan Qufecb6062022-11-12 04:44:31 +0000132 // The map from the input device physical port location to the input device layout info.
133 // Can be used to determine the layout of the keyboard device.
134 std::unordered_map<std::string, KeyboardLayoutInfo> keyboardLayoutAssociations;
135
Garfield Tan888a6a42020-01-09 11:39:16 -0800136 // The suggested display ID to show the cursor.
Linnan Li13bf76a2024-05-05 19:18:02 +0800137 ui::LogicalDisplayId defaultPointerDisplayId;
Garfield Tan888a6a42020-01-09 11:39:16 -0800138
Harry Cuttse78184b2024-01-08 15:54:58 +0000139 // The mouse pointer speed, as a number from -7 (slowest) to 7 (fastest).
140 //
141 // Currently only used when the enable_new_mouse_pointer_ballistics flag is enabled.
142 int32_t mousePointerSpeed;
143
Prabir Pradhan777245c2024-01-19 20:44:36 +0000144 // Displays on which an acceleration curve shouldn't be applied for pointer movements from mice.
Harry Cuttse78184b2024-01-08 15:54:58 +0000145 //
146 // Currently only used when the enable_new_mouse_pointer_ballistics flag is enabled.
Linnan Li13bf76a2024-05-05 19:18:02 +0800147 std::set<ui::LogicalDisplayId> displaysWithMousePointerAccelerationDisabled;
Harry Cuttse78184b2024-01-08 15:54:58 +0000148
Prabir Pradhan29c95332018-11-14 20:14:11 -0800149 // Velocity control parameters for mouse pointer movements.
Harry Cuttse78184b2024-01-08 15:54:58 +0000150 //
151 // If the enable_new_mouse_pointer_ballistics flag is enabled, these are ignored and the values
152 // of mousePointerSpeed and mousePointerAccelerationEnabled used instead.
Prabir Pradhan29c95332018-11-14 20:14:11 -0800153 VelocityControlParameters pointerVelocityControlParameters;
154
155 // Velocity control parameters for mouse wheel movements.
156 VelocityControlParameters wheelVelocityControlParameters;
157
158 // True if pointer gestures are enabled.
159 bool pointerGesturesEnabled;
160
161 // Quiet time between certain pointer gesture transitions.
162 // Time to allow for all fingers or buttons to settle into a stable state before
163 // starting a new gesture.
164 nsecs_t pointerGestureQuietInterval;
165
166 // The minimum speed that a pointer must travel for us to consider switching the active
167 // touch pointer to it during a drag. This threshold is set to avoid switching due
168 // to noise from a finger resting on the touch pad (perhaps just pressing it down).
169 float pointerGestureDragMinSwitchSpeed; // in pixels per second
170
171 // Tap gesture delay time.
172 // The time between down and up must be less than this to be considered a tap.
173 nsecs_t pointerGestureTapInterval;
174
175 // Tap drag gesture delay time.
176 // The time between the previous tap's up and the next down must be less than
177 // this to be considered a drag. Otherwise, the previous tap is finished and a
178 // new tap begins.
179 //
180 // Note that the previous tap will be held down for this entire duration so this
181 // interval must be shorter than the long press timeout.
182 nsecs_t pointerGestureTapDragInterval;
183
184 // The distance in pixels that the pointer is allowed to move from initial down
185 // to up and still be called a tap.
186 float pointerGestureTapSlop; // in pixels
187
188 // Time after the first touch points go down to settle on an initial centroid.
189 // This is intended to be enough time to handle cases where the user puts down two
190 // fingers at almost but not quite exactly the same time.
191 nsecs_t pointerGestureMultitouchSettleInterval;
192
193 // The transition from PRESS to SWIPE or FREEFORM gesture mode is made when
194 // at least two pointers have moved at least this far from their starting place.
195 float pointerGestureMultitouchMinDistance; // in pixels
196
197 // The transition from PRESS to SWIPE gesture mode can only occur when the
198 // cosine of the angle between the two vectors is greater than or equal to than this value
199 // which indicates that the vectors are oriented in the same direction.
200 // When the vectors are oriented in the exactly same direction, the cosine is 1.0.
201 // (In exactly opposite directions, the cosine is -1.0.)
202 float pointerGestureSwipeTransitionAngleCosine;
203
204 // The transition from PRESS to SWIPE gesture mode can only occur when the
205 // fingers are no more than this far apart relative to the diagonal size of
206 // the touch pad. For example, a ratio of 0.5 means that the fingers must be
207 // no more than half the diagonal size of the touch pad apart.
208 float pointerGestureSwipeMaxWidthRatio;
209
210 // The gesture movement speed factor relative to the size of the display.
211 // Movement speed applies when the fingers are moving in the same direction.
212 // Without acceleration, a full swipe of the touch pad diagonal in movement mode
213 // will cover this portion of the display diagonal.
214 float pointerGestureMovementSpeedRatio;
215
216 // The gesture zoom speed factor relative to the size of the display.
217 // Zoom speed applies when the fingers are mostly moving relative to each other
218 // to execute a scale gesture or similar.
219 // Without acceleration, a full swipe of the touch pad diagonal in zoom mode
220 // will cover this portion of the display diagonal.
221 float pointerGestureZoomSpeedRatio;
222
Prabir Pradhan5cc1a692021-08-06 14:01:18 +0000223 // The latest request to enable or disable Pointer Capture.
224 PointerCaptureRequest pointerCaptureRequest;
Prabir Pradhan29c95332018-11-14 20:14:11 -0800225
Harry Cuttsa546ba82023-01-13 17:21:00 +0000226 // The touchpad pointer speed, as a number from -7 (slowest) to 7 (fastest).
227 int32_t touchpadPointerSpeed;
228
229 // True to invert the touchpad scrolling direction, so that moving two fingers downwards on the
230 // touchpad scrolls the content upwards.
231 bool touchpadNaturalScrollingEnabled;
232
233 // True to enable tap-to-click on touchpads.
234 bool touchpadTapToClickEnabled;
235
Harry Cuttse0e799d2024-01-24 16:27:56 +0000236 // True to enable tap dragging on touchpads.
237 bool touchpadTapDraggingEnabled;
238
Abdelrahman Awadalla61d0da32024-08-12 17:02:13 +0000239 // True if hardware state update notifications should be sent to the policy.
240 bool shouldNotifyTouchpadHardwareState;
241
Harry Cuttsa546ba82023-01-13 17:21:00 +0000242 // True to enable a zone on the right-hand side of touchpads where clicks will be turned into
243 // context (a.k.a. "right") clicks.
244 bool touchpadRightClickZoneEnabled;
245
Prabir Pradhan29c95332018-11-14 20:14:11 -0800246 // The set of currently disabled input devices.
Siarhei Vishniakouc6f61192019-07-23 18:12:31 +0000247 std::set<int32_t> disabledDevices;
Prabir Pradhan29c95332018-11-14 20:14:11 -0800248
Prabir Pradhan7aa7ff02022-12-21 21:05:38 +0000249 // True if stylus button reporting through motion events should be enabled, in which case
250 // stylus button state changes are reported through motion events.
251 bool stylusButtonMotionEventsEnabled;
252
Seunghwan Choi2de48e42023-01-17 20:45:15 +0900253 // True if a pointer icon should be shown for direct stylus pointers.
254 bool stylusPointerIconEnabled;
255
Linnan Lie5657f22024-09-13 21:54:37 +0800256 // Keycodes to be remapped.
257 std::map<int32_t /* fromKeyCode */, int32_t /* toKeyCode */> keyRemapping;
258
Jimmy2ac7e812024-09-13 19:17:25 +0000259 // True if the external mouse should have its vertical scrolling reversed, so that rotating the
260 // wheel downwards scrolls the content upwards.
261 bool mouseReverseVerticalScrollingEnabled;
262
Jimmyd77178e2024-09-18 22:55:45 +0000263 // True if the connected mouse should have its primary button (default: left click) swapped,
264 // so that the right click will be the primary action button and the left click will be the
265 // secondary action.
266 bool mouseSwapPrimaryButtonEnabled;
267
Prabir Pradhan5cc1a692021-08-06 14:01:18 +0000268 InputReaderConfiguration()
269 : virtualKeyQuietTime(0),
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700270 defaultPointerDisplayId(ui::LogicalDisplayId::DEFAULT),
Harry Cuttse78184b2024-01-08 15:54:58 +0000271 mousePointerSpeed(0),
Prabir Pradhan777245c2024-01-19 20:44:36 +0000272 displaysWithMousePointerAccelerationDisabled(),
Christine Franks46d8a1e2022-01-05 16:11:48 -0800273 pointerVelocityControlParameters(1.0f, 500.0f, 3000.0f,
274 static_cast<float>(
275 android::os::IInputConstants::
276 DEFAULT_POINTER_ACCELERATION)),
Prabir Pradhan29c95332018-11-14 20:14:11 -0800277 wheelVelocityControlParameters(1.0f, 15.0f, 50.0f, 4.0f),
278 pointerGesturesEnabled(true),
Prabir Pradhan5cc1a692021-08-06 14:01:18 +0000279 pointerGestureQuietInterval(100 * 1000000LL), // 100 ms
280 pointerGestureDragMinSwitchSpeed(50), // 50 pixels per second
281 pointerGestureTapInterval(150 * 1000000LL), // 150 ms
282 pointerGestureTapDragInterval(150 * 1000000LL), // 150 ms
283 pointerGestureTapSlop(10.0f), // 10 pixels
Prabir Pradhan29c95332018-11-14 20:14:11 -0800284 pointerGestureMultitouchSettleInterval(100 * 1000000LL), // 100 ms
Prabir Pradhan5cc1a692021-08-06 14:01:18 +0000285 pointerGestureMultitouchMinDistance(15), // 15 pixels
286 pointerGestureSwipeTransitionAngleCosine(0.2588f), // cosine of 75 degrees
Prabir Pradhan29c95332018-11-14 20:14:11 -0800287 pointerGestureSwipeMaxWidthRatio(0.25f),
288 pointerGestureMovementSpeedRatio(0.8f),
289 pointerGestureZoomSpeedRatio(0.3f),
Prabir Pradhan7aa7ff02022-12-21 21:05:38 +0000290 pointerCaptureRequest(),
Harry Cuttsa546ba82023-01-13 17:21:00 +0000291 touchpadPointerSpeed(0),
292 touchpadNaturalScrollingEnabled(true),
293 touchpadTapToClickEnabled(true),
Harry Cuttse0e799d2024-01-24 16:27:56 +0000294 touchpadTapDraggingEnabled(false),
Abdelrahman Awadalla61d0da32024-08-12 17:02:13 +0000295 shouldNotifyTouchpadHardwareState(false),
Harry Cuttsa546ba82023-01-13 17:21:00 +0000296 touchpadRightClickZoneEnabled(false),
Seunghwan Choi2de48e42023-01-17 20:45:15 +0900297 stylusButtonMotionEventsEnabled(true),
Jimmy2ac7e812024-09-13 19:17:25 +0000298 stylusPointerIconEnabled(false),
Jimmyd77178e2024-09-18 22:55:45 +0000299 mouseReverseVerticalScrollingEnabled(false),
300 mouseSwapPrimaryButtonEnabled(false) {}
Prabir Pradhan29c95332018-11-14 20:14:11 -0800301
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -0700302 std::optional<DisplayViewport> getDisplayViewportByType(ViewportType type) const;
303 std::optional<DisplayViewport> getDisplayViewportByUniqueId(const std::string& uniqueDisplayId)
304 const;
305 std::optional<DisplayViewport> getDisplayViewportByPort(uint8_t physicalPort) const;
Linnan Li13bf76a2024-05-05 19:18:02 +0800306 std::optional<DisplayViewport> getDisplayViewportById(ui::LogicalDisplayId displayId) const;
Prabir Pradhan29c95332018-11-14 20:14:11 -0800307 void setDisplayViewports(const std::vector<DisplayViewport>& viewports);
308
Prabir Pradhan29c95332018-11-14 20:14:11 -0800309 void dump(std::string& dump) const;
310 void dumpViewport(std::string& dump, const DisplayViewport& viewport) const;
311
312private:
313 std::vector<DisplayViewport> mDisplays;
314};
315
Prabir Pradhan4bf6d452023-04-18 21:26:56 +0000316using ConfigurationChanges = ftl::Flags<InputReaderConfiguration::Change>;
317
318// --- InputReaderInterface ---
319
320/* The interface for the InputReader shared library.
321 *
322 * Manages one or more threads that process raw input events and sends cooked event data to an
323 * input listener.
324 *
325 * The implementation must guarantee thread safety for this interface. However, since the input
326 * listener is NOT thread safe, all calls to the listener must happen from the same thread.
327 */
328class InputReaderInterface {
329public:
330 InputReaderInterface() {}
331 virtual ~InputReaderInterface() {}
332 /* Dumps the state of the input reader.
333 *
334 * This method may be called on any thread (usually by the input manager). */
335 virtual void dump(std::string& dump) = 0;
336
337 /* Called by the heartbeat to ensures that the reader has not deadlocked. */
338 virtual void monitor() = 0;
339
Prabir Pradhan4bf6d452023-04-18 21:26:56 +0000340 /* Makes the reader start processing events from the kernel. */
341 virtual status_t start() = 0;
342
343 /* Makes the reader stop processing any more events. */
344 virtual status_t stop() = 0;
345
346 /* Gets information about all input devices.
347 *
348 * This method may be called on any thread (usually by the input manager).
349 */
350 virtual std::vector<InputDeviceInfo> getInputDevices() const = 0;
351
352 /* Query current input state. */
353 virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask, int32_t scanCode) = 0;
354 virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask, int32_t keyCode) = 0;
355 virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask, int32_t sw) = 0;
356
Prabir Pradhan4bf6d452023-04-18 21:26:56 +0000357 virtual int32_t getKeyCodeForKeyLocation(int32_t deviceId, int32_t locationKeyCode) const = 0;
358
359 /* Toggle Caps Lock */
360 virtual void toggleCapsLockState(int32_t deviceId) = 0;
361
362 /* Determine whether physical keys exist for the given framework-domain key codes. */
363 virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask,
364 const std::vector<int32_t>& keyCodes, uint8_t* outFlags) = 0;
365
366 /* Requests that a reconfiguration of all input devices.
367 * The changes flag is a bitfield that indicates what has changed and whether
368 * the input devices must all be reopened. */
369 virtual void requestRefreshConfiguration(ConfigurationChanges changes) = 0;
370
371 /* Controls the vibrator of a particular input device. */
372 virtual void vibrate(int32_t deviceId, const VibrationSequence& sequence, ssize_t repeat,
373 int32_t token) = 0;
374 virtual void cancelVibrate(int32_t deviceId, int32_t token) = 0;
375
376 virtual bool isVibrating(int32_t deviceId) = 0;
377
378 virtual std::vector<int32_t> getVibratorIds(int32_t deviceId) = 0;
379 /* Get battery level of a particular input device. */
380 virtual std::optional<int32_t> getBatteryCapacity(int32_t deviceId) = 0;
381 /* Get battery status of a particular input device. */
382 virtual std::optional<int32_t> getBatteryStatus(int32_t deviceId) = 0;
383 /* Get the device path for the battery of an input device. */
384 virtual std::optional<std::string> getBatteryDevicePath(int32_t deviceId) = 0;
385
386 virtual std::vector<InputDeviceLightInfo> getLights(int32_t deviceId) = 0;
387
388 virtual std::vector<InputDeviceSensorInfo> getSensors(int32_t deviceId) = 0;
389
Omar Abdelmonem5e70e962024-08-06 09:38:42 +0000390 virtual std::optional<HardwareProperties> getTouchpadHardwareProperties(int32_t deviceId) = 0;
391
Prabir Pradhan4bf6d452023-04-18 21:26:56 +0000392 /* Return true if the device can send input events to the specified display. */
Linnan Li13bf76a2024-05-05 19:18:02 +0800393 virtual bool canDispatchToDisplay(int32_t deviceId, ui::LogicalDisplayId displayId) = 0;
Prabir Pradhan4bf6d452023-04-18 21:26:56 +0000394
395 /* Enable sensor in input reader mapper. */
396 virtual bool enableSensor(int32_t deviceId, InputDeviceSensorType sensorType,
397 std::chrono::microseconds samplingPeriod,
398 std::chrono::microseconds maxBatchReportLatency) = 0;
399
400 /* Disable sensor in input reader mapper. */
401 virtual void disableSensor(int32_t deviceId, InputDeviceSensorType sensorType) = 0;
402
403 /* Flush sensor data in input reader mapper. */
404 virtual void flushSensor(int32_t deviceId, InputDeviceSensorType sensorType) = 0;
405
406 /* Set color for the light */
407 virtual bool setLightColor(int32_t deviceId, int32_t lightId, int32_t color) = 0;
408 /* Set player ID for the light */
409 virtual bool setLightPlayerId(int32_t deviceId, int32_t lightId, int32_t playerId) = 0;
410 /* Get light color */
411 virtual std::optional<int32_t> getLightColor(int32_t deviceId, int32_t lightId) = 0;
412 /* Get light player ID */
413 virtual std::optional<int32_t> getLightPlayerId(int32_t deviceId, int32_t lightId) = 0;
414
415 /* Get the Bluetooth address of an input device, if known. */
416 virtual std::optional<std::string> getBluetoothAddress(int32_t deviceId) const = 0;
417
418 /* Sysfs node change reported. Recreate device if required to incorporate the new sysfs nodes */
419 virtual void sysfsNodeChanged(const std::string& sysfsNodePath) = 0;
Prabir Pradhan018faea2024-05-08 21:52:54 +0000420
421 /* Get the ID of the InputDevice that was used most recently.
422 *
423 * Returns ReservedInputDeviceId::INVALID_INPUT_DEVICE_ID if no device has been used since boot.
424 */
425 virtual DeviceId getLastUsedInputDeviceId() = 0;
Arpit Singh849beb42024-06-06 07:14:17 +0000426
427 /* Notifies that mouse cursor faded due to typing. */
428 virtual void notifyMouseCursorFadedOnTyping() = 0;
Yanye Li81a590c2024-10-22 19:25:54 +0000429
430 /* Set whether the given input device can wake up the kernel from sleep
431 * when it generates input events. By default, usually only internal (built-in)
432 * input devices can wake the kernel from sleep. For an external input device
433 * that supports remote wakeup to be able to wake the kernel, this must be called
434 * after each time the device is connected/added.
435 *
436 * Returns true if setting power wakeup was successful.
437 */
438 virtual bool setKernelWakeEnabled(int32_t deviceId, bool enabled) = 0;
Prabir Pradhan4bf6d452023-04-18 21:26:56 +0000439};
440
Prabir Pradhan28efc192019-11-05 01:10:04 +0000441// --- TouchAffineTransformation ---
442
Prabir Pradhan29c95332018-11-14 20:14:11 -0800443struct TouchAffineTransformation {
444 float x_scale;
445 float x_ymix;
446 float x_offset;
447 float y_xmix;
448 float y_scale;
449 float y_offset;
450
451 TouchAffineTransformation() :
452 x_scale(1.0f), x_ymix(0.0f), x_offset(0.0f),
453 y_xmix(0.0f), y_scale(1.0f), y_offset(0.0f) {
454 }
455
456 TouchAffineTransformation(float xscale, float xymix, float xoffset,
457 float yxmix, float yscale, float yoffset) :
458 x_scale(xscale), x_ymix(xymix), x_offset(xoffset),
459 y_xmix(yxmix), y_scale(yscale), y_offset(yoffset) {
460 }
461
462 void applyTo(float& x, float& y) const;
463};
464
Prabir Pradhan28efc192019-11-05 01:10:04 +0000465// --- InputReaderPolicyInterface ---
466
Prabir Pradhan29c95332018-11-14 20:14:11 -0800467/*
468 * Input reader policy interface.
469 *
470 * The input reader policy is used by the input reader to interact with the Window Manager
471 * and other system components.
472 *
473 * The actual implementation is partially supported by callbacks into the DVM
474 * via JNI. This interface is also mocked in the unit tests.
475 *
Prabir Pradhan28efc192019-11-05 01:10:04 +0000476 * These methods will NOT re-enter the input reader interface, so they may be called from
477 * any method in the input reader interface.
Prabir Pradhan29c95332018-11-14 20:14:11 -0800478 */
479class InputReaderPolicyInterface : public virtual RefBase {
480protected:
481 InputReaderPolicyInterface() { }
482 virtual ~InputReaderPolicyInterface() { }
483
484public:
485 /* Gets the input reader configuration. */
486 virtual void getReaderConfiguration(InputReaderConfiguration* outConfig) = 0;
487
Prabir Pradhan29c95332018-11-14 20:14:11 -0800488 /* Notifies the input reader policy that some input devices have changed
489 * and provides information about all current input devices.
490 */
Arthur Hung7c3ae9c2019-03-11 11:23:03 +0800491 virtual void notifyInputDevicesChanged(const std::vector<InputDeviceInfo>& inputDevices) = 0;
Prabir Pradhan29c95332018-11-14 20:14:11 -0800492
Abdelrahman Awadalla8c4160d2024-08-05 16:26:10 +0000493 /* Sends the hardware state of a connected touchpad */
494 virtual void notifyTouchpadHardwareState(const SelfContainedHardwareState& schs,
495 int32_t deviceId) = 0;
496
Omar Abdelmonem5ebf21f2024-09-12 11:44:15 +0000497 /* Sends the Info of gestures that happen on the touchpad. */
498 virtual void notifyTouchpadGestureInfo(GestureType type, int32_t deviceId) = 0;
499
Prabir Pradhan29c95332018-11-14 20:14:11 -0800500 /* Gets the keyboard layout for a particular input device. */
Chris Ye3a1e4462020-08-12 10:13:15 -0700501 virtual std::shared_ptr<KeyCharacterMap> getKeyboardLayoutOverlay(
Vaibhav Devmuraridec30802023-07-11 15:02:03 +0000502 const InputDeviceIdentifier& identifier,
503 const std::optional<KeyboardLayoutInfo> keyboardLayoutInfo) = 0;
Prabir Pradhan29c95332018-11-14 20:14:11 -0800504
505 /* Gets a user-supplied alias for a particular input device, or an empty string if none. */
506 virtual std::string getDeviceAlias(const InputDeviceIdentifier& identifier) = 0;
507
508 /* Gets the affine calibration associated with the specified device. */
509 virtual TouchAffineTransformation getTouchAffineTransformation(
Michael Wrighta9cf4192022-12-01 23:46:39 +0000510 const std::string& inputDeviceDescriptor, ui::Rotation surfaceRotation) = 0;
Prabir Pradhanda20b172022-09-26 17:01:18 +0000511 /* Notifies the input reader policy that a stylus gesture has started. */
512 virtual void notifyStylusGestureStarted(int32_t deviceId, nsecs_t eventTime) = 0;
Arpit Singhb3b3f732023-07-04 14:30:05 +0000513
514 /* Returns true if any InputConnection is currently active. */
515 virtual bool isInputMethodConnectionActive() = 0;
Byoungho Jungda10dd32023-10-06 17:03:45 +0900516
Prabir Pradhan19767602023-11-03 16:53:31 +0000517 /* Gets the viewport of a particular display that the pointer device is associated with. If
518 * the pointer device is not associated with any display, it should ADISPLAY_IS_NONE to get
519 * the viewport that should be used. The device should get a new viewport using this method
520 * every time there is a display configuration change. The logical bounds of the viewport should
521 * be used as the range of possible values for pointing devices, like mice and touchpads.
Byoungho Jungda10dd32023-10-06 17:03:45 +0900522 */
Prabir Pradhan19767602023-11-03 16:53:31 +0000523 virtual std::optional<DisplayViewport> getPointerViewportForAssociatedDisplay(
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700524 ui::LogicalDisplayId associatedDisplayId = ui::LogicalDisplayId::INVALID) = 0;
Prabir Pradhan29c95332018-11-14 20:14:11 -0800525};
526
527} // namespace android