| 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 |  | 
 | 95 |     /* Sets the list of input windows. | 
 | 96 |      * | 
 | 97 |      * This method may be called on any thread (usually by the input manager). | 
 | 98 |      */ | 
 | 99 |     virtual void setInputWindows( | 
 | 100 |             const std::vector<sp<InputWindowHandle> >& inputWindowHandles, int32_t displayId, | 
 | 101 |             const sp<ISetInputWindowsListener>& setInputWindowsListener = nullptr) = 0; | 
 | 102 |  | 
 | 103 |     /* Sets the focused application on the given display. | 
 | 104 |      * | 
 | 105 |      * This method may be called on any thread (usually by the input manager). | 
 | 106 |      */ | 
 | 107 |     virtual void setFocusedApplication( | 
 | 108 |             int32_t displayId, const sp<InputApplicationHandle>& inputApplicationHandle) = 0; | 
 | 109 |  | 
 | 110 |     /* Sets the focused display. | 
 | 111 |      * | 
 | 112 |      * This method may be called on any thread (usually by the input manager). | 
 | 113 |      */ | 
 | 114 |     virtual void setFocusedDisplay(int32_t displayId) = 0; | 
 | 115 |  | 
 | 116 |     /* Sets the input dispatching mode. | 
 | 117 |      * | 
 | 118 |      * This method may be called on any thread (usually by the input manager). | 
 | 119 |      */ | 
 | 120 |     virtual void setInputDispatchMode(bool enabled, bool frozen) = 0; | 
 | 121 |  | 
 | 122 |     /* Sets whether input event filtering is enabled. | 
 | 123 |      * When enabled, incoming input events are sent to the policy's filterInputEvent | 
 | 124 |      * method instead of being dispatched.  The filter is expected to use | 
 | 125 |      * injectInputEvent to inject the events it would like to have dispatched. | 
 | 126 |      * It should include POLICY_FLAG_FILTERED in the policy flags during injection. | 
 | 127 |      */ | 
 | 128 |     virtual void setInputFilterEnabled(bool enabled) = 0; | 
 | 129 |  | 
| Siarhei Vishniakou | f3bc1aa | 2019-11-25 13:48:53 -0800 | [diff] [blame] | 130 |     /** | 
 | 131 |      * Set the touch mode state. | 
 | 132 |      * Touch mode is a global state that apps may enter / exit based on specific | 
 | 133 |      * user interactions with input devices. | 
 | 134 |      * If true, the device is in touch mode. | 
 | 135 |      */ | 
 | 136 |     virtual void setInTouchMode(bool inTouchMode) = 0; | 
 | 137 |  | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 138 |     /* Transfers touch focus from one window to another window. | 
 | 139 |      * | 
 | 140 |      * Returns true on success.  False if the window did not actually have touch focus. | 
 | 141 |      */ | 
 | 142 |     virtual bool transferTouchFocus(const sp<IBinder>& fromToken, const sp<IBinder>& toToken) = 0; | 
 | 143 |  | 
 | 144 |     /* Registers input channels that may be used as targets for input events. | 
 | 145 |      * | 
 | 146 |      * This method may be called on any thread (usually by the input manager). | 
 | 147 |      */ | 
| Siarhei Vishniakou | 7c34b23 | 2019-10-11 19:08:48 -0700 | [diff] [blame] | 148 |     virtual status_t registerInputChannel(const sp<InputChannel>& inputChannel) = 0; | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 149 |  | 
 | 150 |     /* Registers input channels to be used to monitor input events. | 
 | 151 |      * | 
 | 152 |      * Each monitor must target a specific display and will only receive input events sent to that | 
 | 153 |      * display. If the monitor is a gesture monitor, it will only receive pointer events on the | 
 | 154 |      * targeted display. | 
 | 155 |      * | 
 | 156 |      * This method may be called on any thread (usually by the input manager). | 
 | 157 |      */ | 
 | 158 |     virtual status_t registerInputMonitor(const sp<InputChannel>& inputChannel, int32_t displayId, | 
 | 159 |                                           bool gestureMonitor) = 0; | 
 | 160 |  | 
 | 161 |     /* Unregister input channels that will no longer receive input events. | 
 | 162 |      * | 
 | 163 |      * This method may be called on any thread (usually by the input manager). | 
 | 164 |      */ | 
 | 165 |     virtual status_t unregisterInputChannel(const sp<InputChannel>& inputChannel) = 0; | 
 | 166 |  | 
 | 167 |     /* Allows an input monitor steal the current pointer stream away from normal input windows. | 
 | 168 |      * | 
 | 169 |      * This method may be called on any thread (usually by the input manager). | 
 | 170 |      */ | 
 | 171 |     virtual status_t pilferPointers(const sp<IBinder>& token) = 0; | 
 | 172 | }; | 
 | 173 |  | 
 | 174 | } // namespace android | 
 | 175 |  | 
 | 176 | #endif // _UI_INPUT_INPUTDISPATCHER_INPUTDISPATCHERINTERFACE_H |