blob: 001dc6cf7bc4821268b6766908e30c8365d2b571 [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
Prabir Pradhan48108662022-09-09 21:22:04 +000017#pragma once
Garfield Tane84e6f92019-08-29 17:28:41 -070018
19#include <InputListener.h>
Garfield Tan15601662020-09-22 15:32:38 -070020#include <android-base/result.h>
chaviw3277faf2021-05-19 16:45:23 -050021#include <android/gui/FocusRequest.h>
Hani Kazmi3ce9c3a2022-04-25 09:40:23 +000022
Siarhei Vishniakouae6229e2019-12-30 16:23:19 -080023#include <android/os/InputEventInjectionResult.h>
24#include <android/os/InputEventInjectionSync.h>
chaviw3277faf2021-05-19 16:45:23 -050025#include <gui/InputApplication.h>
26#include <gui/WindowInfo.h>
Chris Yef59a2f42020-10-16 12:55:26 -070027#include <input/InputDevice.h>
Chris Ye0783e992020-06-02 21:34:49 -070028#include <input/InputTransport.h>
Arthur Hung72d8dc32020-03-28 00:48:39 +000029#include <unordered_map>
Garfield Tane84e6f92019-08-29 17:28:41 -070030
31namespace android {
32
Garfield Tane84e6f92019-08-29 17:28:41 -070033/* Notifies the system about input events generated by the input reader.
34 * The dispatcher is expected to be mostly asynchronous. */
Siarhei Vishniakou18050092021-09-01 13:32:49 -070035class InputDispatcherInterface : public InputListenerInterface {
36public:
Garfield Tane84e6f92019-08-29 17:28:41 -070037 InputDispatcherInterface() {}
38 virtual ~InputDispatcherInterface() {}
Garfield Tane84e6f92019-08-29 17:28:41 -070039 /* Dumps the state of the input dispatcher.
40 *
41 * This method may be called on any thread (usually by the input manager). */
Siarhei Vishniakou5e20f272023-06-08 17:24:44 -070042 virtual void dump(std::string& dump) const = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -070043
44 /* Called by the heatbeat to ensures that the dispatcher has not deadlocked. */
45 virtual void monitor() = 0;
46
Siarhei Vishniakou2bfa9052019-11-21 18:10:54 -080047 /**
48 * Wait until dispatcher is idle. That means, there are no further events to be processed,
49 * and all of the policy callbacks have been completed.
50 * Return true if the dispatcher is idle.
51 * Return false if the timeout waiting for the dispatcher to become idle has expired.
52 */
Siarhei Vishniakoua66d65e2023-06-16 10:32:51 -070053 virtual bool waitForIdle() const = 0;
Siarhei Vishniakou2bfa9052019-11-21 18:10:54 -080054
Prabir Pradhan3608aad2019-10-02 17:08:26 -070055 /* Make the dispatcher start processing events.
Garfield Tane84e6f92019-08-29 17:28:41 -070056 *
Prabir Pradhan3608aad2019-10-02 17:08:26 -070057 * The dispatcher will start consuming events from the InputListenerInterface
58 * in the order that they were received.
Garfield Tane84e6f92019-08-29 17:28:41 -070059 */
Prabir Pradhan3608aad2019-10-02 17:08:26 -070060 virtual status_t start() = 0;
61
62 /* Makes the dispatcher stop processing events. */
63 virtual status_t stop() = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -070064
65 /* Injects an input event and optionally waits for sync.
66 * The synchronization mode determines whether the method blocks while waiting for
67 * input injection to proceed.
68 * Returns one of the INPUT_EVENT_INJECTION_XXX constants.
69 *
Prabir Pradhan5735a322022-04-11 17:23:34 +000070 * If a targetUid is provided, InputDispatcher will only consider injecting the input event into
71 * windows owned by the provided uid. If the input event is targeted at a window that is not
72 * owned by the provided uid, input injection will fail. If no targetUid is provided, the input
73 * event will be dispatched as-is.
74 *
75 * This method may be called on any thread (usually by the input manager). The caller must
76 * perform all necessary permission checks prior to injecting events.
Garfield Tane84e6f92019-08-29 17:28:41 -070077 */
Siarhei Vishniakouae6229e2019-12-30 16:23:19 -080078 virtual android::os::InputEventInjectionResult injectInputEvent(
Prabir Pradhan8a5c41d2023-06-08 19:13:46 +000079 const InputEvent* event, std::optional<gui::Uid> targetUid,
Siarhei Vishniakouae6229e2019-12-30 16:23:19 -080080 android::os::InputEventInjectionSync syncMode, std::chrono::milliseconds timeout,
81 uint32_t policyFlags) = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -070082
Siarhei Vishniakou54d3e182020-01-15 17:38:38 -080083 /*
84 * Check whether InputEvent actually happened by checking the signature of the event.
85 *
86 * Return nullptr if the event cannot be verified.
87 */
88 virtual std::unique_ptr<VerifiedInputEvent> verifyInputEvent(const InputEvent& event) = 0;
89
Garfield Tane84e6f92019-08-29 17:28:41 -070090 /* Sets the focused application on the given display.
91 *
92 * This method may be called on any thread (usually by the input manager).
93 */
94 virtual void setFocusedApplication(
Chris Yea209fde2020-07-22 13:54:51 -070095 int32_t displayId,
96 const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle) = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -070097
98 /* Sets the focused display.
99 *
100 * This method may be called on any thread (usually by the input manager).
101 */
102 virtual void setFocusedDisplay(int32_t displayId) = 0;
103
104 /* Sets the input dispatching mode.
105 *
106 * This method may be called on any thread (usually by the input manager).
107 */
108 virtual void setInputDispatchMode(bool enabled, bool frozen) = 0;
109
110 /* Sets whether input event filtering is enabled.
111 * When enabled, incoming input events are sent to the policy's filterInputEvent
112 * method instead of being dispatched. The filter is expected to use
113 * injectInputEvent to inject the events it would like to have dispatched.
114 * It should include POLICY_FLAG_FILTERED in the policy flags during injection.
115 */
116 virtual void setInputFilterEnabled(bool enabled) = 0;
117
Siarhei Vishniakouf3bc1aa2019-11-25 13:48:53 -0800118 /**
119 * Set the touch mode state.
Sandro Meier08338902022-11-07 10:27:23 +0000120 * Touch mode is a per display state that apps may enter / exit based on specific user
121 * interactions with input devices. If <code>inTouchMode</code> is set to true, the display
122 * identified by <code>displayId</code> will be changed to touch mode. Performs a permission
123 * check if hasPermission is set to false.
124 *
125 * This method also enqueues a a TouchModeEntry message for dispatching.
Antonio Kantekea47acb2021-12-23 12:41:25 -0800126 *
127 * Returns true when changing touch mode state.
Siarhei Vishniakouf3bc1aa2019-11-25 13:48:53 -0800128 */
Prabir Pradhanaeebeb42023-06-13 19:53:03 +0000129 virtual bool setInTouchMode(bool inTouchMode, gui::Pid pid, gui::Uid uid, bool hasPermission,
Antonio Kanteka042c022022-07-06 16:51:07 -0700130 int32_t displayId) = 0;
Siarhei Vishniakouf3bc1aa2019-11-25 13:48:53 -0800131
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100132 /**
133 * Sets the maximum allowed obscuring opacity by UID to propagate touches.
134 * For certain window types (eg. SAWs), the decision of honoring
135 * FLAG_NOT_TOUCHABLE or not depends on the combined obscuring opacity of
136 * the windows above the touch-consuming window.
137 */
138 virtual void setMaximumObscuringOpacityForTouch(float opacity) = 0;
139
Garfield Tane84e6f92019-08-29 17:28:41 -0700140 /* Transfers touch focus from one window to another window.
141 *
142 * Returns true on success. False if the window did not actually have touch focus.
143 */
arthurhungb89ccb02020-12-30 16:19:01 +0800144 virtual bool transferTouchFocus(const sp<IBinder>& fromToken, const sp<IBinder>& toToken,
145 bool isDragDrop) = 0;
Siarhei Vishniakoud0c6bc82021-03-13 03:14:52 +0000146
147 /**
148 * Transfer touch focus to the provided channel, no matter where the current touch is.
149 *
150 * Return true on success, false if there was no on-going touch.
151 */
Siarhei Vishniakou7ae7afd2022-03-31 15:26:13 -0700152 virtual bool transferTouch(const sp<IBinder>& destChannelToken, int32_t displayId) = 0;
Siarhei Vishniakoud0c6bc82021-03-13 03:14:52 +0000153
Vishnu Naire798b472020-07-23 13:52:21 -0700154 /**
155 * Sets focus on the specified window.
156 */
chaviw3277faf2021-05-19 16:45:23 -0500157 virtual void setFocusedWindow(const gui::FocusRequest&) = 0;
Vishnu Naire798b472020-07-23 13:52:21 -0700158
Garfield Tan15601662020-09-22 15:32:38 -0700159 /**
160 * Creates an input channel that may be used as targets for input events.
Garfield Tane84e6f92019-08-29 17:28:41 -0700161 *
162 * This method may be called on any thread (usually by the input manager).
163 */
Garfield Tan15601662020-09-22 15:32:38 -0700164 virtual base::Result<std::unique_ptr<InputChannel>> createInputChannel(
165 const std::string& name) = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -0700166
Garfield Tan15601662020-09-22 15:32:38 -0700167 /**
Prabir Pradhandfabf8a2022-01-21 08:19:30 -0800168 * Creates an input channel to be used to monitor all input events on a display.
Garfield Tane84e6f92019-08-29 17:28:41 -0700169 *
170 * Each monitor must target a specific display and will only receive input events sent to that
Prabir Pradhandfabf8a2022-01-21 08:19:30 -0800171 * display.
Garfield Tane84e6f92019-08-29 17:28:41 -0700172 *
173 * This method may be called on any thread (usually by the input manager).
174 */
Siarhei Vishniakou58cfc602020-12-14 23:21:30 +0000175 virtual base::Result<std::unique_ptr<InputChannel>> createInputMonitor(int32_t displayId,
Siarhei Vishniakou58cfc602020-12-14 23:21:30 +0000176 const std::string& name,
Prabir Pradhanaeebeb42023-06-13 19:53:03 +0000177 gui::Pid pid) = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -0700178
Garfield Tan15601662020-09-22 15:32:38 -0700179 /* Removes input channels that will no longer receive input events.
Garfield Tane84e6f92019-08-29 17:28:41 -0700180 *
181 * This method may be called on any thread (usually by the input manager).
182 */
Garfield Tan15601662020-09-22 15:32:38 -0700183 virtual status_t removeInputChannel(const sp<IBinder>& connectionToken) = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -0700184
185 /* Allows an input monitor steal the current pointer stream away from normal input windows.
186 *
187 * This method may be called on any thread (usually by the input manager).
188 */
189 virtual status_t pilferPointers(const sp<IBinder>& token) = 0;
Prabir Pradhan99987712020-11-10 18:43:05 -0800190
191 /**
192 * Enables Pointer Capture on the specified window if the window has focus.
193 *
194 * InputDispatcher is the source of truth of Pointer Capture.
195 */
196 virtual void requestPointerCapture(const sp<IBinder>& windowToken, bool enabled) = 0;
Antonio Kantek7242d8b2021-08-05 16:07:20 -0700197
Christine Franksb768bb42021-11-29 12:11:31 -0800198 /**
199 * Sets the eligibility of a given display to enable pointer capture. If a display is marked
200 * ineligible, all attempts to request pointer capture for windows on that display will fail.
201 * TODO(b/214621487): Remove or move to a display flag.
202 */
203 virtual void setDisplayEligibilityForPointerCapture(int displayId, bool isEligible) = 0;
204
Chris Yef59a2f42020-10-16 12:55:26 -0700205 /* Flush input device motion sensor.
206 *
207 * Returns true on success.
208 */
209 virtual bool flushSensor(int deviceId, InputDeviceSensorType sensorType) = 0;
Vishnu Nair599f1412021-06-21 10:39:58 -0700210
211 /**
212 * Called when a display has been removed from the system.
213 */
214 virtual void displayRemoved(int32_t displayId) = 0;
Arthur Hungdfd528e2021-12-08 13:23:04 +0000215
216 /*
217 * Abort the current touch stream.
218 */
219 virtual void cancelCurrentTouch() = 0;
Prabir Pradhan87112a72023-04-20 19:13:39 +0000220
Nergi Rahardi730cf3c2023-04-13 12:41:17 +0900221 /*
222 * Updates key repeat configuration timeout and delay.
Prabir Pradhan87112a72023-04-20 19:13:39 +0000223 */
Siarhei Vishniakoufa2a0492023-11-14 13:13:18 -0800224 virtual void setKeyRepeatConfiguration(std::chrono::nanoseconds timeout,
225 std::chrono::nanoseconds delay) = 0;
Prabir Pradhan64f21d22023-11-28 21:19:42 +0000226
227 /*
228 * Determine if a pointer from a device is being dispatched to the given window.
229 */
230 virtual bool isPointerInWindow(const sp<IBinder>& token, int32_t displayId, DeviceId deviceId,
231 int32_t pointerId) = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -0700232};
233
234} // namespace android