Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Prabir Pradhan | 4810866 | 2022-09-09 21:22:04 +0000 | [diff] [blame] | 17 | #pragma once |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 18 | |
| 19 | #include <InputListener.h> |
Garfield Tan | 1560166 | 2020-09-22 15:32:38 -0700 | [diff] [blame] | 20 | #include <android-base/result.h> |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 21 | #include <android/gui/FocusRequest.h> |
Hani Kazmi | 3ce9c3a | 2022-04-25 09:40:23 +0000 | [diff] [blame] | 22 | |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 23 | #include <android/os/InputEventInjectionResult.h> |
| 24 | #include <android/os/InputEventInjectionSync.h> |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 25 | #include <gui/InputApplication.h> |
| 26 | #include <gui/WindowInfo.h> |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 27 | #include <input/InputDevice.h> |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 28 | #include <input/InputTransport.h> |
Arthur Hung | 72d8dc3 | 2020-03-28 00:48:39 +0000 | [diff] [blame] | 29 | #include <unordered_map> |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 30 | |
| 31 | namespace android { |
| 32 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 33 | /* Notifies the system about input events generated by the input reader. |
| 34 | * The dispatcher is expected to be mostly asynchronous. */ |
Siarhei Vishniakou | 1805009 | 2021-09-01 13:32:49 -0700 | [diff] [blame] | 35 | class InputDispatcherInterface : public InputListenerInterface { |
| 36 | public: |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 37 | InputDispatcherInterface() {} |
| 38 | virtual ~InputDispatcherInterface() {} |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 39 | /* Dumps the state of the input dispatcher. |
| 40 | * |
| 41 | * This method may be called on any thread (usually by the input manager). */ |
Siarhei Vishniakou | 5e20f27 | 2023-06-08 17:24:44 -0700 | [diff] [blame] | 42 | virtual void dump(std::string& dump) const = 0; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 43 | |
| 44 | /* Called by the heatbeat to ensures that the dispatcher has not deadlocked. */ |
| 45 | virtual void monitor() = 0; |
| 46 | |
Siarhei Vishniakou | 2bfa905 | 2019-11-21 18:10:54 -0800 | [diff] [blame] | 47 | /** |
| 48 | * Wait until dispatcher is idle. That means, there are no further events to be processed, |
| 49 | * and all of the policy callbacks have been completed. |
| 50 | * Return true if the dispatcher is idle. |
| 51 | * Return false if the timeout waiting for the dispatcher to become idle has expired. |
| 52 | */ |
Siarhei Vishniakou | a66d65e | 2023-06-16 10:32:51 -0700 | [diff] [blame] | 53 | virtual bool waitForIdle() const = 0; |
Siarhei Vishniakou | 2bfa905 | 2019-11-21 18:10:54 -0800 | [diff] [blame] | 54 | |
Prabir Pradhan | 3608aad | 2019-10-02 17:08:26 -0700 | [diff] [blame] | 55 | /* Make the dispatcher start processing events. |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 56 | * |
Prabir Pradhan | 3608aad | 2019-10-02 17:08:26 -0700 | [diff] [blame] | 57 | * The dispatcher will start consuming events from the InputListenerInterface |
| 58 | * in the order that they were received. |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 59 | */ |
Prabir Pradhan | 3608aad | 2019-10-02 17:08:26 -0700 | [diff] [blame] | 60 | virtual status_t start() = 0; |
| 61 | |
| 62 | /* Makes the dispatcher stop processing events. */ |
| 63 | virtual status_t stop() = 0; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 64 | |
| 65 | /* Injects an input event and optionally waits for sync. |
| 66 | * The synchronization mode determines whether the method blocks while waiting for |
| 67 | * input injection to proceed. |
| 68 | * Returns one of the INPUT_EVENT_INJECTION_XXX constants. |
| 69 | * |
Prabir Pradhan | 5735a32 | 2022-04-11 17:23:34 +0000 | [diff] [blame] | 70 | * If a targetUid is provided, InputDispatcher will only consider injecting the input event into |
| 71 | * windows owned by the provided uid. If the input event is targeted at a window that is not |
| 72 | * owned by the provided uid, input injection will fail. If no targetUid is provided, the input |
| 73 | * event will be dispatched as-is. |
| 74 | * |
| 75 | * This method may be called on any thread (usually by the input manager). The caller must |
| 76 | * perform all necessary permission checks prior to injecting events. |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 77 | */ |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 78 | virtual android::os::InputEventInjectionResult injectInputEvent( |
Prabir Pradhan | 8a5c41d | 2023-06-08 19:13:46 +0000 | [diff] [blame] | 79 | const InputEvent* event, std::optional<gui::Uid> targetUid, |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 80 | android::os::InputEventInjectionSync syncMode, std::chrono::milliseconds timeout, |
| 81 | uint32_t policyFlags) = 0; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 82 | |
Siarhei Vishniakou | 54d3e18 | 2020-01-15 17:38:38 -0800 | [diff] [blame] | 83 | /* |
| 84 | * Check whether InputEvent actually happened by checking the signature of the event. |
| 85 | * |
| 86 | * Return nullptr if the event cannot be verified. |
| 87 | */ |
| 88 | virtual std::unique_ptr<VerifiedInputEvent> verifyInputEvent(const InputEvent& event) = 0; |
| 89 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 90 | /* Sets the focused application on the given display. |
| 91 | * |
| 92 | * This method may be called on any thread (usually by the input manager). |
| 93 | */ |
| 94 | virtual void setFocusedApplication( |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame^] | 95 | ui::LogicalDisplayId displayId, |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 96 | const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle) = 0; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 97 | |
| 98 | /* Sets the focused display. |
| 99 | * |
| 100 | * This method may be called on any thread (usually by the input manager). |
| 101 | */ |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame^] | 102 | virtual void setFocusedDisplay(ui::LogicalDisplayId displayId) = 0; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 103 | |
Yeabkal Wubshit | b8aadfa | 2024-01-17 17:03:42 -0800 | [diff] [blame] | 104 | /** Sets the minimum time between user activity pokes. */ |
| 105 | virtual void setMinTimeBetweenUserActivityPokes(std::chrono::milliseconds interval) = 0; |
| 106 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 107 | /* Sets the input dispatching mode. |
| 108 | * |
| 109 | * This method may be called on any thread (usually by the input manager). |
| 110 | */ |
| 111 | virtual void setInputDispatchMode(bool enabled, bool frozen) = 0; |
| 112 | |
| 113 | /* Sets whether input event filtering is enabled. |
| 114 | * When enabled, incoming input events are sent to the policy's filterInputEvent |
| 115 | * method instead of being dispatched. The filter is expected to use |
| 116 | * injectInputEvent to inject the events it would like to have dispatched. |
| 117 | * It should include POLICY_FLAG_FILTERED in the policy flags during injection. |
| 118 | */ |
| 119 | virtual void setInputFilterEnabled(bool enabled) = 0; |
| 120 | |
Siarhei Vishniakou | f3bc1aa | 2019-11-25 13:48:53 -0800 | [diff] [blame] | 121 | /** |
| 122 | * Set the touch mode state. |
Sandro Meier | 0833890 | 2022-11-07 10:27:23 +0000 | [diff] [blame] | 123 | * Touch mode is a per display state that apps may enter / exit based on specific user |
| 124 | * interactions with input devices. If <code>inTouchMode</code> is set to true, the display |
| 125 | * identified by <code>displayId</code> will be changed to touch mode. Performs a permission |
| 126 | * check if hasPermission is set to false. |
| 127 | * |
| 128 | * This method also enqueues a a TouchModeEntry message for dispatching. |
Antonio Kantek | ea47acb | 2021-12-23 12:41:25 -0800 | [diff] [blame] | 129 | * |
| 130 | * Returns true when changing touch mode state. |
Siarhei Vishniakou | f3bc1aa | 2019-11-25 13:48:53 -0800 | [diff] [blame] | 131 | */ |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 132 | virtual bool setInTouchMode(bool inTouchMode, gui::Pid pid, gui::Uid uid, bool hasPermission, |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame^] | 133 | ui::LogicalDisplayId displayId) = 0; |
Siarhei Vishniakou | f3bc1aa | 2019-11-25 13:48:53 -0800 | [diff] [blame] | 134 | |
Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame] | 135 | /** |
| 136 | * Sets the maximum allowed obscuring opacity by UID to propagate touches. |
| 137 | * For certain window types (eg. SAWs), the decision of honoring |
| 138 | * FLAG_NOT_TOUCHABLE or not depends on the combined obscuring opacity of |
| 139 | * the windows above the touch-consuming window. |
| 140 | */ |
| 141 | virtual void setMaximumObscuringOpacityForTouch(float opacity) = 0; |
| 142 | |
Prabir Pradhan | 65455c7 | 2024-02-13 21:46:41 +0000 | [diff] [blame] | 143 | /** |
Prabir Pradhan | 367f343 | 2024-02-13 23:05:58 +0000 | [diff] [blame] | 144 | * Transfers a touch gesture from one window to another window. Transferring touch will not |
Prabir Pradhan | 65455c7 | 2024-02-13 21:46:41 +0000 | [diff] [blame] | 145 | * have any effect on the focused window. |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 146 | * |
Prabir Pradhan | 367f343 | 2024-02-13 23:05:58 +0000 | [diff] [blame] | 147 | * Returns true on success. False if the window did not actually have an active touch gesture. |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 148 | */ |
Prabir Pradhan | 367f343 | 2024-02-13 23:05:58 +0000 | [diff] [blame] | 149 | virtual bool transferTouchGesture(const sp<IBinder>& fromToken, const sp<IBinder>& toToken, |
| 150 | bool isDragDrop) = 0; |
Siarhei Vishniakou | d0c6bc8 | 2021-03-13 03:14:52 +0000 | [diff] [blame] | 151 | |
| 152 | /** |
Prabir Pradhan | 367f343 | 2024-02-13 23:05:58 +0000 | [diff] [blame] | 153 | * Transfer a touch gesture to the provided channel, no matter where the current touch is. |
| 154 | * Transferring touch will not have any effect on the focused window. |
Siarhei Vishniakou | d0c6bc8 | 2021-03-13 03:14:52 +0000 | [diff] [blame] | 155 | * |
Prabir Pradhan | 367f343 | 2024-02-13 23:05:58 +0000 | [diff] [blame] | 156 | * Returns true on success, false if there was no on-going touch on the display. |
| 157 | * @deprecated |
Siarhei Vishniakou | d0c6bc8 | 2021-03-13 03:14:52 +0000 | [diff] [blame] | 158 | */ |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame^] | 159 | virtual bool transferTouchOnDisplay(const sp<IBinder>& destChannelToken, |
| 160 | ui::LogicalDisplayId displayId) = 0; |
Siarhei Vishniakou | d0c6bc8 | 2021-03-13 03:14:52 +0000 | [diff] [blame] | 161 | |
Vishnu Nair | e798b47 | 2020-07-23 13:52:21 -0700 | [diff] [blame] | 162 | /** |
| 163 | * Sets focus on the specified window. |
| 164 | */ |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 165 | virtual void setFocusedWindow(const gui::FocusRequest&) = 0; |
Vishnu Nair | e798b47 | 2020-07-23 13:52:21 -0700 | [diff] [blame] | 166 | |
Garfield Tan | 1560166 | 2020-09-22 15:32:38 -0700 | [diff] [blame] | 167 | /** |
| 168 | * Creates an input channel that may be used as targets for input events. |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 169 | * |
| 170 | * This method may be called on any thread (usually by the input manager). |
| 171 | */ |
Garfield Tan | 1560166 | 2020-09-22 15:32:38 -0700 | [diff] [blame] | 172 | virtual base::Result<std::unique_ptr<InputChannel>> createInputChannel( |
| 173 | const std::string& name) = 0; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 174 | |
Garfield Tan | 1560166 | 2020-09-22 15:32:38 -0700 | [diff] [blame] | 175 | /** |
Prabir Pradhan | dfabf8a | 2022-01-21 08:19:30 -0800 | [diff] [blame] | 176 | * Creates an input channel to be used to monitor all input events on a display. |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 177 | * |
| 178 | * Each monitor must target a specific display and will only receive input events sent to that |
Prabir Pradhan | dfabf8a | 2022-01-21 08:19:30 -0800 | [diff] [blame] | 179 | * display. |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 180 | * |
| 181 | * This method may be called on any thread (usually by the input manager). |
| 182 | */ |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame^] | 183 | virtual base::Result<std::unique_ptr<InputChannel>> createInputMonitor( |
| 184 | ui::LogicalDisplayId displayId, const std::string& name, gui::Pid pid) = 0; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 185 | |
Garfield Tan | 1560166 | 2020-09-22 15:32:38 -0700 | [diff] [blame] | 186 | /* Removes input channels that will no longer receive input events. |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 187 | * |
| 188 | * This method may be called on any thread (usually by the input manager). |
| 189 | */ |
Garfield Tan | 1560166 | 2020-09-22 15:32:38 -0700 | [diff] [blame] | 190 | virtual status_t removeInputChannel(const sp<IBinder>& connectionToken) = 0; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 191 | |
| 192 | /* Allows an input monitor steal the current pointer stream away from normal input windows. |
| 193 | * |
| 194 | * This method may be called on any thread (usually by the input manager). |
| 195 | */ |
| 196 | virtual status_t pilferPointers(const sp<IBinder>& token) = 0; |
Prabir Pradhan | 9998771 | 2020-11-10 18:43:05 -0800 | [diff] [blame] | 197 | |
| 198 | /** |
| 199 | * Enables Pointer Capture on the specified window if the window has focus. |
| 200 | * |
| 201 | * InputDispatcher is the source of truth of Pointer Capture. |
| 202 | */ |
| 203 | virtual void requestPointerCapture(const sp<IBinder>& windowToken, bool enabled) = 0; |
Antonio Kantek | 7242d8b | 2021-08-05 16:07:20 -0700 | [diff] [blame] | 204 | |
Christine Franks | b768bb4 | 2021-11-29 12:11:31 -0800 | [diff] [blame] | 205 | /** |
| 206 | * Sets the eligibility of a given display to enable pointer capture. If a display is marked |
| 207 | * ineligible, all attempts to request pointer capture for windows on that display will fail. |
| 208 | * TODO(b/214621487): Remove or move to a display flag. |
| 209 | */ |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame^] | 210 | virtual void setDisplayEligibilityForPointerCapture(ui::LogicalDisplayId displayId, |
| 211 | bool isEligible) = 0; |
Christine Franks | b768bb4 | 2021-11-29 12:11:31 -0800 | [diff] [blame] | 212 | |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 213 | /* Flush input device motion sensor. |
| 214 | * |
| 215 | * Returns true on success. |
| 216 | */ |
| 217 | virtual bool flushSensor(int deviceId, InputDeviceSensorType sensorType) = 0; |
Vishnu Nair | 599f141 | 2021-06-21 10:39:58 -0700 | [diff] [blame] | 218 | |
| 219 | /** |
| 220 | * Called when a display has been removed from the system. |
| 221 | */ |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame^] | 222 | virtual void displayRemoved(ui::LogicalDisplayId displayId) = 0; |
Arthur Hung | dfd528e | 2021-12-08 13:23:04 +0000 | [diff] [blame] | 223 | |
| 224 | /* |
| 225 | * Abort the current touch stream. |
| 226 | */ |
| 227 | virtual void cancelCurrentTouch() = 0; |
Prabir Pradhan | 87112a7 | 2023-04-20 19:13:39 +0000 | [diff] [blame] | 228 | |
Nergi Rahardi | 730cf3c | 2023-04-13 12:41:17 +0900 | [diff] [blame] | 229 | /* |
| 230 | * Updates key repeat configuration timeout and delay. |
Prabir Pradhan | 87112a7 | 2023-04-20 19:13:39 +0000 | [diff] [blame] | 231 | */ |
Siarhei Vishniakou | fa2a049 | 2023-11-14 13:13:18 -0800 | [diff] [blame] | 232 | virtual void setKeyRepeatConfiguration(std::chrono::nanoseconds timeout, |
| 233 | std::chrono::nanoseconds delay) = 0; |
Prabir Pradhan | 64f21d2 | 2023-11-28 21:19:42 +0000 | [diff] [blame] | 234 | |
| 235 | /* |
| 236 | * Determine if a pointer from a device is being dispatched to the given window. |
| 237 | */ |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame^] | 238 | virtual bool isPointerInWindow(const sp<IBinder>& token, ui::LogicalDisplayId displayId, |
| 239 | DeviceId deviceId, int32_t pointerId) = 0; |
Prabir Pradhan | 04a6642 | 2024-03-15 22:45:27 +0000 | [diff] [blame] | 240 | |
| 241 | /* |
| 242 | * Notify the dispatcher that the state of the input method connection changed. |
| 243 | */ |
| 244 | virtual void setInputMethodConnectionIsActive(bool isActive) = 0; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 245 | }; |
| 246 | |
| 247 | } // namespace android |