| 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> | 
| Vishnu Nair | e798b47 | 2020-07-23 13:52:21 -0700 | [diff] [blame] | 21 | #include <android/FocusRequest.h> | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 22 | #include <android/os/ISetInputWindowsListener.h> | 
|  | 23 | #include <input/InputApplication.h> | 
|  | 24 | #include <input/InputTransport.h> | 
|  | 25 | #include <input/InputWindow.h> | 
| Arthur Hung | 72d8dc3 | 2020-03-28 00:48:39 +0000 | [diff] [blame] | 26 | #include <unordered_map> | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 27 |  | 
|  | 28 | namespace android { | 
|  | 29 |  | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 30 | /* | 
|  | 31 | * Constants used to report the outcome of input event injection. | 
|  | 32 | */ | 
|  | 33 | enum { | 
|  | 34 | /* (INTERNAL USE ONLY) Specifies that injection is pending and its outcome is unknown. */ | 
|  | 35 | INPUT_EVENT_INJECTION_PENDING = -1, | 
|  | 36 |  | 
|  | 37 | /* Injection succeeded. */ | 
|  | 38 | INPUT_EVENT_INJECTION_SUCCEEDED = 0, | 
|  | 39 |  | 
|  | 40 | /* Injection failed because the injector did not have permission to inject | 
|  | 41 | * into the application with input focus. */ | 
|  | 42 | INPUT_EVENT_INJECTION_PERMISSION_DENIED = 1, | 
|  | 43 |  | 
|  | 44 | /* Injection failed because there were no available input targets. */ | 
|  | 45 | INPUT_EVENT_INJECTION_FAILED = 2, | 
|  | 46 |  | 
|  | 47 | /* Injection failed due to a timeout. */ | 
|  | 48 | INPUT_EVENT_INJECTION_TIMED_OUT = 3 | 
|  | 49 | }; | 
|  | 50 |  | 
|  | 51 | /* Notifies the system about input events generated by the input reader. | 
|  | 52 | * The dispatcher is expected to be mostly asynchronous. */ | 
|  | 53 | class InputDispatcherInterface : public virtual RefBase, public InputListenerInterface { | 
|  | 54 | protected: | 
|  | 55 | InputDispatcherInterface() {} | 
|  | 56 | virtual ~InputDispatcherInterface() {} | 
|  | 57 |  | 
|  | 58 | public: | 
|  | 59 | /* Dumps the state of the input dispatcher. | 
|  | 60 | * | 
|  | 61 | * This method may be called on any thread (usually by the input manager). */ | 
|  | 62 | virtual void dump(std::string& dump) = 0; | 
|  | 63 |  | 
|  | 64 | /* Called by the heatbeat to ensures that the dispatcher has not deadlocked. */ | 
|  | 65 | virtual void monitor() = 0; | 
|  | 66 |  | 
| Siarhei Vishniakou | 2bfa905 | 2019-11-21 18:10:54 -0800 | [diff] [blame] | 67 | /** | 
|  | 68 | * Wait until dispatcher is idle. That means, there are no further events to be processed, | 
|  | 69 | * and all of the policy callbacks have been completed. | 
|  | 70 | * Return true if the dispatcher is idle. | 
|  | 71 | * Return false if the timeout waiting for the dispatcher to become idle has expired. | 
|  | 72 | */ | 
|  | 73 | virtual bool waitForIdle() = 0; | 
|  | 74 |  | 
| Prabir Pradhan | 3608aad | 2019-10-02 17:08:26 -0700 | [diff] [blame] | 75 | /* Make the dispatcher start processing events. | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 76 | * | 
| Prabir Pradhan | 3608aad | 2019-10-02 17:08:26 -0700 | [diff] [blame] | 77 | * The dispatcher will start consuming events from the InputListenerInterface | 
|  | 78 | * in the order that they were received. | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 79 | */ | 
| Prabir Pradhan | 3608aad | 2019-10-02 17:08:26 -0700 | [diff] [blame] | 80 | virtual status_t start() = 0; | 
|  | 81 |  | 
|  | 82 | /* Makes the dispatcher stop processing events. */ | 
|  | 83 | virtual status_t stop() = 0; | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 84 |  | 
|  | 85 | /* Injects an input event and optionally waits for sync. | 
|  | 86 | * The synchronization mode determines whether the method blocks while waiting for | 
|  | 87 | * input injection to proceed. | 
|  | 88 | * Returns one of the INPUT_EVENT_INJECTION_XXX constants. | 
|  | 89 | * | 
|  | 90 | * This method may be called on any thread (usually by the input manager). | 
|  | 91 | */ | 
|  | 92 | virtual int32_t injectInputEvent(const InputEvent* event, int32_t injectorPid, | 
| Siarhei Vishniakou | 097c3db | 2020-05-06 14:18:38 -0700 | [diff] [blame] | 93 | int32_t injectorUid, int32_t syncMode, | 
|  | 94 | std::chrono::milliseconds timeout, uint32_t policyFlags) = 0; | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 95 |  | 
| Siarhei Vishniakou | 54d3e18 | 2020-01-15 17:38:38 -0800 | [diff] [blame] | 96 | /* | 
|  | 97 | * Check whether InputEvent actually happened by checking the signature of the event. | 
|  | 98 | * | 
|  | 99 | * Return nullptr if the event cannot be verified. | 
|  | 100 | */ | 
|  | 101 | virtual std::unique_ptr<VerifiedInputEvent> verifyInputEvent(const InputEvent& event) = 0; | 
|  | 102 |  | 
| Arthur Hung | 72d8dc3 | 2020-03-28 00:48:39 +0000 | [diff] [blame] | 103 | /* Sets the list of input windows per display. | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 104 | * | 
|  | 105 | * This method may be called on any thread (usually by the input manager). | 
|  | 106 | */ | 
|  | 107 | virtual void setInputWindows( | 
| Arthur Hung | 72d8dc3 | 2020-03-28 00:48:39 +0000 | [diff] [blame] | 108 | const std::unordered_map<int32_t, std::vector<sp<InputWindowHandle>>>& | 
|  | 109 | handlesPerDisplay) = 0; | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 110 |  | 
|  | 111 | /* Sets the focused application on the given display. | 
|  | 112 | * | 
|  | 113 | * This method may be called on any thread (usually by the input manager). | 
|  | 114 | */ | 
|  | 115 | virtual void setFocusedApplication( | 
| Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 116 | int32_t displayId, | 
|  | 117 | const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle) = 0; | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 118 |  | 
|  | 119 | /* Sets the focused display. | 
|  | 120 | * | 
|  | 121 | * This method may be called on any thread (usually by the input manager). | 
|  | 122 | */ | 
|  | 123 | virtual void setFocusedDisplay(int32_t displayId) = 0; | 
|  | 124 |  | 
|  | 125 | /* Sets the input dispatching mode. | 
|  | 126 | * | 
|  | 127 | * This method may be called on any thread (usually by the input manager). | 
|  | 128 | */ | 
|  | 129 | virtual void setInputDispatchMode(bool enabled, bool frozen) = 0; | 
|  | 130 |  | 
|  | 131 | /* Sets whether input event filtering is enabled. | 
|  | 132 | * When enabled, incoming input events are sent to the policy's filterInputEvent | 
|  | 133 | * method instead of being dispatched.  The filter is expected to use | 
|  | 134 | * injectInputEvent to inject the events it would like to have dispatched. | 
|  | 135 | * It should include POLICY_FLAG_FILTERED in the policy flags during injection. | 
|  | 136 | */ | 
|  | 137 | virtual void setInputFilterEnabled(bool enabled) = 0; | 
|  | 138 |  | 
| Siarhei Vishniakou | f3bc1aa | 2019-11-25 13:48:53 -0800 | [diff] [blame] | 139 | /** | 
|  | 140 | * Set the touch mode state. | 
|  | 141 | * Touch mode is a global state that apps may enter / exit based on specific | 
|  | 142 | * user interactions with input devices. | 
|  | 143 | * If true, the device is in touch mode. | 
|  | 144 | */ | 
|  | 145 | virtual void setInTouchMode(bool inTouchMode) = 0; | 
|  | 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 | */ | 
|  | 151 | virtual bool transferTouchFocus(const sp<IBinder>& fromToken, const sp<IBinder>& toToken) = 0; | 
|  | 152 |  | 
| Vishnu Nair | e798b47 | 2020-07-23 13:52:21 -0700 | [diff] [blame] | 153 | /** | 
|  | 154 | * Sets focus on the specified window. | 
|  | 155 | */ | 
|  | 156 | virtual void setFocusedWindow(const FocusRequest&) = 0; | 
|  | 157 |  | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 158 | /* Registers input channels that may be used as targets for input events. | 
|  | 159 | * | 
|  | 160 | * This method may be called on any thread (usually by the input manager). | 
|  | 161 | */ | 
| Siarhei Vishniakou | ce5ab08 | 2020-07-09 17:03:21 -0500 | [diff] [blame] | 162 | virtual status_t registerInputChannel(const std::shared_ptr<InputChannel>& inputChannel) = 0; | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 163 |  | 
|  | 164 | /* Registers input channels to be used to monitor input events. | 
|  | 165 | * | 
|  | 166 | * Each monitor must target a specific display and will only receive input events sent to that | 
|  | 167 | * display. If the monitor is a gesture monitor, it will only receive pointer events on the | 
|  | 168 | * targeted display. | 
|  | 169 | * | 
|  | 170 | * This method may be called on any thread (usually by the input manager). | 
|  | 171 | */ | 
| Siarhei Vishniakou | ce5ab08 | 2020-07-09 17:03:21 -0500 | [diff] [blame] | 172 | virtual status_t registerInputMonitor(const std::shared_ptr<InputChannel>& inputChannel, | 
|  | 173 | int32_t displayId, bool gestureMonitor) = 0; | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 174 |  | 
|  | 175 | /* Unregister input channels that will no longer receive input events. | 
|  | 176 | * | 
|  | 177 | * This method may be called on any thread (usually by the input manager). | 
|  | 178 | */ | 
| Siarhei Vishniakou | adefc3e | 2020-09-02 22:28:29 -0500 | [diff] [blame] | 179 | virtual status_t unregisterInputChannel(const sp<IBinder>& connectionToken) = 0; | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 180 |  | 
|  | 181 | /* Allows an input monitor steal the current pointer stream away from normal input windows. | 
|  | 182 | * | 
|  | 183 | * This method may be called on any thread (usually by the input manager). | 
|  | 184 | */ | 
|  | 185 | virtual status_t pilferPointers(const sp<IBinder>& token) = 0; | 
|  | 186 | }; | 
|  | 187 |  | 
|  | 188 | } // namespace android | 
|  | 189 |  | 
|  | 190 | #endif // _UI_INPUT_INPUTDISPATCHER_INPUTDISPATCHERINTERFACE_H |