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 | |
| 66 | /* Runs a single iteration of the dispatch loop. |
| 67 | * Nominally processes one queued event, a timeout, or a response from an input consumer. |
| 68 | * |
| 69 | * This method should only be called on the input dispatcher thread. |
| 70 | */ |
| 71 | virtual void dispatchOnce() = 0; |
| 72 | |
| 73 | /* Injects an input event and optionally waits for sync. |
| 74 | * The synchronization mode determines whether the method blocks while waiting for |
| 75 | * input injection to proceed. |
| 76 | * Returns one of the INPUT_EVENT_INJECTION_XXX constants. |
| 77 | * |
| 78 | * This method may be called on any thread (usually by the input manager). |
| 79 | */ |
| 80 | virtual int32_t injectInputEvent(const InputEvent* event, int32_t injectorPid, |
| 81 | int32_t injectorUid, int32_t syncMode, int32_t timeoutMillis, |
| 82 | uint32_t policyFlags) = 0; |
| 83 | |
| 84 | /* Sets the list of input windows. |
| 85 | * |
| 86 | * This method may be called on any thread (usually by the input manager). |
| 87 | */ |
| 88 | virtual void setInputWindows( |
| 89 | const std::vector<sp<InputWindowHandle> >& inputWindowHandles, int32_t displayId, |
| 90 | const sp<ISetInputWindowsListener>& setInputWindowsListener = nullptr) = 0; |
| 91 | |
| 92 | /* Sets the focused application on the given display. |
| 93 | * |
| 94 | * This method may be called on any thread (usually by the input manager). |
| 95 | */ |
| 96 | virtual void setFocusedApplication( |
| 97 | int32_t displayId, const sp<InputApplicationHandle>& inputApplicationHandle) = 0; |
| 98 | |
| 99 | /* Sets the focused display. |
| 100 | * |
| 101 | * This method may be called on any thread (usually by the input manager). |
| 102 | */ |
| 103 | virtual void setFocusedDisplay(int32_t displayId) = 0; |
| 104 | |
| 105 | /* Sets the input dispatching mode. |
| 106 | * |
| 107 | * This method may be called on any thread (usually by the input manager). |
| 108 | */ |
| 109 | virtual void setInputDispatchMode(bool enabled, bool frozen) = 0; |
| 110 | |
| 111 | /* Sets whether input event filtering is enabled. |
| 112 | * When enabled, incoming input events are sent to the policy's filterInputEvent |
| 113 | * method instead of being dispatched. The filter is expected to use |
| 114 | * injectInputEvent to inject the events it would like to have dispatched. |
| 115 | * It should include POLICY_FLAG_FILTERED in the policy flags during injection. |
| 116 | */ |
| 117 | virtual void setInputFilterEnabled(bool enabled) = 0; |
| 118 | |
| 119 | /* Transfers touch focus from one window to another window. |
| 120 | * |
| 121 | * Returns true on success. False if the window did not actually have touch focus. |
| 122 | */ |
| 123 | virtual bool transferTouchFocus(const sp<IBinder>& fromToken, const sp<IBinder>& toToken) = 0; |
| 124 | |
| 125 | /* Registers input channels that may be used as targets for input events. |
| 126 | * |
| 127 | * This method may be called on any thread (usually by the input manager). |
| 128 | */ |
Siarhei Vishniakou | 7c34b23 | 2019-10-11 19:08:48 -0700 | [diff] [blame^] | 129 | virtual status_t registerInputChannel(const sp<InputChannel>& inputChannel) = 0; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 130 | |
| 131 | /* Registers input channels to be used to monitor input events. |
| 132 | * |
| 133 | * Each monitor must target a specific display and will only receive input events sent to that |
| 134 | * display. If the monitor is a gesture monitor, it will only receive pointer events on the |
| 135 | * targeted display. |
| 136 | * |
| 137 | * This method may be called on any thread (usually by the input manager). |
| 138 | */ |
| 139 | virtual status_t registerInputMonitor(const sp<InputChannel>& inputChannel, int32_t displayId, |
| 140 | bool gestureMonitor) = 0; |
| 141 | |
| 142 | /* Unregister input channels that will no longer receive input events. |
| 143 | * |
| 144 | * This method may be called on any thread (usually by the input manager). |
| 145 | */ |
| 146 | virtual status_t unregisterInputChannel(const sp<InputChannel>& inputChannel) = 0; |
| 147 | |
| 148 | /* Allows an input monitor steal the current pointer stream away from normal input windows. |
| 149 | * |
| 150 | * This method may be called on any thread (usually by the input manager). |
| 151 | */ |
| 152 | virtual status_t pilferPointers(const sp<IBinder>& token) = 0; |
| 153 | }; |
| 154 | |
| 155 | } // namespace android |
| 156 | |
| 157 | #endif // _UI_INPUT_INPUTDISPATCHER_INPUTDISPATCHERINTERFACE_H |