| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 1 | /* | 
|  | 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 Pradhan | 4810866 | 2022-09-09 21:22:04 +0000 | [diff] [blame] | 17 | #pragma once | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 18 |  | 
| Christine Franks | 46d8a1e | 2022-01-05 16:11:48 -0800 | [diff] [blame] | 19 | #include <android/os/IInputConstants.h> | 
| Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 20 | #include <input/DisplayViewport.h> | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 21 | #include <input/Input.h> | 
|  | 22 | #include <input/InputDevice.h> | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 23 | #include <input/VelocityControl.h> | 
|  | 24 | #include <input/VelocityTracker.h> | 
| Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 25 | #include <stddef.h> | 
| Michael Wright | a9cf419 | 2022-12-01 23:46:39 +0000 | [diff] [blame] | 26 | #include <ui/Rotation.h> | 
| Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 27 | #include <unistd.h> | 
| Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 28 | #include <utils/Errors.h> | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 29 | #include <utils/RefBase.h> | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 30 |  | 
| Siarhei Vishniakou | c6f6119 | 2019-07-23 18:12:31 +0000 | [diff] [blame] | 31 | #include <optional> | 
|  | 32 | #include <set> | 
| Siarhei Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 33 | #include <unordered_map> | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 34 | #include <vector> | 
|  | 35 |  | 
| Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 36 | #include "PointerControllerInterface.h" | 
|  | 37 | #include "VibrationElement.h" | 
|  | 38 |  | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 39 | // Maximum supported size of a vibration pattern. | 
|  | 40 | // Must be at least 2. | 
|  | 41 | #define MAX_VIBRATE_PATTERN_SIZE 100 | 
|  | 42 |  | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 43 | namespace android { | 
|  | 44 |  | 
| Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 45 | // --- InputReaderInterface --- | 
|  | 46 |  | 
|  | 47 | /* The interface for the InputReader shared library. | 
|  | 48 | * | 
|  | 49 | * Manages one or more threads that process raw input events and sends cooked event data to an | 
|  | 50 | * input listener. | 
|  | 51 | * | 
|  | 52 | * The implementation must guarantee thread safety for this interface. However, since the input | 
|  | 53 | * listener is NOT thread safe, all calls to the listener must happen from the same thread. | 
|  | 54 | */ | 
| Siarhei Vishniakou | 1805009 | 2021-09-01 13:32:49 -0700 | [diff] [blame] | 55 | class InputReaderInterface { | 
|  | 56 | public: | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 57 | InputReaderInterface() { } | 
|  | 58 | virtual ~InputReaderInterface() { } | 
|  | 59 |  | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 60 | /* Dumps the state of the input reader. | 
|  | 61 | * | 
|  | 62 | * This method may be called on any thread (usually by the input manager). */ | 
|  | 63 | virtual void dump(std::string& dump) = 0; | 
|  | 64 |  | 
| Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 65 | /* Called by the heartbeat to ensures that the reader has not deadlocked. */ | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 66 | virtual void monitor() = 0; | 
|  | 67 |  | 
|  | 68 | /* Returns true if the input device is enabled. */ | 
|  | 69 | virtual bool isInputDeviceEnabled(int32_t deviceId) = 0; | 
|  | 70 |  | 
| Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 71 | /* Makes the reader start processing events from the kernel. */ | 
|  | 72 | virtual status_t start() = 0; | 
|  | 73 |  | 
|  | 74 | /* Makes the reader stop processing any more events. */ | 
|  | 75 | virtual status_t stop() = 0; | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 76 |  | 
|  | 77 | /* Gets information about all input devices. | 
|  | 78 | * | 
|  | 79 | * This method may be called on any thread (usually by the input manager). | 
|  | 80 | */ | 
| Chris Ye | 98d3f53 | 2020-10-01 21:48:59 -0700 | [diff] [blame] | 81 | virtual std::vector<InputDeviceInfo> getInputDevices() const = 0; | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 82 |  | 
|  | 83 | /* Query current input state. */ | 
|  | 84 | virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask, | 
|  | 85 | int32_t scanCode) = 0; | 
|  | 86 | virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask, | 
|  | 87 | int32_t keyCode) = 0; | 
|  | 88 | virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask, | 
|  | 89 | int32_t sw) = 0; | 
|  | 90 |  | 
| Vaibhav Devmurari | cbba14c | 2022-10-10 16:54:49 +0000 | [diff] [blame] | 91 | virtual void addKeyRemapping(int32_t deviceId, int32_t fromKeyCode, | 
|  | 92 | int32_t toKeyCode) const = 0; | 
|  | 93 |  | 
| Philip Junker | 4af3b3d | 2021-12-14 10:36:55 +0100 | [diff] [blame] | 94 | virtual int32_t getKeyCodeForKeyLocation(int32_t deviceId, int32_t locationKeyCode) const = 0; | 
|  | 95 |  | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 96 | /* Toggle Caps Lock */ | 
|  | 97 | virtual void toggleCapsLockState(int32_t deviceId) = 0; | 
|  | 98 |  | 
|  | 99 | /* Determine whether physical keys exist for the given framework-domain key codes. */ | 
|  | 100 | virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask, | 
| Siarhei Vishniakou | 7400794 | 2022-06-13 13:57:47 -0700 | [diff] [blame] | 101 | const std::vector<int32_t>& keyCodes, uint8_t* outFlags) = 0; | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 102 |  | 
|  | 103 | /* Requests that a reconfiguration of all input devices. | 
|  | 104 | * The changes flag is a bitfield that indicates what has changed and whether | 
|  | 105 | * the input devices must all be reopened. */ | 
|  | 106 | virtual void requestRefreshConfiguration(uint32_t changes) = 0; | 
|  | 107 |  | 
|  | 108 | /* Controls the vibrator of a particular input device. */ | 
| Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 109 | virtual void vibrate(int32_t deviceId, const VibrationSequence& sequence, ssize_t repeat, | 
|  | 110 | int32_t token) = 0; | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 111 | virtual void cancelVibrate(int32_t deviceId, int32_t token) = 0; | 
| Arthur Hung | c23540e | 2018-11-29 20:42:11 +0800 | [diff] [blame] | 112 |  | 
| Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 113 | virtual bool isVibrating(int32_t deviceId) = 0; | 
|  | 114 |  | 
|  | 115 | virtual std::vector<int32_t> getVibratorIds(int32_t deviceId) = 0; | 
| Kim Low | 03ea035 | 2020-11-06 12:45:07 -0800 | [diff] [blame] | 116 | /* Get battery level of a particular input device. */ | 
|  | 117 | virtual std::optional<int32_t> getBatteryCapacity(int32_t deviceId) = 0; | 
|  | 118 | /* Get battery status of a particular input device. */ | 
|  | 119 | virtual std::optional<int32_t> getBatteryStatus(int32_t deviceId) = 0; | 
| Prabir Pradhan | e287ecd | 2022-09-07 21:18:05 +0000 | [diff] [blame] | 120 | /* Get the device path for the battery of an input device. */ | 
|  | 121 | virtual std::optional<std::string> getBatteryDevicePath(int32_t deviceId) = 0; | 
| Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 122 |  | 
| Siarhei Vishniakou | 1983a71 | 2021-06-04 19:27:09 +0000 | [diff] [blame] | 123 | virtual std::vector<InputDeviceLightInfo> getLights(int32_t deviceId) = 0; | 
| Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 124 |  | 
| Siarhei Vishniakou | 1983a71 | 2021-06-04 19:27:09 +0000 | [diff] [blame] | 125 | virtual std::vector<InputDeviceSensorInfo> getSensors(int32_t deviceId) = 0; | 
| Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 126 |  | 
| Arthur Hung | c23540e | 2018-11-29 20:42:11 +0800 | [diff] [blame] | 127 | /* Return true if the device can send input events to the specified display. */ | 
|  | 128 | virtual bool canDispatchToDisplay(int32_t deviceId, int32_t displayId) = 0; | 
| Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 129 |  | 
|  | 130 | /* Enable sensor in input reader mapper. */ | 
|  | 131 | virtual bool enableSensor(int32_t deviceId, InputDeviceSensorType sensorType, | 
|  | 132 | std::chrono::microseconds samplingPeriod, | 
|  | 133 | std::chrono::microseconds maxBatchReportLatency) = 0; | 
|  | 134 |  | 
|  | 135 | /* Disable sensor in input reader mapper. */ | 
|  | 136 | virtual void disableSensor(int32_t deviceId, InputDeviceSensorType sensorType) = 0; | 
|  | 137 |  | 
|  | 138 | /* Flush sensor data in input reader mapper. */ | 
|  | 139 | virtual void flushSensor(int32_t deviceId, InputDeviceSensorType sensorType) = 0; | 
| Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 140 |  | 
|  | 141 | /* Set color for the light */ | 
|  | 142 | virtual bool setLightColor(int32_t deviceId, int32_t lightId, int32_t color) = 0; | 
|  | 143 | /* Set player ID for the light */ | 
|  | 144 | virtual bool setLightPlayerId(int32_t deviceId, int32_t lightId, int32_t playerId) = 0; | 
|  | 145 | /* Get light color */ | 
|  | 146 | virtual std::optional<int32_t> getLightColor(int32_t deviceId, int32_t lightId) = 0; | 
|  | 147 | /* Get light player ID */ | 
|  | 148 | virtual std::optional<int32_t> getLightPlayerId(int32_t deviceId, int32_t lightId) = 0; | 
| Prabir Pradhan | b54ffb2 | 2022-10-27 18:03:34 +0000 | [diff] [blame] | 149 |  | 
|  | 150 | /* Get the Bluetooth address of an input device, if known. */ | 
|  | 151 | virtual std::optional<std::string> getBluetoothAddress(int32_t deviceId) const = 0; | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 152 | }; | 
|  | 153 |  | 
| Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 154 | // --- InputReaderConfiguration --- | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 155 |  | 
|  | 156 | /* | 
|  | 157 | * Input reader configuration. | 
|  | 158 | * | 
|  | 159 | * Specifies various options that modify the behavior of the input reader. | 
|  | 160 | */ | 
|  | 161 | struct InputReaderConfiguration { | 
|  | 162 | // Describes changes that have occurred. | 
|  | 163 | enum { | 
|  | 164 | // The pointer speed changed. | 
|  | 165 | CHANGE_POINTER_SPEED = 1 << 0, | 
|  | 166 |  | 
|  | 167 | // The pointer gesture control changed. | 
|  | 168 | CHANGE_POINTER_GESTURE_ENABLEMENT = 1 << 1, | 
|  | 169 |  | 
|  | 170 | // The display size or orientation changed. | 
|  | 171 | CHANGE_DISPLAY_INFO = 1 << 2, | 
|  | 172 |  | 
|  | 173 | // The visible touches option changed. | 
|  | 174 | CHANGE_SHOW_TOUCHES = 1 << 3, | 
|  | 175 |  | 
|  | 176 | // The keyboard layouts must be reloaded. | 
|  | 177 | CHANGE_KEYBOARD_LAYOUTS = 1 << 4, | 
|  | 178 |  | 
|  | 179 | // The device name alias supplied by the may have changed for some devices. | 
|  | 180 | CHANGE_DEVICE_ALIAS = 1 << 5, | 
|  | 181 |  | 
|  | 182 | // The location calibration matrix changed. | 
|  | 183 | CHANGE_TOUCH_AFFINE_TRANSFORMATION = 1 << 6, | 
|  | 184 |  | 
|  | 185 | // The presence of an external stylus has changed. | 
|  | 186 | CHANGE_EXTERNAL_STYLUS_PRESENCE = 1 << 7, | 
|  | 187 |  | 
|  | 188 | // The pointer capture mode has changed. | 
|  | 189 | CHANGE_POINTER_CAPTURE = 1 << 8, | 
|  | 190 |  | 
|  | 191 | // The set of disabled input devices (disabledDevices) has changed. | 
|  | 192 | CHANGE_ENABLED_STATE = 1 << 9, | 
|  | 193 |  | 
| Ambrus Weisz | 7bc23bf | 2022-10-04 13:13:07 +0000 | [diff] [blame] | 194 | // The device type has been updated. | 
|  | 195 | CHANGE_DEVICE_TYPE = 1 << 10, | 
|  | 196 |  | 
| Zixuan Qu | fecb606 | 2022-11-12 04:44:31 +0000 | [diff] [blame] | 197 | // The keyboard layout association has changed. | 
|  | 198 | CHANGE_KEYBOARD_LAYOUT_ASSOCIATION = 1 << 11, | 
|  | 199 |  | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 200 | // All devices must be reopened. | 
|  | 201 | CHANGE_MUST_REOPEN = 1 << 31, | 
|  | 202 | }; | 
|  | 203 |  | 
|  | 204 | // Gets the amount of time to disable virtual keys after the screen is touched | 
|  | 205 | // in order to filter out accidental virtual key presses due to swiping gestures | 
|  | 206 | // or taps near the edge of the display.  May be 0 to disable the feature. | 
|  | 207 | nsecs_t virtualKeyQuietTime; | 
|  | 208 |  | 
|  | 209 | // The excluded device names for the platform. | 
|  | 210 | // Devices with these names will be ignored. | 
|  | 211 | std::vector<std::string> excludedDeviceNames; | 
|  | 212 |  | 
| Siarhei Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 213 | // The associations between input ports and display ports. | 
|  | 214 | // Used to determine which DisplayViewport should be tied to which InputDevice. | 
|  | 215 | std::unordered_map<std::string, uint8_t> portAssociations; | 
|  | 216 |  | 
| Zixuan Qu | fecb606 | 2022-11-12 04:44:31 +0000 | [diff] [blame] | 217 | // The associations between input device physical port locations and display unique ids. | 
| Christine Franks | 1ba71cc | 2021-04-07 14:37:42 -0700 | [diff] [blame] | 218 | // Used to determine which DisplayViewport should be tied to which InputDevice. | 
|  | 219 | std::unordered_map<std::string, std::string> uniqueIdAssociations; | 
|  | 220 |  | 
| Ambrus Weisz | 7bc23bf | 2022-10-04 13:13:07 +0000 | [diff] [blame] | 221 | // The associations between input device ports device types. | 
|  | 222 | // This is used to determine which device type and source should be tied to which InputDevice. | 
|  | 223 | std::unordered_map<std::string, std::string> deviceTypeAssociations; | 
|  | 224 |  | 
| Zixuan Qu | fecb606 | 2022-11-12 04:44:31 +0000 | [diff] [blame] | 225 | // The map from the input device physical port location to the input device layout info. | 
|  | 226 | // Can be used to determine the layout of the keyboard device. | 
|  | 227 | std::unordered_map<std::string, KeyboardLayoutInfo> keyboardLayoutAssociations; | 
|  | 228 |  | 
| Garfield Tan | 888a6a4 | 2020-01-09 11:39:16 -0800 | [diff] [blame] | 229 | // The suggested display ID to show the cursor. | 
|  | 230 | int32_t defaultPointerDisplayId; | 
|  | 231 |  | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 232 | // Velocity control parameters for mouse pointer movements. | 
|  | 233 | VelocityControlParameters pointerVelocityControlParameters; | 
|  | 234 |  | 
|  | 235 | // Velocity control parameters for mouse wheel movements. | 
|  | 236 | VelocityControlParameters wheelVelocityControlParameters; | 
|  | 237 |  | 
|  | 238 | // True if pointer gestures are enabled. | 
|  | 239 | bool pointerGesturesEnabled; | 
|  | 240 |  | 
|  | 241 | // Quiet time between certain pointer gesture transitions. | 
|  | 242 | // Time to allow for all fingers or buttons to settle into a stable state before | 
|  | 243 | // starting a new gesture. | 
|  | 244 | nsecs_t pointerGestureQuietInterval; | 
|  | 245 |  | 
|  | 246 | // The minimum speed that a pointer must travel for us to consider switching the active | 
|  | 247 | // touch pointer to it during a drag.  This threshold is set to avoid switching due | 
|  | 248 | // to noise from a finger resting on the touch pad (perhaps just pressing it down). | 
|  | 249 | float pointerGestureDragMinSwitchSpeed; // in pixels per second | 
|  | 250 |  | 
|  | 251 | // Tap gesture delay time. | 
|  | 252 | // The time between down and up must be less than this to be considered a tap. | 
|  | 253 | nsecs_t pointerGestureTapInterval; | 
|  | 254 |  | 
|  | 255 | // Tap drag gesture delay time. | 
|  | 256 | // The time between the previous tap's up and the next down must be less than | 
|  | 257 | // this to be considered a drag.  Otherwise, the previous tap is finished and a | 
|  | 258 | // new tap begins. | 
|  | 259 | // | 
|  | 260 | // Note that the previous tap will be held down for this entire duration so this | 
|  | 261 | // interval must be shorter than the long press timeout. | 
|  | 262 | nsecs_t pointerGestureTapDragInterval; | 
|  | 263 |  | 
|  | 264 | // The distance in pixels that the pointer is allowed to move from initial down | 
|  | 265 | // to up and still be called a tap. | 
|  | 266 | float pointerGestureTapSlop; // in pixels | 
|  | 267 |  | 
|  | 268 | // Time after the first touch points go down to settle on an initial centroid. | 
|  | 269 | // This is intended to be enough time to handle cases where the user puts down two | 
|  | 270 | // fingers at almost but not quite exactly the same time. | 
|  | 271 | nsecs_t pointerGestureMultitouchSettleInterval; | 
|  | 272 |  | 
|  | 273 | // The transition from PRESS to SWIPE or FREEFORM gesture mode is made when | 
|  | 274 | // at least two pointers have moved at least this far from their starting place. | 
|  | 275 | float pointerGestureMultitouchMinDistance; // in pixels | 
|  | 276 |  | 
|  | 277 | // The transition from PRESS to SWIPE gesture mode can only occur when the | 
|  | 278 | // cosine of the angle between the two vectors is greater than or equal to than this value | 
|  | 279 | // which indicates that the vectors are oriented in the same direction. | 
|  | 280 | // When the vectors are oriented in the exactly same direction, the cosine is 1.0. | 
|  | 281 | // (In exactly opposite directions, the cosine is -1.0.) | 
|  | 282 | float pointerGestureSwipeTransitionAngleCosine; | 
|  | 283 |  | 
|  | 284 | // The transition from PRESS to SWIPE gesture mode can only occur when the | 
|  | 285 | // fingers are no more than this far apart relative to the diagonal size of | 
|  | 286 | // the touch pad.  For example, a ratio of 0.5 means that the fingers must be | 
|  | 287 | // no more than half the diagonal size of the touch pad apart. | 
|  | 288 | float pointerGestureSwipeMaxWidthRatio; | 
|  | 289 |  | 
|  | 290 | // The gesture movement speed factor relative to the size of the display. | 
|  | 291 | // Movement speed applies when the fingers are moving in the same direction. | 
|  | 292 | // Without acceleration, a full swipe of the touch pad diagonal in movement mode | 
|  | 293 | // will cover this portion of the display diagonal. | 
|  | 294 | float pointerGestureMovementSpeedRatio; | 
|  | 295 |  | 
|  | 296 | // The gesture zoom speed factor relative to the size of the display. | 
|  | 297 | // Zoom speed applies when the fingers are mostly moving relative to each other | 
|  | 298 | // to execute a scale gesture or similar. | 
|  | 299 | // Without acceleration, a full swipe of the touch pad diagonal in zoom mode | 
|  | 300 | // will cover this portion of the display diagonal. | 
|  | 301 | float pointerGestureZoomSpeedRatio; | 
|  | 302 |  | 
|  | 303 | // True to show the location of touches on the touch screen as spots. | 
|  | 304 | bool showTouches; | 
|  | 305 |  | 
| Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 306 | // The latest request to enable or disable Pointer Capture. | 
|  | 307 | PointerCaptureRequest pointerCaptureRequest; | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 308 |  | 
|  | 309 | // The set of currently disabled input devices. | 
| Siarhei Vishniakou | c6f6119 | 2019-07-23 18:12:31 +0000 | [diff] [blame] | 310 | std::set<int32_t> disabledDevices; | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 311 |  | 
| Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 312 | InputReaderConfiguration() | 
|  | 313 | : virtualKeyQuietTime(0), | 
| Christine Franks | 46d8a1e | 2022-01-05 16:11:48 -0800 | [diff] [blame] | 314 | pointerVelocityControlParameters(1.0f, 500.0f, 3000.0f, | 
|  | 315 | static_cast<float>( | 
|  | 316 | android::os::IInputConstants:: | 
|  | 317 | DEFAULT_POINTER_ACCELERATION)), | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 318 | wheelVelocityControlParameters(1.0f, 15.0f, 50.0f, 4.0f), | 
|  | 319 | pointerGesturesEnabled(true), | 
| Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 320 | pointerGestureQuietInterval(100 * 1000000LL),            // 100 ms | 
|  | 321 | pointerGestureDragMinSwitchSpeed(50),                    // 50 pixels per second | 
|  | 322 | pointerGestureTapInterval(150 * 1000000LL),              // 150 ms | 
|  | 323 | pointerGestureTapDragInterval(150 * 1000000LL),          // 150 ms | 
|  | 324 | pointerGestureTapSlop(10.0f),                            // 10 pixels | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 325 | pointerGestureMultitouchSettleInterval(100 * 1000000LL), // 100 ms | 
| Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 326 | pointerGestureMultitouchMinDistance(15),                 // 15 pixels | 
|  | 327 | pointerGestureSwipeTransitionAngleCosine(0.2588f),       // cosine of 75 degrees | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 328 | pointerGestureSwipeMaxWidthRatio(0.25f), | 
|  | 329 | pointerGestureMovementSpeedRatio(0.8f), | 
|  | 330 | pointerGestureZoomSpeedRatio(0.3f), | 
| Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 331 | showTouches(false), | 
|  | 332 | pointerCaptureRequest() {} | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 333 |  | 
| Siarhei Vishniakou | c5ae0dc | 2019-07-10 15:51:18 -0700 | [diff] [blame] | 334 | static std::string changesToString(uint32_t changes); | 
|  | 335 |  | 
| Siarhei Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 336 | std::optional<DisplayViewport> getDisplayViewportByType(ViewportType type) const; | 
|  | 337 | std::optional<DisplayViewport> getDisplayViewportByUniqueId(const std::string& uniqueDisplayId) | 
|  | 338 | const; | 
|  | 339 | std::optional<DisplayViewport> getDisplayViewportByPort(uint8_t physicalPort) const; | 
| Garfield Tan | 888a6a4 | 2020-01-09 11:39:16 -0800 | [diff] [blame] | 340 | std::optional<DisplayViewport> getDisplayViewportById(int32_t displayId) const; | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 341 | void setDisplayViewports(const std::vector<DisplayViewport>& viewports); | 
|  | 342 |  | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 343 | void dump(std::string& dump) const; | 
|  | 344 | void dumpViewport(std::string& dump, const DisplayViewport& viewport) const; | 
|  | 345 |  | 
|  | 346 | private: | 
|  | 347 | std::vector<DisplayViewport> mDisplays; | 
|  | 348 | }; | 
|  | 349 |  | 
| Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 350 | // --- TouchAffineTransformation --- | 
|  | 351 |  | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 352 | struct TouchAffineTransformation { | 
|  | 353 | float x_scale; | 
|  | 354 | float x_ymix; | 
|  | 355 | float x_offset; | 
|  | 356 | float y_xmix; | 
|  | 357 | float y_scale; | 
|  | 358 | float y_offset; | 
|  | 359 |  | 
|  | 360 | TouchAffineTransformation() : | 
|  | 361 | x_scale(1.0f), x_ymix(0.0f), x_offset(0.0f), | 
|  | 362 | y_xmix(0.0f), y_scale(1.0f), y_offset(0.0f) { | 
|  | 363 | } | 
|  | 364 |  | 
|  | 365 | TouchAffineTransformation(float xscale, float xymix, float xoffset, | 
|  | 366 | float yxmix, float yscale, float yoffset) : | 
|  | 367 | x_scale(xscale), x_ymix(xymix), x_offset(xoffset), | 
|  | 368 | y_xmix(yxmix), y_scale(yscale), y_offset(yoffset) { | 
|  | 369 | } | 
|  | 370 |  | 
|  | 371 | void applyTo(float& x, float& y) const; | 
|  | 372 | }; | 
|  | 373 |  | 
| Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 374 | // --- InputReaderPolicyInterface --- | 
|  | 375 |  | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 376 | /* | 
|  | 377 | * Input reader policy interface. | 
|  | 378 | * | 
|  | 379 | * The input reader policy is used by the input reader to interact with the Window Manager | 
|  | 380 | * and other system components. | 
|  | 381 | * | 
|  | 382 | * The actual implementation is partially supported by callbacks into the DVM | 
|  | 383 | * via JNI.  This interface is also mocked in the unit tests. | 
|  | 384 | * | 
| Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 385 | * These methods will NOT re-enter the input reader interface, so they may be called from | 
|  | 386 | * any method in the input reader interface. | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 387 | */ | 
|  | 388 | class InputReaderPolicyInterface : public virtual RefBase { | 
|  | 389 | protected: | 
|  | 390 | InputReaderPolicyInterface() { } | 
|  | 391 | virtual ~InputReaderPolicyInterface() { } | 
|  | 392 |  | 
|  | 393 | public: | 
|  | 394 | /* Gets the input reader configuration. */ | 
|  | 395 | virtual void getReaderConfiguration(InputReaderConfiguration* outConfig) = 0; | 
|  | 396 |  | 
|  | 397 | /* Gets a pointer controller associated with the specified cursor device (ie. a mouse). */ | 
| Michael Wright | 17db18e | 2020-06-26 20:51:44 +0100 | [diff] [blame] | 398 | virtual std::shared_ptr<PointerControllerInterface> obtainPointerController( | 
|  | 399 | int32_t deviceId) = 0; | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 400 |  | 
|  | 401 | /* Notifies the input reader policy that some input devices have changed | 
|  | 402 | * and provides information about all current input devices. | 
|  | 403 | */ | 
| Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 404 | virtual void notifyInputDevicesChanged(const std::vector<InputDeviceInfo>& inputDevices) = 0; | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 405 |  | 
|  | 406 | /* Gets the keyboard layout for a particular input device. */ | 
| Chris Ye | 3a1e446 | 2020-08-12 10:13:15 -0700 | [diff] [blame] | 407 | virtual std::shared_ptr<KeyCharacterMap> getKeyboardLayoutOverlay( | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 408 | const InputDeviceIdentifier& identifier) = 0; | 
|  | 409 |  | 
|  | 410 | /* Gets a user-supplied alias for a particular input device, or an empty string if none. */ | 
|  | 411 | virtual std::string getDeviceAlias(const InputDeviceIdentifier& identifier) = 0; | 
|  | 412 |  | 
|  | 413 | /* Gets the affine calibration associated with the specified device. */ | 
|  | 414 | virtual TouchAffineTransformation getTouchAffineTransformation( | 
| Michael Wright | a9cf419 | 2022-12-01 23:46:39 +0000 | [diff] [blame] | 415 | const std::string& inputDeviceDescriptor, ui::Rotation surfaceRotation) = 0; | 
| Prabir Pradhan | da20b17 | 2022-09-26 17:01:18 +0000 | [diff] [blame] | 416 | /* Notifies the input reader policy that a stylus gesture has started. */ | 
|  | 417 | virtual void notifyStylusGestureStarted(int32_t deviceId, nsecs_t eventTime) = 0; | 
| Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 418 | }; | 
|  | 419 |  | 
|  | 420 | } // namespace android |