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