blob: 67d9a0610818ab80db6eb7088c046d2070fc03fc [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>
Chris Ye0783e992020-06-02 21:34:49 -070023#include <android/os/ISetInputWindowsListener.h>
24#include <input/InputApplication.h>
25#include <input/InputTransport.h>
26#include <input/InputWindow.h>
Arthur Hung72d8dc32020-03-28 00:48:39 +000027#include <unordered_map>
Garfield Tane84e6f92019-08-29 17:28:41 -070028
29namespace android {
30
Garfield Tane84e6f92019-08-29 17:28:41 -070031/*
32 * Constants used to report the outcome of input event injection.
33 */
34enum {
35 /* (INTERNAL USE ONLY) Specifies that injection is pending and its outcome is unknown. */
36 INPUT_EVENT_INJECTION_PENDING = -1,
37
38 /* Injection succeeded. */
39 INPUT_EVENT_INJECTION_SUCCEEDED = 0,
40
41 /* Injection failed because the injector did not have permission to inject
42 * into the application with input focus. */
43 INPUT_EVENT_INJECTION_PERMISSION_DENIED = 1,
44
45 /* Injection failed because there were no available input targets. */
46 INPUT_EVENT_INJECTION_FAILED = 2,
47
48 /* Injection failed due to a timeout. */
49 INPUT_EVENT_INJECTION_TIMED_OUT = 3
50};
51
52/* Notifies the system about input events generated by the input reader.
53 * The dispatcher is expected to be mostly asynchronous. */
54class InputDispatcherInterface : public virtual RefBase, public InputListenerInterface {
55protected:
56 InputDispatcherInterface() {}
57 virtual ~InputDispatcherInterface() {}
58
59public:
60 /* Dumps the state of the input dispatcher.
61 *
62 * This method may be called on any thread (usually by the input manager). */
63 virtual void dump(std::string& dump) = 0;
64
65 /* Called by the heatbeat to ensures that the dispatcher has not deadlocked. */
66 virtual void monitor() = 0;
67
Siarhei Vishniakou2bfa9052019-11-21 18:10:54 -080068 /**
69 * Wait until dispatcher is idle. That means, there are no further events to be processed,
70 * and all of the policy callbacks have been completed.
71 * Return true if the dispatcher is idle.
72 * Return false if the timeout waiting for the dispatcher to become idle has expired.
73 */
74 virtual bool waitForIdle() = 0;
75
Prabir Pradhan3608aad2019-10-02 17:08:26 -070076 /* Make the dispatcher start processing events.
Garfield Tane84e6f92019-08-29 17:28:41 -070077 *
Prabir Pradhan3608aad2019-10-02 17:08:26 -070078 * The dispatcher will start consuming events from the InputListenerInterface
79 * in the order that they were received.
Garfield Tane84e6f92019-08-29 17:28:41 -070080 */
Prabir Pradhan3608aad2019-10-02 17:08:26 -070081 virtual status_t start() = 0;
82
83 /* Makes the dispatcher stop processing events. */
84 virtual status_t stop() = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -070085
86 /* Injects an input event and optionally waits for sync.
87 * The synchronization mode determines whether the method blocks while waiting for
88 * input injection to proceed.
89 * Returns one of the INPUT_EVENT_INJECTION_XXX constants.
90 *
91 * This method may be called on any thread (usually by the input manager).
92 */
93 virtual int32_t injectInputEvent(const InputEvent* event, int32_t injectorPid,
Siarhei Vishniakou097c3db2020-05-06 14:18:38 -070094 int32_t injectorUid, int32_t syncMode,
95 std::chrono::milliseconds timeout, uint32_t policyFlags) = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -070096
Siarhei Vishniakou54d3e182020-01-15 17:38:38 -080097 /*
98 * Check whether InputEvent actually happened by checking the signature of the event.
99 *
100 * Return nullptr if the event cannot be verified.
101 */
102 virtual std::unique_ptr<VerifiedInputEvent> verifyInputEvent(const InputEvent& event) = 0;
103
Arthur Hung72d8dc32020-03-28 00:48:39 +0000104 /* Sets the list of input windows per display.
Garfield Tane84e6f92019-08-29 17:28:41 -0700105 *
106 * This method may be called on any thread (usually by the input manager).
107 */
108 virtual void setInputWindows(
Arthur Hung72d8dc32020-03-28 00:48:39 +0000109 const std::unordered_map<int32_t, std::vector<sp<InputWindowHandle>>>&
110 handlesPerDisplay) = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -0700111
112 /* Sets the focused application on the given display.
113 *
114 * This method may be called on any thread (usually by the input manager).
115 */
116 virtual void setFocusedApplication(
Chris Yea209fde2020-07-22 13:54:51 -0700117 int32_t displayId,
118 const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle) = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -0700119
120 /* Sets the focused display.
121 *
122 * This method may be called on any thread (usually by the input manager).
123 */
124 virtual void setFocusedDisplay(int32_t displayId) = 0;
125
126 /* Sets the input dispatching mode.
127 *
128 * This method may be called on any thread (usually by the input manager).
129 */
130 virtual void setInputDispatchMode(bool enabled, bool frozen) = 0;
131
132 /* Sets whether input event filtering is enabled.
133 * When enabled, incoming input events are sent to the policy's filterInputEvent
134 * method instead of being dispatched. The filter is expected to use
135 * injectInputEvent to inject the events it would like to have dispatched.
136 * It should include POLICY_FLAG_FILTERED in the policy flags during injection.
137 */
138 virtual void setInputFilterEnabled(bool enabled) = 0;
139
Siarhei Vishniakouf3bc1aa2019-11-25 13:48:53 -0800140 /**
141 * Set the touch mode state.
142 * Touch mode is a global state that apps may enter / exit based on specific
143 * user interactions with input devices.
144 * If true, the device is in touch mode.
145 */
146 virtual void setInTouchMode(bool inTouchMode) = 0;
147
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 */
152 virtual bool transferTouchFocus(const sp<IBinder>& fromToken, const sp<IBinder>& toToken) = 0;
153
Vishnu Naire798b472020-07-23 13:52:21 -0700154 /**
155 * Sets focus on the specified window.
156 */
157 virtual void setFocusedWindow(const FocusRequest&) = 0;
158
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 /**
168 * Creates an input channel to be used to monitor input events.
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
171 * display. If the monitor is a gesture monitor, it will only receive pointer events on the
172 * targeted display.
173 *
174 * This method may be called on any thread (usually by the input manager).
175 */
Garfield Tan15601662020-09-22 15:32:38 -0700176 virtual base::Result<std::unique_ptr<InputChannel>> createInputMonitor(
177 int32_t displayId, bool gestureMonitor, const std::string& name) = 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;
190};
191
192} // namespace android
193
194#endif // _UI_INPUT_INPUTDISPATCHER_INPUTDISPATCHERINTERFACE_H