blob: 79c8a4ba76472ee35be4e562c895c63f8f1e71b1 [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"
37#include "VibrationElement.h"
38
Prabir Pradhan29c95332018-11-14 20:14:11 -080039// Maximum supported size of a vibration pattern.
40// Must be at least 2.
41#define MAX_VIBRATE_PATTERN_SIZE 100
42
Prabir Pradhan29c95332018-11-14 20:14:11 -080043namespace android {
44
Prabir Pradhan28efc192019-11-05 01:10:04 +000045// --- InputReaderConfiguration ---
Prabir Pradhan29c95332018-11-14 20:14:11 -080046
47/*
48 * Input reader configuration.
49 *
50 * Specifies various options that modify the behavior of the input reader.
51 */
52struct InputReaderConfiguration {
53 // Describes changes that have occurred.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000054 enum class Change : uint32_t {
Harry Cuttsa546ba82023-01-13 17:21:00 +000055 // The mouse pointer speed changed.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000056 POINTER_SPEED = 1u << 0,
Prabir Pradhan29c95332018-11-14 20:14:11 -080057
58 // The pointer gesture control changed.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000059 POINTER_GESTURE_ENABLEMENT = 1u << 1,
Prabir Pradhan29c95332018-11-14 20:14:11 -080060
61 // The display size or orientation changed.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000062 DISPLAY_INFO = 1u << 2,
Prabir Pradhan29c95332018-11-14 20:14:11 -080063
64 // The visible touches option changed.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000065 SHOW_TOUCHES = 1u << 3,
Prabir Pradhan29c95332018-11-14 20:14:11 -080066
67 // The keyboard layouts must be reloaded.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000068 KEYBOARD_LAYOUTS = 1u << 4,
Prabir Pradhan29c95332018-11-14 20:14:11 -080069
70 // The device name alias supplied by the may have changed for some devices.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000071 DEVICE_ALIAS = 1u << 5,
Prabir Pradhan29c95332018-11-14 20:14:11 -080072
73 // The location calibration matrix changed.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000074 TOUCH_AFFINE_TRANSFORMATION = 1u << 6,
Prabir Pradhan29c95332018-11-14 20:14:11 -080075
76 // The presence of an external stylus has changed.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000077 EXTERNAL_STYLUS_PRESENCE = 1u << 7,
Prabir Pradhan29c95332018-11-14 20:14:11 -080078
79 // The pointer capture mode has changed.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000080 POINTER_CAPTURE = 1u << 8,
Prabir Pradhan29c95332018-11-14 20:14:11 -080081
82 // The set of disabled input devices (disabledDevices) has changed.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000083 ENABLED_STATE = 1u << 9,
Prabir Pradhan29c95332018-11-14 20:14:11 -080084
Ambrus Weisz7bc23bf2022-10-04 13:13:07 +000085 // The device type has been updated.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000086 DEVICE_TYPE = 1u << 10,
Ambrus Weisz7bc23bf2022-10-04 13:13:07 +000087
Zixuan Qufecb6062022-11-12 04:44:31 +000088 // The keyboard layout association has changed.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000089 KEYBOARD_LAYOUT_ASSOCIATION = 1u << 11,
Zixuan Qufecb6062022-11-12 04:44:31 +000090
Prabir Pradhan7aa7ff02022-12-21 21:05:38 +000091 // The stylus button reporting configurations has changed.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000092 STYLUS_BUTTON_REPORTING = 1u << 12,
Prabir Pradhan7aa7ff02022-12-21 21:05:38 +000093
Harry Cuttsa546ba82023-01-13 17:21:00 +000094 // The touchpad settings changed.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000095 TOUCHPAD_SETTINGS = 1u << 13,
Harry Cuttsa546ba82023-01-13 17:21:00 +000096
Prabir Pradhan29c95332018-11-14 20:14:11 -080097 // All devices must be reopened.
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000098 MUST_REOPEN = 1u << 31,
Prabir Pradhan29c95332018-11-14 20:14:11 -080099 };
100
101 // Gets the amount of time to disable virtual keys after the screen is touched
102 // in order to filter out accidental virtual key presses due to swiping gestures
103 // or taps near the edge of the display. May be 0 to disable the feature.
104 nsecs_t virtualKeyQuietTime;
105
106 // The excluded device names for the platform.
107 // Devices with these names will be ignored.
108 std::vector<std::string> excludedDeviceNames;
109
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -0700110 // The associations between input ports and display ports.
111 // Used to determine which DisplayViewport should be tied to which InputDevice.
112 std::unordered_map<std::string, uint8_t> portAssociations;
113
Zixuan Qufecb6062022-11-12 04:44:31 +0000114 // The associations between input device physical port locations and display unique ids.
Christine Franks1ba71cc2021-04-07 14:37:42 -0700115 // Used to determine which DisplayViewport should be tied to which InputDevice.
116 std::unordered_map<std::string, std::string> uniqueIdAssociations;
117
Ambrus Weisz7bc23bf2022-10-04 13:13:07 +0000118 // The associations between input device ports device types.
119 // This is used to determine which device type and source should be tied to which InputDevice.
120 std::unordered_map<std::string, std::string> deviceTypeAssociations;
121
Zixuan Qufecb6062022-11-12 04:44:31 +0000122 // The map from the input device physical port location to the input device layout info.
123 // Can be used to determine the layout of the keyboard device.
124 std::unordered_map<std::string, KeyboardLayoutInfo> keyboardLayoutAssociations;
125
Garfield Tan888a6a42020-01-09 11:39:16 -0800126 // The suggested display ID to show the cursor.
127 int32_t defaultPointerDisplayId;
128
Harry Cuttse78184b2024-01-08 15:54:58 +0000129 // The mouse pointer speed, as a number from -7 (slowest) to 7 (fastest).
130 //
131 // Currently only used when the enable_new_mouse_pointer_ballistics flag is enabled.
132 int32_t mousePointerSpeed;
133
Prabir Pradhan777245c2024-01-19 20:44:36 +0000134 // Displays on which an acceleration curve shouldn't be applied for pointer movements from mice.
Harry Cuttse78184b2024-01-08 15:54:58 +0000135 //
136 // Currently only used when the enable_new_mouse_pointer_ballistics flag is enabled.
Prabir Pradhan777245c2024-01-19 20:44:36 +0000137 std::set<int32_t> displaysWithMousePointerAccelerationDisabled;
Harry Cuttse78184b2024-01-08 15:54:58 +0000138
Prabir Pradhan29c95332018-11-14 20:14:11 -0800139 // Velocity control parameters for mouse pointer movements.
Harry Cuttse78184b2024-01-08 15:54:58 +0000140 //
141 // If the enable_new_mouse_pointer_ballistics flag is enabled, these are ignored and the values
142 // of mousePointerSpeed and mousePointerAccelerationEnabled used instead.
Prabir Pradhan29c95332018-11-14 20:14:11 -0800143 VelocityControlParameters pointerVelocityControlParameters;
144
145 // Velocity control parameters for mouse wheel movements.
146 VelocityControlParameters wheelVelocityControlParameters;
147
148 // True if pointer gestures are enabled.
149 bool pointerGesturesEnabled;
150
151 // Quiet time between certain pointer gesture transitions.
152 // Time to allow for all fingers or buttons to settle into a stable state before
153 // starting a new gesture.
154 nsecs_t pointerGestureQuietInterval;
155
156 // The minimum speed that a pointer must travel for us to consider switching the active
157 // touch pointer to it during a drag. This threshold is set to avoid switching due
158 // to noise from a finger resting on the touch pad (perhaps just pressing it down).
159 float pointerGestureDragMinSwitchSpeed; // in pixels per second
160
161 // Tap gesture delay time.
162 // The time between down and up must be less than this to be considered a tap.
163 nsecs_t pointerGestureTapInterval;
164
165 // Tap drag gesture delay time.
166 // The time between the previous tap's up and the next down must be less than
167 // this to be considered a drag. Otherwise, the previous tap is finished and a
168 // new tap begins.
169 //
170 // Note that the previous tap will be held down for this entire duration so this
171 // interval must be shorter than the long press timeout.
172 nsecs_t pointerGestureTapDragInterval;
173
174 // The distance in pixels that the pointer is allowed to move from initial down
175 // to up and still be called a tap.
176 float pointerGestureTapSlop; // in pixels
177
178 // Time after the first touch points go down to settle on an initial centroid.
179 // This is intended to be enough time to handle cases where the user puts down two
180 // fingers at almost but not quite exactly the same time.
181 nsecs_t pointerGestureMultitouchSettleInterval;
182
183 // The transition from PRESS to SWIPE or FREEFORM gesture mode is made when
184 // at least two pointers have moved at least this far from their starting place.
185 float pointerGestureMultitouchMinDistance; // in pixels
186
187 // The transition from PRESS to SWIPE gesture mode can only occur when the
188 // cosine of the angle between the two vectors is greater than or equal to than this value
189 // which indicates that the vectors are oriented in the same direction.
190 // When the vectors are oriented in the exactly same direction, the cosine is 1.0.
191 // (In exactly opposite directions, the cosine is -1.0.)
192 float pointerGestureSwipeTransitionAngleCosine;
193
194 // The transition from PRESS to SWIPE gesture mode can only occur when the
195 // fingers are no more than this far apart relative to the diagonal size of
196 // the touch pad. For example, a ratio of 0.5 means that the fingers must be
197 // no more than half the diagonal size of the touch pad apart.
198 float pointerGestureSwipeMaxWidthRatio;
199
200 // The gesture movement speed factor relative to the size of the display.
201 // Movement speed applies when the fingers are moving in the same direction.
202 // Without acceleration, a full swipe of the touch pad diagonal in movement mode
203 // will cover this portion of the display diagonal.
204 float pointerGestureMovementSpeedRatio;
205
206 // The gesture zoom speed factor relative to the size of the display.
207 // Zoom speed applies when the fingers are mostly moving relative to each other
208 // to execute a scale gesture or similar.
209 // Without acceleration, a full swipe of the touch pad diagonal in zoom mode
210 // will cover this portion of the display diagonal.
211 float pointerGestureZoomSpeedRatio;
212
213 // True to show the location of touches on the touch screen as spots.
214 bool showTouches;
215
Prabir Pradhan5cc1a692021-08-06 14:01:18 +0000216 // The latest request to enable or disable Pointer Capture.
217 PointerCaptureRequest pointerCaptureRequest;
Prabir Pradhan29c95332018-11-14 20:14:11 -0800218
Harry Cuttsa546ba82023-01-13 17:21:00 +0000219 // The touchpad pointer speed, as a number from -7 (slowest) to 7 (fastest).
220 int32_t touchpadPointerSpeed;
221
222 // True to invert the touchpad scrolling direction, so that moving two fingers downwards on the
223 // touchpad scrolls the content upwards.
224 bool touchpadNaturalScrollingEnabled;
225
226 // True to enable tap-to-click on touchpads.
227 bool touchpadTapToClickEnabled;
228
Harry Cuttse0e799d2024-01-24 16:27:56 +0000229 // True to enable tap dragging on touchpads.
230 bool touchpadTapDraggingEnabled;
231
Harry Cuttsa546ba82023-01-13 17:21:00 +0000232 // True to enable a zone on the right-hand side of touchpads where clicks will be turned into
233 // context (a.k.a. "right") clicks.
234 bool touchpadRightClickZoneEnabled;
235
Prabir Pradhan29c95332018-11-14 20:14:11 -0800236 // The set of currently disabled input devices.
Siarhei Vishniakouc6f61192019-07-23 18:12:31 +0000237 std::set<int32_t> disabledDevices;
Prabir Pradhan29c95332018-11-14 20:14:11 -0800238
Prabir Pradhan7aa7ff02022-12-21 21:05:38 +0000239 // True if stylus button reporting through motion events should be enabled, in which case
240 // stylus button state changes are reported through motion events.
241 bool stylusButtonMotionEventsEnabled;
242
Seunghwan Choi2de48e42023-01-17 20:45:15 +0900243 // True if a pointer icon should be shown for direct stylus pointers.
244 bool stylusPointerIconEnabled;
245
Prabir Pradhan5cc1a692021-08-06 14:01:18 +0000246 InputReaderConfiguration()
247 : virtualKeyQuietTime(0),
Harry Cuttse78184b2024-01-08 15:54:58 +0000248 mousePointerSpeed(0),
Prabir Pradhan777245c2024-01-19 20:44:36 +0000249 displaysWithMousePointerAccelerationDisabled(),
Christine Franks46d8a1e2022-01-05 16:11:48 -0800250 pointerVelocityControlParameters(1.0f, 500.0f, 3000.0f,
251 static_cast<float>(
252 android::os::IInputConstants::
253 DEFAULT_POINTER_ACCELERATION)),
Prabir Pradhan29c95332018-11-14 20:14:11 -0800254 wheelVelocityControlParameters(1.0f, 15.0f, 50.0f, 4.0f),
255 pointerGesturesEnabled(true),
Prabir Pradhan5cc1a692021-08-06 14:01:18 +0000256 pointerGestureQuietInterval(100 * 1000000LL), // 100 ms
257 pointerGestureDragMinSwitchSpeed(50), // 50 pixels per second
258 pointerGestureTapInterval(150 * 1000000LL), // 150 ms
259 pointerGestureTapDragInterval(150 * 1000000LL), // 150 ms
260 pointerGestureTapSlop(10.0f), // 10 pixels
Prabir Pradhan29c95332018-11-14 20:14:11 -0800261 pointerGestureMultitouchSettleInterval(100 * 1000000LL), // 100 ms
Prabir Pradhan5cc1a692021-08-06 14:01:18 +0000262 pointerGestureMultitouchMinDistance(15), // 15 pixels
263 pointerGestureSwipeTransitionAngleCosine(0.2588f), // cosine of 75 degrees
Prabir Pradhan29c95332018-11-14 20:14:11 -0800264 pointerGestureSwipeMaxWidthRatio(0.25f),
265 pointerGestureMovementSpeedRatio(0.8f),
266 pointerGestureZoomSpeedRatio(0.3f),
Prabir Pradhan5cc1a692021-08-06 14:01:18 +0000267 showTouches(false),
Prabir Pradhan7aa7ff02022-12-21 21:05:38 +0000268 pointerCaptureRequest(),
Harry Cuttsa546ba82023-01-13 17:21:00 +0000269 touchpadPointerSpeed(0),
270 touchpadNaturalScrollingEnabled(true),
271 touchpadTapToClickEnabled(true),
Harry Cuttse0e799d2024-01-24 16:27:56 +0000272 touchpadTapDraggingEnabled(false),
Harry Cuttsa546ba82023-01-13 17:21:00 +0000273 touchpadRightClickZoneEnabled(false),
Seunghwan Choi2de48e42023-01-17 20:45:15 +0900274 stylusButtonMotionEventsEnabled(true),
275 stylusPointerIconEnabled(false) {}
Prabir Pradhan29c95332018-11-14 20:14:11 -0800276
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -0700277 std::optional<DisplayViewport> getDisplayViewportByType(ViewportType type) const;
278 std::optional<DisplayViewport> getDisplayViewportByUniqueId(const std::string& uniqueDisplayId)
279 const;
280 std::optional<DisplayViewport> getDisplayViewportByPort(uint8_t physicalPort) const;
Garfield Tan888a6a42020-01-09 11:39:16 -0800281 std::optional<DisplayViewport> getDisplayViewportById(int32_t displayId) const;
Prabir Pradhan29c95332018-11-14 20:14:11 -0800282 void setDisplayViewports(const std::vector<DisplayViewport>& viewports);
283
Prabir Pradhan29c95332018-11-14 20:14:11 -0800284 void dump(std::string& dump) const;
285 void dumpViewport(std::string& dump, const DisplayViewport& viewport) const;
286
287private:
288 std::vector<DisplayViewport> mDisplays;
289};
290
Prabir Pradhan4bf6d452023-04-18 21:26:56 +0000291using ConfigurationChanges = ftl::Flags<InputReaderConfiguration::Change>;
292
293// --- InputReaderInterface ---
294
295/* The interface for the InputReader shared library.
296 *
297 * Manages one or more threads that process raw input events and sends cooked event data to an
298 * input listener.
299 *
300 * The implementation must guarantee thread safety for this interface. However, since the input
301 * listener is NOT thread safe, all calls to the listener must happen from the same thread.
302 */
303class InputReaderInterface {
304public:
305 InputReaderInterface() {}
306 virtual ~InputReaderInterface() {}
307 /* Dumps the state of the input reader.
308 *
309 * This method may be called on any thread (usually by the input manager). */
310 virtual void dump(std::string& dump) = 0;
311
312 /* Called by the heartbeat to ensures that the reader has not deadlocked. */
313 virtual void monitor() = 0;
314
315 /* Returns true if the input device is enabled. */
316 virtual bool isInputDeviceEnabled(int32_t deviceId) = 0;
317
318 /* Makes the reader start processing events from the kernel. */
319 virtual status_t start() = 0;
320
321 /* Makes the reader stop processing any more events. */
322 virtual status_t stop() = 0;
323
324 /* Gets information about all input devices.
325 *
326 * This method may be called on any thread (usually by the input manager).
327 */
328 virtual std::vector<InputDeviceInfo> getInputDevices() const = 0;
329
330 /* Query current input state. */
331 virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask, int32_t scanCode) = 0;
332 virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask, int32_t keyCode) = 0;
333 virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask, int32_t sw) = 0;
334
335 virtual void addKeyRemapping(int32_t deviceId, int32_t fromKeyCode,
336 int32_t toKeyCode) const = 0;
337
338 virtual int32_t getKeyCodeForKeyLocation(int32_t deviceId, int32_t locationKeyCode) const = 0;
339
340 /* Toggle Caps Lock */
341 virtual void toggleCapsLockState(int32_t deviceId) = 0;
342
343 /* Determine whether physical keys exist for the given framework-domain key codes. */
344 virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask,
345 const std::vector<int32_t>& keyCodes, uint8_t* outFlags) = 0;
346
347 /* Requests that a reconfiguration of all input devices.
348 * The changes flag is a bitfield that indicates what has changed and whether
349 * the input devices must all be reopened. */
350 virtual void requestRefreshConfiguration(ConfigurationChanges changes) = 0;
351
352 /* Controls the vibrator of a particular input device. */
353 virtual void vibrate(int32_t deviceId, const VibrationSequence& sequence, ssize_t repeat,
354 int32_t token) = 0;
355 virtual void cancelVibrate(int32_t deviceId, int32_t token) = 0;
356
357 virtual bool isVibrating(int32_t deviceId) = 0;
358
359 virtual std::vector<int32_t> getVibratorIds(int32_t deviceId) = 0;
360 /* Get battery level of a particular input device. */
361 virtual std::optional<int32_t> getBatteryCapacity(int32_t deviceId) = 0;
362 /* Get battery status of a particular input device. */
363 virtual std::optional<int32_t> getBatteryStatus(int32_t deviceId) = 0;
364 /* Get the device path for the battery of an input device. */
365 virtual std::optional<std::string> getBatteryDevicePath(int32_t deviceId) = 0;
366
367 virtual std::vector<InputDeviceLightInfo> getLights(int32_t deviceId) = 0;
368
369 virtual std::vector<InputDeviceSensorInfo> getSensors(int32_t deviceId) = 0;
370
371 /* Return true if the device can send input events to the specified display. */
372 virtual bool canDispatchToDisplay(int32_t deviceId, int32_t displayId) = 0;
373
374 /* Enable sensor in input reader mapper. */
375 virtual bool enableSensor(int32_t deviceId, InputDeviceSensorType sensorType,
376 std::chrono::microseconds samplingPeriod,
377 std::chrono::microseconds maxBatchReportLatency) = 0;
378
379 /* Disable sensor in input reader mapper. */
380 virtual void disableSensor(int32_t deviceId, InputDeviceSensorType sensorType) = 0;
381
382 /* Flush sensor data in input reader mapper. */
383 virtual void flushSensor(int32_t deviceId, InputDeviceSensorType sensorType) = 0;
384
385 /* Set color for the light */
386 virtual bool setLightColor(int32_t deviceId, int32_t lightId, int32_t color) = 0;
387 /* Set player ID for the light */
388 virtual bool setLightPlayerId(int32_t deviceId, int32_t lightId, int32_t playerId) = 0;
389 /* Get light color */
390 virtual std::optional<int32_t> getLightColor(int32_t deviceId, int32_t lightId) = 0;
391 /* Get light player ID */
392 virtual std::optional<int32_t> getLightPlayerId(int32_t deviceId, int32_t lightId) = 0;
393
394 /* Get the Bluetooth address of an input device, if known. */
395 virtual std::optional<std::string> getBluetoothAddress(int32_t deviceId) const = 0;
396
397 /* Sysfs node change reported. Recreate device if required to incorporate the new sysfs nodes */
398 virtual void sysfsNodeChanged(const std::string& sysfsNodePath) = 0;
399};
400
Prabir Pradhan28efc192019-11-05 01:10:04 +0000401// --- TouchAffineTransformation ---
402
Prabir Pradhan29c95332018-11-14 20:14:11 -0800403struct TouchAffineTransformation {
404 float x_scale;
405 float x_ymix;
406 float x_offset;
407 float y_xmix;
408 float y_scale;
409 float y_offset;
410
411 TouchAffineTransformation() :
412 x_scale(1.0f), x_ymix(0.0f), x_offset(0.0f),
413 y_xmix(0.0f), y_scale(1.0f), y_offset(0.0f) {
414 }
415
416 TouchAffineTransformation(float xscale, float xymix, float xoffset,
417 float yxmix, float yscale, float yoffset) :
418 x_scale(xscale), x_ymix(xymix), x_offset(xoffset),
419 y_xmix(yxmix), y_scale(yscale), y_offset(yoffset) {
420 }
421
422 void applyTo(float& x, float& y) const;
423};
424
Prabir Pradhan28efc192019-11-05 01:10:04 +0000425// --- InputReaderPolicyInterface ---
426
Prabir Pradhan29c95332018-11-14 20:14:11 -0800427/*
428 * Input reader policy interface.
429 *
430 * The input reader policy is used by the input reader to interact with the Window Manager
431 * and other system components.
432 *
433 * The actual implementation is partially supported by callbacks into the DVM
434 * via JNI. This interface is also mocked in the unit tests.
435 *
Prabir Pradhan28efc192019-11-05 01:10:04 +0000436 * These methods will NOT re-enter the input reader interface, so they may be called from
437 * any method in the input reader interface.
Prabir Pradhan29c95332018-11-14 20:14:11 -0800438 */
439class InputReaderPolicyInterface : public virtual RefBase {
440protected:
441 InputReaderPolicyInterface() { }
442 virtual ~InputReaderPolicyInterface() { }
443
444public:
445 /* Gets the input reader configuration. */
446 virtual void getReaderConfiguration(InputReaderConfiguration* outConfig) = 0;
447
448 /* Gets a pointer controller associated with the specified cursor device (ie. a mouse). */
Michael Wright17db18e2020-06-26 20:51:44 +0100449 virtual std::shared_ptr<PointerControllerInterface> obtainPointerController(
450 int32_t deviceId) = 0;
Prabir Pradhan29c95332018-11-14 20:14:11 -0800451
452 /* Notifies the input reader policy that some input devices have changed
453 * and provides information about all current input devices.
454 */
Arthur Hung7c3ae9c2019-03-11 11:23:03 +0800455 virtual void notifyInputDevicesChanged(const std::vector<InputDeviceInfo>& inputDevices) = 0;
Prabir Pradhan29c95332018-11-14 20:14:11 -0800456
457 /* Gets the keyboard layout for a particular input device. */
Chris Ye3a1e4462020-08-12 10:13:15 -0700458 virtual std::shared_ptr<KeyCharacterMap> getKeyboardLayoutOverlay(
Vaibhav Devmuraridec30802023-07-11 15:02:03 +0000459 const InputDeviceIdentifier& identifier,
460 const std::optional<KeyboardLayoutInfo> keyboardLayoutInfo) = 0;
Prabir Pradhan29c95332018-11-14 20:14:11 -0800461
462 /* Gets a user-supplied alias for a particular input device, or an empty string if none. */
463 virtual std::string getDeviceAlias(const InputDeviceIdentifier& identifier) = 0;
464
465 /* Gets the affine calibration associated with the specified device. */
466 virtual TouchAffineTransformation getTouchAffineTransformation(
Michael Wrighta9cf4192022-12-01 23:46:39 +0000467 const std::string& inputDeviceDescriptor, ui::Rotation surfaceRotation) = 0;
Prabir Pradhanda20b172022-09-26 17:01:18 +0000468 /* Notifies the input reader policy that a stylus gesture has started. */
469 virtual void notifyStylusGestureStarted(int32_t deviceId, nsecs_t eventTime) = 0;
Arpit Singhb3b3f732023-07-04 14:30:05 +0000470
471 /* Returns true if any InputConnection is currently active. */
472 virtual bool isInputMethodConnectionActive() = 0;
Byoungho Jungda10dd32023-10-06 17:03:45 +0900473
Prabir Pradhan19767602023-11-03 16:53:31 +0000474 /* Gets the viewport of a particular display that the pointer device is associated with. If
475 * the pointer device is not associated with any display, it should ADISPLAY_IS_NONE to get
476 * the viewport that should be used. The device should get a new viewport using this method
477 * every time there is a display configuration change. The logical bounds of the viewport should
478 * be used as the range of possible values for pointing devices, like mice and touchpads.
Byoungho Jungda10dd32023-10-06 17:03:45 +0900479 */
Prabir Pradhan19767602023-11-03 16:53:31 +0000480 virtual std::optional<DisplayViewport> getPointerViewportForAssociatedDisplay(
481 int32_t associatedDisplayId = ADISPLAY_ID_NONE) = 0;
Prabir Pradhan29c95332018-11-14 20:14:11 -0800482};
483
484} // namespace android