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" |
Abdelrahman Awadalla | 8c4160d | 2024-08-05 16:26:10 +0000 | [diff] [blame] | 37 | #include "TouchpadHardwareState.h" |
Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 38 | #include "VibrationElement.h" |
Omar Abdelmonem | 5e70e96 | 2024-08-06 09:38:42 +0000 | [diff] [blame] | 39 | #include "include/gestures.h" |
Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 40 | |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 41 | // Maximum supported size of a vibration pattern. |
| 42 | // Must be at least 2. |
| 43 | #define MAX_VIBRATE_PATTERN_SIZE 100 |
| 44 | |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 45 | namespace android { |
| 46 | |
Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 47 | // --- InputReaderConfiguration --- |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 48 | |
| 49 | /* |
| 50 | * Input reader configuration. |
| 51 | * |
| 52 | * Specifies various options that modify the behavior of the input reader. |
| 53 | */ |
| 54 | struct InputReaderConfiguration { |
| 55 | // Describes changes that have occurred. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 56 | enum class Change : uint32_t { |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 57 | // The mouse pointer speed changed. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 58 | POINTER_SPEED = 1u << 0, |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 59 | |
| 60 | // The pointer gesture control changed. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 61 | POINTER_GESTURE_ENABLEMENT = 1u << 1, |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 62 | |
| 63 | // The display size or orientation changed. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 64 | DISPLAY_INFO = 1u << 2, |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 65 | |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 66 | // The keyboard layouts must be reloaded. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 67 | KEYBOARD_LAYOUTS = 1u << 4, |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 68 | |
| 69 | // The device name alias supplied by the may have changed for some devices. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 70 | DEVICE_ALIAS = 1u << 5, |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 71 | |
| 72 | // The location calibration matrix changed. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 73 | TOUCH_AFFINE_TRANSFORMATION = 1u << 6, |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 74 | |
| 75 | // The presence of an external stylus has changed. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 76 | EXTERNAL_STYLUS_PRESENCE = 1u << 7, |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 77 | |
| 78 | // The pointer capture mode has changed. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 79 | POINTER_CAPTURE = 1u << 8, |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 80 | |
| 81 | // The set of disabled input devices (disabledDevices) has changed. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 82 | ENABLED_STATE = 1u << 9, |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 83 | |
Ambrus Weisz | 7bc23bf | 2022-10-04 13:13:07 +0000 | [diff] [blame] | 84 | // The device type has been updated. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 85 | DEVICE_TYPE = 1u << 10, |
Ambrus Weisz | 7bc23bf | 2022-10-04 13:13:07 +0000 | [diff] [blame] | 86 | |
Zixuan Qu | fecb606 | 2022-11-12 04:44:31 +0000 | [diff] [blame] | 87 | // The keyboard layout association has changed. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 88 | KEYBOARD_LAYOUT_ASSOCIATION = 1u << 11, |
Zixuan Qu | fecb606 | 2022-11-12 04:44:31 +0000 | [diff] [blame] | 89 | |
Prabir Pradhan | 7aa7ff0 | 2022-12-21 21:05:38 +0000 | [diff] [blame] | 90 | // The stylus button reporting configurations has changed. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 91 | STYLUS_BUTTON_REPORTING = 1u << 12, |
Prabir Pradhan | 7aa7ff0 | 2022-12-21 21:05:38 +0000 | [diff] [blame] | 92 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 93 | // The touchpad settings changed. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 94 | TOUCHPAD_SETTINGS = 1u << 13, |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 95 | |
Linnan Li | e5657f2 | 2024-09-13 21:54:37 +0800 | [diff] [blame] | 96 | // The key remapping has changed. |
| 97 | KEY_REMAPPING = 1u << 14, |
| 98 | |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 99 | // All devices must be reopened. |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 100 | MUST_REOPEN = 1u << 31, |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | // Gets the amount of time to disable virtual keys after the screen is touched |
| 104 | // in order to filter out accidental virtual key presses due to swiping gestures |
| 105 | // or taps near the edge of the display. May be 0 to disable the feature. |
| 106 | nsecs_t virtualKeyQuietTime; |
| 107 | |
| 108 | // The excluded device names for the platform. |
| 109 | // Devices with these names will be ignored. |
| 110 | std::vector<std::string> excludedDeviceNames; |
| 111 | |
Siarhei Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 112 | // The associations between input ports and display ports. |
| 113 | // Used to determine which DisplayViewport should be tied to which InputDevice. |
Mayank Garg | 60b4562 | 2024-05-05 20:23:56 -0700 | [diff] [blame] | 114 | std::unordered_map<std::string, uint8_t> inputPortToDisplayPortAssociations; |
Siarhei Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 115 | |
Antonio Kantek | 0ac5e09 | 2024-04-22 17:10:27 +0000 | [diff] [blame] | 116 | // The associations between input device ports and display unique ids. |
Christine Franks | 1ba71cc | 2021-04-07 14:37:42 -0700 | [diff] [blame] | 117 | // Used to determine which DisplayViewport should be tied to which InputDevice. |
Mayank Garg | 60b4562 | 2024-05-05 20:23:56 -0700 | [diff] [blame] | 118 | std::unordered_map<std::string, std::string> inputPortToDisplayUniqueIdAssociations; |
Antonio Kantek | 0ac5e09 | 2024-04-22 17:10:27 +0000 | [diff] [blame] | 119 | |
| 120 | // The associations between input device descriptor and display unique ids. |
| 121 | // Used to determine which DisplayViewport should be tied to which InputDevice. |
Mayank Garg | 60b4562 | 2024-05-05 20:23:56 -0700 | [diff] [blame] | 122 | std::unordered_map<std::string, std::string> inputDeviceDescriptorToDisplayUniqueIdAssociations; |
Christine Franks | 1ba71cc | 2021-04-07 14:37:42 -0700 | [diff] [blame] | 123 | |
Ambrus Weisz | 7bc23bf | 2022-10-04 13:13:07 +0000 | [diff] [blame] | 124 | // The associations between input device ports device types. |
| 125 | // This is used to determine which device type and source should be tied to which InputDevice. |
| 126 | std::unordered_map<std::string, std::string> deviceTypeAssociations; |
| 127 | |
Zixuan Qu | fecb606 | 2022-11-12 04:44:31 +0000 | [diff] [blame] | 128 | // The map from the input device physical port location to the input device layout info. |
| 129 | // Can be used to determine the layout of the keyboard device. |
| 130 | std::unordered_map<std::string, KeyboardLayoutInfo> keyboardLayoutAssociations; |
| 131 | |
Garfield Tan | 888a6a4 | 2020-01-09 11:39:16 -0800 | [diff] [blame] | 132 | // The suggested display ID to show the cursor. |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 133 | ui::LogicalDisplayId defaultPointerDisplayId; |
Garfield Tan | 888a6a4 | 2020-01-09 11:39:16 -0800 | [diff] [blame] | 134 | |
Harry Cutts | e78184b | 2024-01-08 15:54:58 +0000 | [diff] [blame] | 135 | // The mouse pointer speed, as a number from -7 (slowest) to 7 (fastest). |
| 136 | // |
| 137 | // Currently only used when the enable_new_mouse_pointer_ballistics flag is enabled. |
| 138 | int32_t mousePointerSpeed; |
| 139 | |
Prabir Pradhan | 777245c | 2024-01-19 20:44:36 +0000 | [diff] [blame] | 140 | // Displays on which an acceleration curve shouldn't be applied for pointer movements from mice. |
Harry Cutts | e78184b | 2024-01-08 15:54:58 +0000 | [diff] [blame] | 141 | // |
| 142 | // Currently only used when the enable_new_mouse_pointer_ballistics flag is enabled. |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 143 | std::set<ui::LogicalDisplayId> displaysWithMousePointerAccelerationDisabled; |
Harry Cutts | e78184b | 2024-01-08 15:54:58 +0000 | [diff] [blame] | 144 | |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 145 | // Velocity control parameters for mouse pointer movements. |
Harry Cutts | e78184b | 2024-01-08 15:54:58 +0000 | [diff] [blame] | 146 | // |
| 147 | // If the enable_new_mouse_pointer_ballistics flag is enabled, these are ignored and the values |
| 148 | // of mousePointerSpeed and mousePointerAccelerationEnabled used instead. |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 149 | VelocityControlParameters pointerVelocityControlParameters; |
| 150 | |
| 151 | // Velocity control parameters for mouse wheel movements. |
| 152 | VelocityControlParameters wheelVelocityControlParameters; |
| 153 | |
| 154 | // True if pointer gestures are enabled. |
| 155 | bool pointerGesturesEnabled; |
| 156 | |
| 157 | // Quiet time between certain pointer gesture transitions. |
| 158 | // Time to allow for all fingers or buttons to settle into a stable state before |
| 159 | // starting a new gesture. |
| 160 | nsecs_t pointerGestureQuietInterval; |
| 161 | |
| 162 | // The minimum speed that a pointer must travel for us to consider switching the active |
| 163 | // touch pointer to it during a drag. This threshold is set to avoid switching due |
| 164 | // to noise from a finger resting on the touch pad (perhaps just pressing it down). |
| 165 | float pointerGestureDragMinSwitchSpeed; // in pixels per second |
| 166 | |
| 167 | // Tap gesture delay time. |
| 168 | // The time between down and up must be less than this to be considered a tap. |
| 169 | nsecs_t pointerGestureTapInterval; |
| 170 | |
| 171 | // Tap drag gesture delay time. |
| 172 | // The time between the previous tap's up and the next down must be less than |
| 173 | // this to be considered a drag. Otherwise, the previous tap is finished and a |
| 174 | // new tap begins. |
| 175 | // |
| 176 | // Note that the previous tap will be held down for this entire duration so this |
| 177 | // interval must be shorter than the long press timeout. |
| 178 | nsecs_t pointerGestureTapDragInterval; |
| 179 | |
| 180 | // The distance in pixels that the pointer is allowed to move from initial down |
| 181 | // to up and still be called a tap. |
| 182 | float pointerGestureTapSlop; // in pixels |
| 183 | |
| 184 | // Time after the first touch points go down to settle on an initial centroid. |
| 185 | // This is intended to be enough time to handle cases where the user puts down two |
| 186 | // fingers at almost but not quite exactly the same time. |
| 187 | nsecs_t pointerGestureMultitouchSettleInterval; |
| 188 | |
| 189 | // The transition from PRESS to SWIPE or FREEFORM gesture mode is made when |
| 190 | // at least two pointers have moved at least this far from their starting place. |
| 191 | float pointerGestureMultitouchMinDistance; // in pixels |
| 192 | |
| 193 | // The transition from PRESS to SWIPE gesture mode can only occur when the |
| 194 | // cosine of the angle between the two vectors is greater than or equal to than this value |
| 195 | // which indicates that the vectors are oriented in the same direction. |
| 196 | // When the vectors are oriented in the exactly same direction, the cosine is 1.0. |
| 197 | // (In exactly opposite directions, the cosine is -1.0.) |
| 198 | float pointerGestureSwipeTransitionAngleCosine; |
| 199 | |
| 200 | // The transition from PRESS to SWIPE gesture mode can only occur when the |
| 201 | // fingers are no more than this far apart relative to the diagonal size of |
| 202 | // the touch pad. For example, a ratio of 0.5 means that the fingers must be |
| 203 | // no more than half the diagonal size of the touch pad apart. |
| 204 | float pointerGestureSwipeMaxWidthRatio; |
| 205 | |
| 206 | // The gesture movement speed factor relative to the size of the display. |
| 207 | // Movement speed applies when the fingers are moving in the same direction. |
| 208 | // Without acceleration, a full swipe of the touch pad diagonal in movement mode |
| 209 | // will cover this portion of the display diagonal. |
| 210 | float pointerGestureMovementSpeedRatio; |
| 211 | |
| 212 | // The gesture zoom speed factor relative to the size of the display. |
| 213 | // Zoom speed applies when the fingers are mostly moving relative to each other |
| 214 | // to execute a scale gesture or similar. |
| 215 | // Without acceleration, a full swipe of the touch pad diagonal in zoom mode |
| 216 | // will cover this portion of the display diagonal. |
| 217 | float pointerGestureZoomSpeedRatio; |
| 218 | |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 219 | // The latest request to enable or disable Pointer Capture. |
| 220 | PointerCaptureRequest pointerCaptureRequest; |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 221 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 222 | // The touchpad pointer speed, as a number from -7 (slowest) to 7 (fastest). |
| 223 | int32_t touchpadPointerSpeed; |
| 224 | |
| 225 | // True to invert the touchpad scrolling direction, so that moving two fingers downwards on the |
| 226 | // touchpad scrolls the content upwards. |
| 227 | bool touchpadNaturalScrollingEnabled; |
| 228 | |
| 229 | // True to enable tap-to-click on touchpads. |
| 230 | bool touchpadTapToClickEnabled; |
| 231 | |
Harry Cutts | e0e799d | 2024-01-24 16:27:56 +0000 | [diff] [blame] | 232 | // True to enable tap dragging on touchpads. |
| 233 | bool touchpadTapDraggingEnabled; |
| 234 | |
Abdelrahman Awadalla | 61d0da3 | 2024-08-12 17:02:13 +0000 | [diff] [blame] | 235 | // True if hardware state update notifications should be sent to the policy. |
| 236 | bool shouldNotifyTouchpadHardwareState; |
| 237 | |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 238 | // True to enable a zone on the right-hand side of touchpads where clicks will be turned into |
| 239 | // context (a.k.a. "right") clicks. |
| 240 | bool touchpadRightClickZoneEnabled; |
| 241 | |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 242 | // The set of currently disabled input devices. |
Siarhei Vishniakou | c6f6119 | 2019-07-23 18:12:31 +0000 | [diff] [blame] | 243 | std::set<int32_t> disabledDevices; |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 244 | |
Prabir Pradhan | 7aa7ff0 | 2022-12-21 21:05:38 +0000 | [diff] [blame] | 245 | // True if stylus button reporting through motion events should be enabled, in which case |
| 246 | // stylus button state changes are reported through motion events. |
| 247 | bool stylusButtonMotionEventsEnabled; |
| 248 | |
Seunghwan Choi | 2de48e4 | 2023-01-17 20:45:15 +0900 | [diff] [blame] | 249 | // True if a pointer icon should be shown for direct stylus pointers. |
| 250 | bool stylusPointerIconEnabled; |
| 251 | |
Linnan Li | e5657f2 | 2024-09-13 21:54:37 +0800 | [diff] [blame] | 252 | // Keycodes to be remapped. |
| 253 | std::map<int32_t /* fromKeyCode */, int32_t /* toKeyCode */> keyRemapping; |
| 254 | |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 255 | InputReaderConfiguration() |
| 256 | : virtualKeyQuietTime(0), |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 257 | defaultPointerDisplayId(ui::LogicalDisplayId::DEFAULT), |
Harry Cutts | e78184b | 2024-01-08 15:54:58 +0000 | [diff] [blame] | 258 | mousePointerSpeed(0), |
Prabir Pradhan | 777245c | 2024-01-19 20:44:36 +0000 | [diff] [blame] | 259 | displaysWithMousePointerAccelerationDisabled(), |
Christine Franks | 46d8a1e | 2022-01-05 16:11:48 -0800 | [diff] [blame] | 260 | pointerVelocityControlParameters(1.0f, 500.0f, 3000.0f, |
| 261 | static_cast<float>( |
| 262 | android::os::IInputConstants:: |
| 263 | DEFAULT_POINTER_ACCELERATION)), |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 264 | wheelVelocityControlParameters(1.0f, 15.0f, 50.0f, 4.0f), |
| 265 | pointerGesturesEnabled(true), |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 266 | pointerGestureQuietInterval(100 * 1000000LL), // 100 ms |
| 267 | pointerGestureDragMinSwitchSpeed(50), // 50 pixels per second |
| 268 | pointerGestureTapInterval(150 * 1000000LL), // 150 ms |
| 269 | pointerGestureTapDragInterval(150 * 1000000LL), // 150 ms |
| 270 | pointerGestureTapSlop(10.0f), // 10 pixels |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 271 | pointerGestureMultitouchSettleInterval(100 * 1000000LL), // 100 ms |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 272 | pointerGestureMultitouchMinDistance(15), // 15 pixels |
| 273 | pointerGestureSwipeTransitionAngleCosine(0.2588f), // cosine of 75 degrees |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 274 | pointerGestureSwipeMaxWidthRatio(0.25f), |
| 275 | pointerGestureMovementSpeedRatio(0.8f), |
| 276 | pointerGestureZoomSpeedRatio(0.3f), |
Prabir Pradhan | 7aa7ff0 | 2022-12-21 21:05:38 +0000 | [diff] [blame] | 277 | pointerCaptureRequest(), |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 278 | touchpadPointerSpeed(0), |
| 279 | touchpadNaturalScrollingEnabled(true), |
| 280 | touchpadTapToClickEnabled(true), |
Harry Cutts | e0e799d | 2024-01-24 16:27:56 +0000 | [diff] [blame] | 281 | touchpadTapDraggingEnabled(false), |
Abdelrahman Awadalla | 61d0da3 | 2024-08-12 17:02:13 +0000 | [diff] [blame] | 282 | shouldNotifyTouchpadHardwareState(false), |
Harry Cutts | a546ba8 | 2023-01-13 17:21:00 +0000 | [diff] [blame] | 283 | touchpadRightClickZoneEnabled(false), |
Seunghwan Choi | 2de48e4 | 2023-01-17 20:45:15 +0900 | [diff] [blame] | 284 | stylusButtonMotionEventsEnabled(true), |
| 285 | stylusPointerIconEnabled(false) {} |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 286 | |
Siarhei Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 287 | std::optional<DisplayViewport> getDisplayViewportByType(ViewportType type) const; |
| 288 | std::optional<DisplayViewport> getDisplayViewportByUniqueId(const std::string& uniqueDisplayId) |
| 289 | const; |
| 290 | std::optional<DisplayViewport> getDisplayViewportByPort(uint8_t physicalPort) const; |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 291 | std::optional<DisplayViewport> getDisplayViewportById(ui::LogicalDisplayId displayId) const; |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 292 | void setDisplayViewports(const std::vector<DisplayViewport>& viewports); |
| 293 | |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 294 | void dump(std::string& dump) const; |
| 295 | void dumpViewport(std::string& dump, const DisplayViewport& viewport) const; |
| 296 | |
| 297 | private: |
| 298 | std::vector<DisplayViewport> mDisplays; |
| 299 | }; |
| 300 | |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 301 | using ConfigurationChanges = ftl::Flags<InputReaderConfiguration::Change>; |
| 302 | |
| 303 | // --- InputReaderInterface --- |
| 304 | |
| 305 | /* The interface for the InputReader shared library. |
| 306 | * |
| 307 | * Manages one or more threads that process raw input events and sends cooked event data to an |
| 308 | * input listener. |
| 309 | * |
| 310 | * The implementation must guarantee thread safety for this interface. However, since the input |
| 311 | * listener is NOT thread safe, all calls to the listener must happen from the same thread. |
| 312 | */ |
| 313 | class InputReaderInterface { |
| 314 | public: |
| 315 | InputReaderInterface() {} |
| 316 | virtual ~InputReaderInterface() {} |
| 317 | /* Dumps the state of the input reader. |
| 318 | * |
| 319 | * This method may be called on any thread (usually by the input manager). */ |
| 320 | virtual void dump(std::string& dump) = 0; |
| 321 | |
| 322 | /* Called by the heartbeat to ensures that the reader has not deadlocked. */ |
| 323 | virtual void monitor() = 0; |
| 324 | |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 325 | /* Makes the reader start processing events from the kernel. */ |
| 326 | virtual status_t start() = 0; |
| 327 | |
| 328 | /* Makes the reader stop processing any more events. */ |
| 329 | virtual status_t stop() = 0; |
| 330 | |
| 331 | /* Gets information about all input devices. |
| 332 | * |
| 333 | * This method may be called on any thread (usually by the input manager). |
| 334 | */ |
| 335 | virtual std::vector<InputDeviceInfo> getInputDevices() const = 0; |
| 336 | |
| 337 | /* Query current input state. */ |
| 338 | virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask, int32_t scanCode) = 0; |
| 339 | virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask, int32_t keyCode) = 0; |
| 340 | virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask, int32_t sw) = 0; |
| 341 | |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 342 | virtual int32_t getKeyCodeForKeyLocation(int32_t deviceId, int32_t locationKeyCode) const = 0; |
| 343 | |
| 344 | /* Toggle Caps Lock */ |
| 345 | virtual void toggleCapsLockState(int32_t deviceId) = 0; |
| 346 | |
| 347 | /* Determine whether physical keys exist for the given framework-domain key codes. */ |
| 348 | virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask, |
| 349 | const std::vector<int32_t>& keyCodes, uint8_t* outFlags) = 0; |
| 350 | |
| 351 | /* Requests that a reconfiguration of all input devices. |
| 352 | * The changes flag is a bitfield that indicates what has changed and whether |
| 353 | * the input devices must all be reopened. */ |
| 354 | virtual void requestRefreshConfiguration(ConfigurationChanges changes) = 0; |
| 355 | |
| 356 | /* Controls the vibrator of a particular input device. */ |
| 357 | virtual void vibrate(int32_t deviceId, const VibrationSequence& sequence, ssize_t repeat, |
| 358 | int32_t token) = 0; |
| 359 | virtual void cancelVibrate(int32_t deviceId, int32_t token) = 0; |
| 360 | |
| 361 | virtual bool isVibrating(int32_t deviceId) = 0; |
| 362 | |
| 363 | virtual std::vector<int32_t> getVibratorIds(int32_t deviceId) = 0; |
| 364 | /* Get battery level of a particular input device. */ |
| 365 | virtual std::optional<int32_t> getBatteryCapacity(int32_t deviceId) = 0; |
| 366 | /* Get battery status of a particular input device. */ |
| 367 | virtual std::optional<int32_t> getBatteryStatus(int32_t deviceId) = 0; |
| 368 | /* Get the device path for the battery of an input device. */ |
| 369 | virtual std::optional<std::string> getBatteryDevicePath(int32_t deviceId) = 0; |
| 370 | |
| 371 | virtual std::vector<InputDeviceLightInfo> getLights(int32_t deviceId) = 0; |
| 372 | |
| 373 | virtual std::vector<InputDeviceSensorInfo> getSensors(int32_t deviceId) = 0; |
| 374 | |
Omar Abdelmonem | 5e70e96 | 2024-08-06 09:38:42 +0000 | [diff] [blame] | 375 | virtual std::optional<HardwareProperties> getTouchpadHardwareProperties(int32_t deviceId) = 0; |
| 376 | |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 377 | /* Return true if the device can send input events to the specified display. */ |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 378 | virtual bool canDispatchToDisplay(int32_t deviceId, ui::LogicalDisplayId displayId) = 0; |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 379 | |
| 380 | /* Enable sensor in input reader mapper. */ |
| 381 | virtual bool enableSensor(int32_t deviceId, InputDeviceSensorType sensorType, |
| 382 | std::chrono::microseconds samplingPeriod, |
| 383 | std::chrono::microseconds maxBatchReportLatency) = 0; |
| 384 | |
| 385 | /* Disable sensor in input reader mapper. */ |
| 386 | virtual void disableSensor(int32_t deviceId, InputDeviceSensorType sensorType) = 0; |
| 387 | |
| 388 | /* Flush sensor data in input reader mapper. */ |
| 389 | virtual void flushSensor(int32_t deviceId, InputDeviceSensorType sensorType) = 0; |
| 390 | |
| 391 | /* Set color for the light */ |
| 392 | virtual bool setLightColor(int32_t deviceId, int32_t lightId, int32_t color) = 0; |
| 393 | /* Set player ID for the light */ |
| 394 | virtual bool setLightPlayerId(int32_t deviceId, int32_t lightId, int32_t playerId) = 0; |
| 395 | /* Get light color */ |
| 396 | virtual std::optional<int32_t> getLightColor(int32_t deviceId, int32_t lightId) = 0; |
| 397 | /* Get light player ID */ |
| 398 | virtual std::optional<int32_t> getLightPlayerId(int32_t deviceId, int32_t lightId) = 0; |
| 399 | |
| 400 | /* Get the Bluetooth address of an input device, if known. */ |
| 401 | virtual std::optional<std::string> getBluetoothAddress(int32_t deviceId) const = 0; |
| 402 | |
| 403 | /* Sysfs node change reported. Recreate device if required to incorporate the new sysfs nodes */ |
| 404 | virtual void sysfsNodeChanged(const std::string& sysfsNodePath) = 0; |
Prabir Pradhan | 018faea | 2024-05-08 21:52:54 +0000 | [diff] [blame] | 405 | |
| 406 | /* Get the ID of the InputDevice that was used most recently. |
| 407 | * |
| 408 | * Returns ReservedInputDeviceId::INVALID_INPUT_DEVICE_ID if no device has been used since boot. |
| 409 | */ |
| 410 | virtual DeviceId getLastUsedInputDeviceId() = 0; |
Arpit Singh | 849beb4 | 2024-06-06 07:14:17 +0000 | [diff] [blame] | 411 | |
| 412 | /* Notifies that mouse cursor faded due to typing. */ |
| 413 | virtual void notifyMouseCursorFadedOnTyping() = 0; |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 414 | }; |
| 415 | |
Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 416 | // --- TouchAffineTransformation --- |
| 417 | |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 418 | struct TouchAffineTransformation { |
| 419 | float x_scale; |
| 420 | float x_ymix; |
| 421 | float x_offset; |
| 422 | float y_xmix; |
| 423 | float y_scale; |
| 424 | float y_offset; |
| 425 | |
| 426 | TouchAffineTransformation() : |
| 427 | x_scale(1.0f), x_ymix(0.0f), x_offset(0.0f), |
| 428 | y_xmix(0.0f), y_scale(1.0f), y_offset(0.0f) { |
| 429 | } |
| 430 | |
| 431 | TouchAffineTransformation(float xscale, float xymix, float xoffset, |
| 432 | float yxmix, float yscale, float yoffset) : |
| 433 | x_scale(xscale), x_ymix(xymix), x_offset(xoffset), |
| 434 | y_xmix(yxmix), y_scale(yscale), y_offset(yoffset) { |
| 435 | } |
| 436 | |
| 437 | void applyTo(float& x, float& y) const; |
| 438 | }; |
| 439 | |
Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 440 | // --- InputReaderPolicyInterface --- |
| 441 | |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 442 | /* |
| 443 | * Input reader policy interface. |
| 444 | * |
| 445 | * The input reader policy is used by the input reader to interact with the Window Manager |
| 446 | * and other system components. |
| 447 | * |
| 448 | * The actual implementation is partially supported by callbacks into the DVM |
| 449 | * via JNI. This interface is also mocked in the unit tests. |
| 450 | * |
Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 451 | * These methods will NOT re-enter the input reader interface, so they may be called from |
| 452 | * any method in the input reader interface. |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 453 | */ |
| 454 | class InputReaderPolicyInterface : public virtual RefBase { |
| 455 | protected: |
| 456 | InputReaderPolicyInterface() { } |
| 457 | virtual ~InputReaderPolicyInterface() { } |
| 458 | |
| 459 | public: |
| 460 | /* Gets the input reader configuration. */ |
| 461 | virtual void getReaderConfiguration(InputReaderConfiguration* outConfig) = 0; |
| 462 | |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 463 | /* Notifies the input reader policy that some input devices have changed |
| 464 | * and provides information about all current input devices. |
| 465 | */ |
Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 466 | virtual void notifyInputDevicesChanged(const std::vector<InputDeviceInfo>& inputDevices) = 0; |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 467 | |
Abdelrahman Awadalla | 8c4160d | 2024-08-05 16:26:10 +0000 | [diff] [blame] | 468 | /* Sends the hardware state of a connected touchpad */ |
| 469 | virtual void notifyTouchpadHardwareState(const SelfContainedHardwareState& schs, |
| 470 | int32_t deviceId) = 0; |
| 471 | |
Omar Abdelmonem | 5ebf21f | 2024-09-12 11:44:15 +0000 | [diff] [blame] | 472 | /* Sends the Info of gestures that happen on the touchpad. */ |
| 473 | virtual void notifyTouchpadGestureInfo(GestureType type, int32_t deviceId) = 0; |
| 474 | |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 475 | /* Gets the keyboard layout for a particular input device. */ |
Chris Ye | 3a1e446 | 2020-08-12 10:13:15 -0700 | [diff] [blame] | 476 | virtual std::shared_ptr<KeyCharacterMap> getKeyboardLayoutOverlay( |
Vaibhav Devmurari | dec3080 | 2023-07-11 15:02:03 +0000 | [diff] [blame] | 477 | const InputDeviceIdentifier& identifier, |
| 478 | const std::optional<KeyboardLayoutInfo> keyboardLayoutInfo) = 0; |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 479 | |
| 480 | /* Gets a user-supplied alias for a particular input device, or an empty string if none. */ |
| 481 | virtual std::string getDeviceAlias(const InputDeviceIdentifier& identifier) = 0; |
| 482 | |
| 483 | /* Gets the affine calibration associated with the specified device. */ |
| 484 | virtual TouchAffineTransformation getTouchAffineTransformation( |
Michael Wright | a9cf419 | 2022-12-01 23:46:39 +0000 | [diff] [blame] | 485 | const std::string& inputDeviceDescriptor, ui::Rotation surfaceRotation) = 0; |
Prabir Pradhan | da20b17 | 2022-09-26 17:01:18 +0000 | [diff] [blame] | 486 | /* Notifies the input reader policy that a stylus gesture has started. */ |
| 487 | virtual void notifyStylusGestureStarted(int32_t deviceId, nsecs_t eventTime) = 0; |
Arpit Singh | b3b3f73 | 2023-07-04 14:30:05 +0000 | [diff] [blame] | 488 | |
| 489 | /* Returns true if any InputConnection is currently active. */ |
| 490 | virtual bool isInputMethodConnectionActive() = 0; |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 491 | |
Prabir Pradhan | 1976760 | 2023-11-03 16:53:31 +0000 | [diff] [blame] | 492 | /* Gets the viewport of a particular display that the pointer device is associated with. If |
| 493 | * the pointer device is not associated with any display, it should ADISPLAY_IS_NONE to get |
| 494 | * the viewport that should be used. The device should get a new viewport using this method |
| 495 | * every time there is a display configuration change. The logical bounds of the viewport should |
| 496 | * be used as the range of possible values for pointing devices, like mice and touchpads. |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame] | 497 | */ |
Prabir Pradhan | 1976760 | 2023-11-03 16:53:31 +0000 | [diff] [blame] | 498 | virtual std::optional<DisplayViewport> getPointerViewportForAssociatedDisplay( |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 499 | ui::LogicalDisplayId associatedDisplayId = ui::LogicalDisplayId::INVALID) = 0; |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 500 | }; |
| 501 | |
| 502 | } // namespace android |