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 | |
| 17 | #ifndef _UI_INPUT_INPUTDISPATCHER_INPUTDISPATCHERINTERFACE_H |
| 18 | #define _UI_INPUT_INPUTDISPATCHER_INPUTDISPATCHERINTERFACE_H |
| 19 | |
| 20 | #include <InputListener.h> |
Garfield Tan | 1560166 | 2020-09-22 15:32:38 -0700 | [diff] [blame] | 21 | #include <android-base/result.h> |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 22 | #include <android/gui/FocusRequest.h> |
Hani Kazmi | 3ce9c3a | 2022-04-25 09:40:23 +0000 | [diff] [blame^] | 23 | |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 24 | #include <android/os/InputEventInjectionResult.h> |
| 25 | #include <android/os/InputEventInjectionSync.h> |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 26 | #include <gui/InputApplication.h> |
| 27 | #include <gui/WindowInfo.h> |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 28 | #include <input/InputDevice.h> |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 29 | #include <input/InputTransport.h> |
Arthur Hung | 72d8dc3 | 2020-03-28 00:48:39 +0000 | [diff] [blame] | 30 | #include <unordered_map> |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 31 | |
| 32 | namespace android { |
| 33 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 34 | /* Notifies the system about input events generated by the input reader. |
| 35 | * The dispatcher is expected to be mostly asynchronous. */ |
Siarhei Vishniakou | 1805009 | 2021-09-01 13:32:49 -0700 | [diff] [blame] | 36 | class InputDispatcherInterface : public InputListenerInterface { |
| 37 | public: |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 38 | InputDispatcherInterface() {} |
| 39 | virtual ~InputDispatcherInterface() {} |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 40 | /* Dumps the state of the input dispatcher. |
| 41 | * |
| 42 | * This method may be called on any thread (usually by the input manager). */ |
| 43 | virtual void dump(std::string& dump) = 0; |
| 44 | |
| 45 | /* Called by the heatbeat to ensures that the dispatcher has not deadlocked. */ |
| 46 | virtual void monitor() = 0; |
| 47 | |
Siarhei Vishniakou | 2bfa905 | 2019-11-21 18:10:54 -0800 | [diff] [blame] | 48 | /** |
| 49 | * Wait until dispatcher is idle. That means, there are no further events to be processed, |
| 50 | * and all of the policy callbacks have been completed. |
| 51 | * Return true if the dispatcher is idle. |
| 52 | * Return false if the timeout waiting for the dispatcher to become idle has expired. |
| 53 | */ |
| 54 | virtual bool waitForIdle() = 0; |
| 55 | |
Prabir Pradhan | 3608aad | 2019-10-02 17:08:26 -0700 | [diff] [blame] | 56 | /* Make the dispatcher start processing events. |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 57 | * |
Prabir Pradhan | 3608aad | 2019-10-02 17:08:26 -0700 | [diff] [blame] | 58 | * The dispatcher will start consuming events from the InputListenerInterface |
| 59 | * in the order that they were received. |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 60 | */ |
Prabir Pradhan | 3608aad | 2019-10-02 17:08:26 -0700 | [diff] [blame] | 61 | virtual status_t start() = 0; |
| 62 | |
| 63 | /* Makes the dispatcher stop processing events. */ |
| 64 | virtual status_t stop() = 0; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 65 | |
| 66 | /* Injects an input event and optionally waits for sync. |
| 67 | * The synchronization mode determines whether the method blocks while waiting for |
| 68 | * input injection to proceed. |
| 69 | * Returns one of the INPUT_EVENT_INJECTION_XXX constants. |
| 70 | * |
Prabir Pradhan | 4df80f5 | 2022-04-05 18:33:16 +0000 | [diff] [blame] | 71 | * This method may be called on any thread (usually by the input manager). |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 72 | */ |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 73 | virtual android::os::InputEventInjectionResult injectInputEvent( |
Prabir Pradhan | 4df80f5 | 2022-04-05 18:33:16 +0000 | [diff] [blame] | 74 | const InputEvent* event, int32_t injectorPid, int32_t injectorUid, |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 75 | android::os::InputEventInjectionSync syncMode, std::chrono::milliseconds timeout, |
| 76 | uint32_t policyFlags) = 0; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 77 | |
Siarhei Vishniakou | 54d3e18 | 2020-01-15 17:38:38 -0800 | [diff] [blame] | 78 | /* |
| 79 | * Check whether InputEvent actually happened by checking the signature of the event. |
| 80 | * |
| 81 | * Return nullptr if the event cannot be verified. |
| 82 | */ |
| 83 | virtual std::unique_ptr<VerifiedInputEvent> verifyInputEvent(const InputEvent& event) = 0; |
| 84 | |
Arthur Hung | 72d8dc3 | 2020-03-28 00:48:39 +0000 | [diff] [blame] | 85 | /* Sets the list of input windows per display. |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 86 | * |
| 87 | * This method may be called on any thread (usually by the input manager). |
| 88 | */ |
| 89 | virtual void setInputWindows( |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 90 | const std::unordered_map<int32_t, std::vector<sp<gui::WindowInfoHandle>>>& |
Arthur Hung | 72d8dc3 | 2020-03-28 00:48:39 +0000 | [diff] [blame] | 91 | handlesPerDisplay) = 0; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 92 | |
| 93 | /* Sets the focused application on the given display. |
| 94 | * |
| 95 | * This method may be called on any thread (usually by the input manager). |
| 96 | */ |
| 97 | virtual void setFocusedApplication( |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 98 | int32_t displayId, |
| 99 | const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle) = 0; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 100 | |
| 101 | /* Sets the focused display. |
| 102 | * |
| 103 | * This method may be called on any thread (usually by the input manager). |
| 104 | */ |
| 105 | virtual void setFocusedDisplay(int32_t displayId) = 0; |
| 106 | |
| 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. |
| 123 | * Touch mode is a global state that apps may enter / exit based on specific |
| 124 | * user interactions with input devices. |
| 125 | * If true, the device is in touch mode. |
Antonio Kantek | ea47acb | 2021-12-23 12:41:25 -0800 | [diff] [blame] | 126 | * |
| 127 | * Returns true when changing touch mode state. |
Siarhei Vishniakou | f3bc1aa | 2019-11-25 13:48:53 -0800 | [diff] [blame] | 128 | */ |
Antonio Kantek | ea47acb | 2021-12-23 12:41:25 -0800 | [diff] [blame] | 129 | virtual bool setInTouchMode(bool inTouchMode, int32_t pid, int32_t uid, bool hasPermission) = 0; |
Siarhei Vishniakou | f3bc1aa | 2019-11-25 13:48:53 -0800 | [diff] [blame] | 130 | |
Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame] | 131 | /** |
| 132 | * Sets the maximum allowed obscuring opacity by UID to propagate touches. |
| 133 | * For certain window types (eg. SAWs), the decision of honoring |
| 134 | * FLAG_NOT_TOUCHABLE or not depends on the combined obscuring opacity of |
| 135 | * the windows above the touch-consuming window. |
| 136 | */ |
| 137 | virtual void setMaximumObscuringOpacityForTouch(float opacity) = 0; |
| 138 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 139 | /* Transfers touch focus from one window to another window. |
| 140 | * |
| 141 | * Returns true on success. False if the window did not actually have touch focus. |
| 142 | */ |
arthurhung | b89ccb0 | 2020-12-30 16:19:01 +0800 | [diff] [blame] | 143 | virtual bool transferTouchFocus(const sp<IBinder>& fromToken, const sp<IBinder>& toToken, |
| 144 | bool isDragDrop) = 0; |
Siarhei Vishniakou | d0c6bc8 | 2021-03-13 03:14:52 +0000 | [diff] [blame] | 145 | |
| 146 | /** |
| 147 | * Transfer touch focus to the provided channel, no matter where the current touch is. |
| 148 | * |
| 149 | * Return true on success, false if there was no on-going touch. |
| 150 | */ |
Siarhei Vishniakou | 7ae7afd | 2022-03-31 15:26:13 -0700 | [diff] [blame] | 151 | virtual bool transferTouch(const sp<IBinder>& destChannelToken, int32_t displayId) = 0; |
Siarhei Vishniakou | d0c6bc8 | 2021-03-13 03:14:52 +0000 | [diff] [blame] | 152 | |
Vishnu Nair | e798b47 | 2020-07-23 13:52:21 -0700 | [diff] [blame] | 153 | /** |
| 154 | * Sets focus on the specified window. |
| 155 | */ |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 156 | virtual void setFocusedWindow(const gui::FocusRequest&) = 0; |
Vishnu Nair | e798b47 | 2020-07-23 13:52:21 -0700 | [diff] [blame] | 157 | |
Garfield Tan | 1560166 | 2020-09-22 15:32:38 -0700 | [diff] [blame] | 158 | /** |
| 159 | * 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] | 160 | * |
| 161 | * This method may be called on any thread (usually by the input manager). |
| 162 | */ |
Garfield Tan | 1560166 | 2020-09-22 15:32:38 -0700 | [diff] [blame] | 163 | virtual base::Result<std::unique_ptr<InputChannel>> createInputChannel( |
| 164 | const std::string& name) = 0; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 165 | |
Garfield Tan | 1560166 | 2020-09-22 15:32:38 -0700 | [diff] [blame] | 166 | /** |
Prabir Pradhan | dfabf8a | 2022-01-21 08:19:30 -0800 | [diff] [blame] | 167 | * 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] | 168 | * |
| 169 | * 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] | 170 | * display. |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 171 | * |
| 172 | * This method may be called on any thread (usually by the input manager). |
| 173 | */ |
Siarhei Vishniakou | 58cfc60 | 2020-12-14 23:21:30 +0000 | [diff] [blame] | 174 | virtual base::Result<std::unique_ptr<InputChannel>> createInputMonitor(int32_t displayId, |
Siarhei Vishniakou | 58cfc60 | 2020-12-14 23:21:30 +0000 | [diff] [blame] | 175 | const std::string& name, |
| 176 | int32_t pid) = 0; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 177 | |
Garfield Tan | 1560166 | 2020-09-22 15:32:38 -0700 | [diff] [blame] | 178 | /* Removes input channels that will no longer receive input events. |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 179 | * |
| 180 | * This method may be called on any thread (usually by the input manager). |
| 181 | */ |
Garfield Tan | 1560166 | 2020-09-22 15:32:38 -0700 | [diff] [blame] | 182 | virtual status_t removeInputChannel(const sp<IBinder>& connectionToken) = 0; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 183 | |
| 184 | /* Allows an input monitor steal the current pointer stream away from normal input windows. |
| 185 | * |
| 186 | * This method may be called on any thread (usually by the input manager). |
| 187 | */ |
| 188 | virtual status_t pilferPointers(const sp<IBinder>& token) = 0; |
Prabir Pradhan | 9998771 | 2020-11-10 18:43:05 -0800 | [diff] [blame] | 189 | |
| 190 | /** |
| 191 | * Enables Pointer Capture on the specified window if the window has focus. |
| 192 | * |
| 193 | * InputDispatcher is the source of truth of Pointer Capture. |
| 194 | */ |
| 195 | virtual void requestPointerCapture(const sp<IBinder>& windowToken, bool enabled) = 0; |
Antonio Kantek | 7242d8b | 2021-08-05 16:07:20 -0700 | [diff] [blame] | 196 | |
Christine Franks | b768bb4 | 2021-11-29 12:11:31 -0800 | [diff] [blame] | 197 | /** |
| 198 | * Sets the eligibility of a given display to enable pointer capture. If a display is marked |
| 199 | * ineligible, all attempts to request pointer capture for windows on that display will fail. |
| 200 | * TODO(b/214621487): Remove or move to a display flag. |
| 201 | */ |
| 202 | virtual void setDisplayEligibilityForPointerCapture(int displayId, bool isEligible) = 0; |
| 203 | |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 204 | /* Flush input device motion sensor. |
| 205 | * |
| 206 | * Returns true on success. |
| 207 | */ |
| 208 | virtual bool flushSensor(int deviceId, InputDeviceSensorType sensorType) = 0; |
Vishnu Nair | 599f141 | 2021-06-21 10:39:58 -0700 | [diff] [blame] | 209 | |
| 210 | /** |
| 211 | * Called when a display has been removed from the system. |
| 212 | */ |
| 213 | virtual void displayRemoved(int32_t displayId) = 0; |
Arthur Hung | dfd528e | 2021-12-08 13:23:04 +0000 | [diff] [blame] | 214 | |
| 215 | /* |
| 216 | * Abort the current touch stream. |
| 217 | */ |
| 218 | virtual void cancelCurrentTouch() = 0; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 219 | }; |
| 220 | |
| 221 | } // namespace android |
| 222 | |
| 223 | #endif // _UI_INPUT_INPUTDISPATCHER_INPUTDISPATCHERINTERFACE_H |