blob: 32b3ddbdebb228d39f20d956242490098c3a1902 [file] [log] [blame]
Garfield Tane84e6f92019-08-29 17:28:41 -07001/*
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 Tan15601662020-09-22 15:32:38 -070021#include <android-base/result.h>
chaviw3277faf2021-05-19 16:45:23 -050022#include <android/gui/FocusRequest.h>
Hani Kazmi3ce9c3a2022-04-25 09:40:23 +000023
Siarhei Vishniakouae6229e2019-12-30 16:23:19 -080024#include <android/os/InputEventInjectionResult.h>
25#include <android/os/InputEventInjectionSync.h>
chaviw3277faf2021-05-19 16:45:23 -050026#include <gui/InputApplication.h>
27#include <gui/WindowInfo.h>
Chris Yef59a2f42020-10-16 12:55:26 -070028#include <input/InputDevice.h>
Chris Ye0783e992020-06-02 21:34:49 -070029#include <input/InputTransport.h>
Arthur Hung72d8dc32020-03-28 00:48:39 +000030#include <unordered_map>
Garfield Tane84e6f92019-08-29 17:28:41 -070031
32namespace android {
33
Garfield Tane84e6f92019-08-29 17:28:41 -070034/* Notifies the system about input events generated by the input reader.
35 * The dispatcher is expected to be mostly asynchronous. */
Siarhei Vishniakou18050092021-09-01 13:32:49 -070036class InputDispatcherInterface : public InputListenerInterface {
37public:
Garfield Tane84e6f92019-08-29 17:28:41 -070038 InputDispatcherInterface() {}
39 virtual ~InputDispatcherInterface() {}
Garfield Tane84e6f92019-08-29 17:28:41 -070040 /* Dumps the state of the input dispatcher.
41 *
42 * This method may be called on any thread (usually by the input manager). */
43 virtual void dump(std::string& dump) = 0;
44
45 /* Called by the heatbeat to ensures that the dispatcher has not deadlocked. */
46 virtual void monitor() = 0;
47
Siarhei Vishniakou2bfa9052019-11-21 18:10:54 -080048 /**
49 * Wait until dispatcher is idle. That means, there are no further events to be processed,
50 * and all of the policy callbacks have been completed.
51 * Return true if the dispatcher is idle.
52 * Return false if the timeout waiting for the dispatcher to become idle has expired.
53 */
54 virtual bool waitForIdle() = 0;
55
Prabir Pradhan3608aad2019-10-02 17:08:26 -070056 /* Make the dispatcher start processing events.
Garfield Tane84e6f92019-08-29 17:28:41 -070057 *
Prabir Pradhan3608aad2019-10-02 17:08:26 -070058 * The dispatcher will start consuming events from the InputListenerInterface
59 * in the order that they were received.
Garfield Tane84e6f92019-08-29 17:28:41 -070060 */
Prabir Pradhan3608aad2019-10-02 17:08:26 -070061 virtual status_t start() = 0;
62
63 /* Makes the dispatcher stop processing events. */
64 virtual status_t stop() = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -070065
66 /* Injects an input event and optionally waits for sync.
67 * The synchronization mode determines whether the method blocks while waiting for
68 * input injection to proceed.
69 * Returns one of the INPUT_EVENT_INJECTION_XXX constants.
70 *
Prabir Pradhan5735a322022-04-11 17:23:34 +000071 * If a targetUid is provided, InputDispatcher will only consider injecting the input event into
72 * windows owned by the provided uid. If the input event is targeted at a window that is not
73 * owned by the provided uid, input injection will fail. If no targetUid is provided, the input
74 * event will be dispatched as-is.
75 *
76 * This method may be called on any thread (usually by the input manager). The caller must
77 * perform all necessary permission checks prior to injecting events.
Garfield Tane84e6f92019-08-29 17:28:41 -070078 */
Siarhei Vishniakouae6229e2019-12-30 16:23:19 -080079 virtual android::os::InputEventInjectionResult injectInputEvent(
Prabir Pradhan5735a322022-04-11 17:23:34 +000080 const InputEvent* event, std::optional<int32_t> targetUid,
Siarhei Vishniakouae6229e2019-12-30 16:23:19 -080081 android::os::InputEventInjectionSync syncMode, std::chrono::milliseconds timeout,
82 uint32_t policyFlags) = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -070083
Siarhei Vishniakou54d3e182020-01-15 17:38:38 -080084 /*
85 * Check whether InputEvent actually happened by checking the signature of the event.
86 *
87 * Return nullptr if the event cannot be verified.
88 */
89 virtual std::unique_ptr<VerifiedInputEvent> verifyInputEvent(const InputEvent& event) = 0;
90
Arthur Hung72d8dc32020-03-28 00:48:39 +000091 /* Sets the list of input windows per display.
Garfield Tane84e6f92019-08-29 17:28:41 -070092 *
93 * This method may be called on any thread (usually by the input manager).
94 */
95 virtual void setInputWindows(
chaviw3277faf2021-05-19 16:45:23 -050096 const std::unordered_map<int32_t, std::vector<sp<gui::WindowInfoHandle>>>&
Arthur Hung72d8dc32020-03-28 00:48:39 +000097 handlesPerDisplay) = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -070098
99 /* Sets the focused application on the given display.
100 *
101 * This method may be called on any thread (usually by the input manager).
102 */
103 virtual void setFocusedApplication(
Chris Yea209fde2020-07-22 13:54:51 -0700104 int32_t displayId,
105 const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle) = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -0700106
107 /* Sets the focused display.
108 *
109 * This method may be called on any thread (usually by the input manager).
110 */
111 virtual void setFocusedDisplay(int32_t displayId) = 0;
112
113 /* Sets the input dispatching mode.
114 *
115 * This method may be called on any thread (usually by the input manager).
116 */
117 virtual void setInputDispatchMode(bool enabled, bool frozen) = 0;
118
119 /* Sets whether input event filtering is enabled.
120 * When enabled, incoming input events are sent to the policy's filterInputEvent
121 * method instead of being dispatched. The filter is expected to use
122 * injectInputEvent to inject the events it would like to have dispatched.
123 * It should include POLICY_FLAG_FILTERED in the policy flags during injection.
124 */
125 virtual void setInputFilterEnabled(bool enabled) = 0;
126
Siarhei Vishniakouf3bc1aa2019-11-25 13:48:53 -0800127 /**
128 * Set the touch mode state.
129 * Touch mode is a global state that apps may enter / exit based on specific
130 * user interactions with input devices.
131 * If true, the device is in touch mode.
Antonio Kantekea47acb2021-12-23 12:41:25 -0800132 *
133 * Returns true when changing touch mode state.
Siarhei Vishniakouf3bc1aa2019-11-25 13:48:53 -0800134 */
Antonio Kanteka042c022022-07-06 16:51:07 -0700135 virtual bool setInTouchMode(bool inTouchMode, int32_t pid, int32_t uid, bool hasPermission,
136 int32_t displayId) = 0;
Siarhei Vishniakouf3bc1aa2019-11-25 13:48:53 -0800137
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100138 /**
139 * Sets the maximum allowed obscuring opacity by UID to propagate touches.
140 * For certain window types (eg. SAWs), the decision of honoring
141 * FLAG_NOT_TOUCHABLE or not depends on the combined obscuring opacity of
142 * the windows above the touch-consuming window.
143 */
144 virtual void setMaximumObscuringOpacityForTouch(float opacity) = 0;
145
Garfield Tane84e6f92019-08-29 17:28:41 -0700146 /* Transfers touch focus from one window to another window.
147 *
148 * Returns true on success. False if the window did not actually have touch focus.
149 */
arthurhungb89ccb02020-12-30 16:19:01 +0800150 virtual bool transferTouchFocus(const sp<IBinder>& fromToken, const sp<IBinder>& toToken,
151 bool isDragDrop) = 0;
Siarhei Vishniakoud0c6bc82021-03-13 03:14:52 +0000152
153 /**
154 * Transfer touch focus to the provided channel, no matter where the current touch is.
155 *
156 * Return true on success, false if there was no on-going touch.
157 */
Siarhei Vishniakou7ae7afd2022-03-31 15:26:13 -0700158 virtual bool transferTouch(const sp<IBinder>& destChannelToken, int32_t displayId) = 0;
Siarhei Vishniakoud0c6bc82021-03-13 03:14:52 +0000159
Vishnu Naire798b472020-07-23 13:52:21 -0700160 /**
161 * Sets focus on the specified window.
162 */
chaviw3277faf2021-05-19 16:45:23 -0500163 virtual void setFocusedWindow(const gui::FocusRequest&) = 0;
Vishnu Naire798b472020-07-23 13:52:21 -0700164
Garfield Tan15601662020-09-22 15:32:38 -0700165 /**
166 * Creates an input channel that may be used as targets for input events.
Garfield Tane84e6f92019-08-29 17:28:41 -0700167 *
168 * This method may be called on any thread (usually by the input manager).
169 */
Garfield Tan15601662020-09-22 15:32:38 -0700170 virtual base::Result<std::unique_ptr<InputChannel>> createInputChannel(
171 const std::string& name) = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -0700172
Garfield Tan15601662020-09-22 15:32:38 -0700173 /**
Prabir Pradhandfabf8a2022-01-21 08:19:30 -0800174 * Creates an input channel to be used to monitor all input events on a display.
Garfield Tane84e6f92019-08-29 17:28:41 -0700175 *
176 * Each monitor must target a specific display and will only receive input events sent to that
Prabir Pradhandfabf8a2022-01-21 08:19:30 -0800177 * display.
Garfield Tane84e6f92019-08-29 17:28:41 -0700178 *
179 * This method may be called on any thread (usually by the input manager).
180 */
Siarhei Vishniakou58cfc602020-12-14 23:21:30 +0000181 virtual base::Result<std::unique_ptr<InputChannel>> createInputMonitor(int32_t displayId,
Siarhei Vishniakou58cfc602020-12-14 23:21:30 +0000182 const std::string& name,
183 int32_t pid) = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -0700184
Garfield Tan15601662020-09-22 15:32:38 -0700185 /* Removes input channels that will no longer receive input events.
Garfield Tane84e6f92019-08-29 17:28:41 -0700186 *
187 * This method may be called on any thread (usually by the input manager).
188 */
Garfield Tan15601662020-09-22 15:32:38 -0700189 virtual status_t removeInputChannel(const sp<IBinder>& connectionToken) = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -0700190
191 /* Allows an input monitor steal the current pointer stream away from normal input windows.
192 *
193 * This method may be called on any thread (usually by the input manager).
194 */
195 virtual status_t pilferPointers(const sp<IBinder>& token) = 0;
Prabir Pradhan99987712020-11-10 18:43:05 -0800196
197 /**
198 * Enables Pointer Capture on the specified window if the window has focus.
199 *
200 * InputDispatcher is the source of truth of Pointer Capture.
201 */
202 virtual void requestPointerCapture(const sp<IBinder>& windowToken, bool enabled) = 0;
Antonio Kantek7242d8b2021-08-05 16:07:20 -0700203
Christine Franksb768bb42021-11-29 12:11:31 -0800204 /**
205 * Sets the eligibility of a given display to enable pointer capture. If a display is marked
206 * ineligible, all attempts to request pointer capture for windows on that display will fail.
207 * TODO(b/214621487): Remove or move to a display flag.
208 */
209 virtual void setDisplayEligibilityForPointerCapture(int displayId, bool isEligible) = 0;
210
Chris Yef59a2f42020-10-16 12:55:26 -0700211 /* Flush input device motion sensor.
212 *
213 * Returns true on success.
214 */
215 virtual bool flushSensor(int deviceId, InputDeviceSensorType sensorType) = 0;
Vishnu Nair599f1412021-06-21 10:39:58 -0700216
217 /**
218 * Called when a display has been removed from the system.
219 */
220 virtual void displayRemoved(int32_t displayId) = 0;
Arthur Hungdfd528e2021-12-08 13:23:04 +0000221
222 /*
223 * Abort the current touch stream.
224 */
225 virtual void cancelCurrentTouch() = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -0700226};
227
228} // namespace android
229
230#endif // _UI_INPUT_INPUTDISPATCHER_INPUTDISPATCHERINTERFACE_H