blob: 7f85e5393b53a375f283caacaec826e12d2cd9b5 [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>
Vishnu Naire798b472020-07-23 13:52:21 -070022#include <android/FocusRequest.h>
Bernardo Rufinoea97d182020-08-19 14:43:14 +010023#include <android/os/BlockUntrustedTouchesMode.h>
Chris Ye0783e992020-06-02 21:34:49 -070024#include <android/os/ISetInputWindowsListener.h>
Siarhei Vishniakouae6229e2019-12-30 16:23:19 -080025#include <android/os/InputEventInjectionResult.h>
26#include <android/os/InputEventInjectionSync.h>
Chris Ye0783e992020-06-02 21:34:49 -070027#include <input/InputApplication.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>
30#include <input/InputWindow.h>
Arthur Hung72d8dc32020-03-28 00:48:39 +000031#include <unordered_map>
Garfield Tane84e6f92019-08-29 17:28:41 -070032
Bernardo Rufinoea97d182020-08-19 14:43:14 +010033
Garfield Tane84e6f92019-08-29 17:28:41 -070034namespace android {
35
Garfield Tane84e6f92019-08-29 17:28:41 -070036/* Notifies the system about input events generated by the input reader.
37 * The dispatcher is expected to be mostly asynchronous. */
38class InputDispatcherInterface : public virtual RefBase, public InputListenerInterface {
39protected:
40 InputDispatcherInterface() {}
41 virtual ~InputDispatcherInterface() {}
42
43public:
44 /* Dumps the state of the input dispatcher.
45 *
46 * This method may be called on any thread (usually by the input manager). */
47 virtual void dump(std::string& dump) = 0;
48
49 /* Called by the heatbeat to ensures that the dispatcher has not deadlocked. */
50 virtual void monitor() = 0;
51
Siarhei Vishniakou2bfa9052019-11-21 18:10:54 -080052 /**
53 * Wait until dispatcher is idle. That means, there are no further events to be processed,
54 * and all of the policy callbacks have been completed.
55 * Return true if the dispatcher is idle.
56 * Return false if the timeout waiting for the dispatcher to become idle has expired.
57 */
58 virtual bool waitForIdle() = 0;
59
Prabir Pradhan3608aad2019-10-02 17:08:26 -070060 /* Make the dispatcher start processing events.
Garfield Tane84e6f92019-08-29 17:28:41 -070061 *
Prabir Pradhan3608aad2019-10-02 17:08:26 -070062 * The dispatcher will start consuming events from the InputListenerInterface
63 * in the order that they were received.
Garfield Tane84e6f92019-08-29 17:28:41 -070064 */
Prabir Pradhan3608aad2019-10-02 17:08:26 -070065 virtual status_t start() = 0;
66
67 /* Makes the dispatcher stop processing events. */
68 virtual status_t stop() = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -070069
70 /* Injects an input event and optionally waits for sync.
71 * The synchronization mode determines whether the method blocks while waiting for
72 * input injection to proceed.
73 * Returns one of the INPUT_EVENT_INJECTION_XXX constants.
74 *
75 * This method may be called on any thread (usually by the input manager).
76 */
Siarhei Vishniakouae6229e2019-12-30 16:23:19 -080077 virtual android::os::InputEventInjectionResult injectInputEvent(
78 const InputEvent* event, int32_t injectorPid, int32_t injectorUid,
79 android::os::InputEventInjectionSync syncMode, std::chrono::milliseconds timeout,
80 uint32_t policyFlags) = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -070081
Siarhei Vishniakou54d3e182020-01-15 17:38:38 -080082 /*
83 * Check whether InputEvent actually happened by checking the signature of the event.
84 *
85 * Return nullptr if the event cannot be verified.
86 */
87 virtual std::unique_ptr<VerifiedInputEvent> verifyInputEvent(const InputEvent& event) = 0;
88
Arthur Hung72d8dc32020-03-28 00:48:39 +000089 /* Sets the list of input windows per display.
Garfield Tane84e6f92019-08-29 17:28:41 -070090 *
91 * This method may be called on any thread (usually by the input manager).
92 */
93 virtual void setInputWindows(
Arthur Hung72d8dc32020-03-28 00:48:39 +000094 const std::unordered_map<int32_t, std::vector<sp<InputWindowHandle>>>&
95 handlesPerDisplay) = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -070096
97 /* Sets the focused application on the given display.
98 *
99 * This method may be called on any thread (usually by the input manager).
100 */
101 virtual void setFocusedApplication(
Chris Yea209fde2020-07-22 13:54:51 -0700102 int32_t displayId,
103 const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle) = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -0700104
105 /* Sets the focused display.
106 *
107 * This method may be called on any thread (usually by the input manager).
108 */
109 virtual void setFocusedDisplay(int32_t displayId) = 0;
110
111 /* Sets the input dispatching mode.
112 *
113 * This method may be called on any thread (usually by the input manager).
114 */
115 virtual void setInputDispatchMode(bool enabled, bool frozen) = 0;
116
117 /* Sets whether input event filtering is enabled.
118 * When enabled, incoming input events are sent to the policy's filterInputEvent
119 * method instead of being dispatched. The filter is expected to use
120 * injectInputEvent to inject the events it would like to have dispatched.
121 * It should include POLICY_FLAG_FILTERED in the policy flags during injection.
122 */
123 virtual void setInputFilterEnabled(bool enabled) = 0;
124
Siarhei Vishniakouf3bc1aa2019-11-25 13:48:53 -0800125 /**
126 * Set the touch mode state.
127 * Touch mode is a global state that apps may enter / exit based on specific
128 * user interactions with input devices.
129 * If true, the device is in touch mode.
130 */
131 virtual void setInTouchMode(bool inTouchMode) = 0;
132
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100133 /**
134 * Sets the maximum allowed obscuring opacity by UID to propagate touches.
135 * For certain window types (eg. SAWs), the decision of honoring
136 * FLAG_NOT_TOUCHABLE or not depends on the combined obscuring opacity of
137 * the windows above the touch-consuming window.
138 */
139 virtual void setMaximumObscuringOpacityForTouch(float opacity) = 0;
140
141 /**
142 * Sets the mode of the block untrusted touches feature.
143 *
144 * TODO(b/169067926): Clean-up feature modes.
145 */
Siarhei Vishniakouae6229e2019-12-30 16:23:19 -0800146 virtual void setBlockUntrustedTouchesMode(android::os::BlockUntrustedTouchesMode mode) = 0;
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100147
Garfield Tane84e6f92019-08-29 17:28:41 -0700148 /* Transfers touch focus from one window to another window.
149 *
150 * Returns true on success. False if the window did not actually have touch focus.
151 */
arthurhungb89ccb02020-12-30 16:19:01 +0800152 virtual bool transferTouchFocus(const sp<IBinder>& fromToken, const sp<IBinder>& toToken,
153 bool isDragDrop) = 0;
Siarhei Vishniakoud0c6bc82021-03-13 03:14:52 +0000154
155 /**
156 * Transfer touch focus to the provided channel, no matter where the current touch is.
157 *
158 * Return true on success, false if there was no on-going touch.
159 */
160 virtual bool transferTouch(const sp<IBinder>& destChannelToken) = 0;
161
Vishnu Naire798b472020-07-23 13:52:21 -0700162 /**
163 * Sets focus on the specified window.
164 */
165 virtual void setFocusedWindow(const FocusRequest&) = 0;
166
Garfield Tan15601662020-09-22 15:32:38 -0700167 /**
168 * Creates an input channel that may be used as targets for input events.
Garfield Tane84e6f92019-08-29 17:28:41 -0700169 *
170 * This method may be called on any thread (usually by the input manager).
171 */
Garfield Tan15601662020-09-22 15:32:38 -0700172 virtual base::Result<std::unique_ptr<InputChannel>> createInputChannel(
173 const std::string& name) = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -0700174
Garfield Tan15601662020-09-22 15:32:38 -0700175 /**
176 * Creates an input channel to be used to monitor input events.
Garfield Tane84e6f92019-08-29 17:28:41 -0700177 *
178 * Each monitor must target a specific display and will only receive input events sent to that
179 * display. If the monitor is a gesture monitor, it will only receive pointer events on the
180 * targeted display.
181 *
182 * This method may be called on any thread (usually by the input manager).
183 */
Siarhei Vishniakou58cfc602020-12-14 23:21:30 +0000184 virtual base::Result<std::unique_ptr<InputChannel>> createInputMonitor(int32_t displayId,
185 bool gestureMonitor,
186 const std::string& name,
187 int32_t pid) = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -0700188
Garfield Tan15601662020-09-22 15:32:38 -0700189 /* Removes input channels that will no longer receive input events.
Garfield Tane84e6f92019-08-29 17:28:41 -0700190 *
191 * This method may be called on any thread (usually by the input manager).
192 */
Garfield Tan15601662020-09-22 15:32:38 -0700193 virtual status_t removeInputChannel(const sp<IBinder>& connectionToken) = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -0700194
195 /* Allows an input monitor steal the current pointer stream away from normal input windows.
196 *
197 * This method may be called on any thread (usually by the input manager).
198 */
199 virtual status_t pilferPointers(const sp<IBinder>& token) = 0;
Prabir Pradhan99987712020-11-10 18:43:05 -0800200
201 /**
202 * Enables Pointer Capture on the specified window if the window has focus.
203 *
204 * InputDispatcher is the source of truth of Pointer Capture.
205 */
206 virtual void requestPointerCapture(const sp<IBinder>& windowToken, bool enabled) = 0;
Chris Yef59a2f42020-10-16 12:55:26 -0700207 /* Flush input device motion sensor.
208 *
209 * Returns true on success.
210 */
211 virtual bool flushSensor(int deviceId, InputDeviceSensorType sensorType) = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -0700212};
213
214} // namespace android
215
216#endif // _UI_INPUT_INPUTDISPATCHER_INPUTDISPATCHERINTERFACE_H