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