blob: db9fba6fccab41fa28586407e8ad10d29d28243d [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>
21#include <input/ISetInputWindowsListener.h>
22
23namespace android {
24
25class InputApplicationHandle;
26class InputChannel;
27class InputWindowHandle;
28
29/*
30 * Constants used to report the outcome of input event injection.
31 */
32enum {
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. */
52class InputDispatcherInterface : public virtual RefBase, public InputListenerInterface {
53protected:
54 InputDispatcherInterface() {}
55 virtual ~InputDispatcherInterface() {}
56
57public:
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
Siarhei Vishniakou2bfa9052019-11-21 18:10:54 -080066 /**
67 * Wait until dispatcher is idle. That means, there are no further events to be processed,
68 * and all of the policy callbacks have been completed.
69 * Return true if the dispatcher is idle.
70 * Return false if the timeout waiting for the dispatcher to become idle has expired.
71 */
72 virtual bool waitForIdle() = 0;
73
Garfield Tane84e6f92019-08-29 17:28:41 -070074 /* Runs a single iteration of the dispatch loop.
75 * Nominally processes one queued event, a timeout, or a response from an input consumer.
76 *
77 * This method should only be called on the input dispatcher thread.
78 */
79 virtual void dispatchOnce() = 0;
80
81 /* Injects an input event and optionally waits for sync.
82 * The synchronization mode determines whether the method blocks while waiting for
83 * input injection to proceed.
84 * Returns one of the INPUT_EVENT_INJECTION_XXX constants.
85 *
86 * This method may be called on any thread (usually by the input manager).
87 */
88 virtual int32_t injectInputEvent(const InputEvent* event, int32_t injectorPid,
89 int32_t injectorUid, int32_t syncMode, int32_t timeoutMillis,
90 uint32_t policyFlags) = 0;
91
92 /* Sets the list of input windows.
93 *
94 * This method may be called on any thread (usually by the input manager).
95 */
96 virtual void setInputWindows(
97 const std::vector<sp<InputWindowHandle> >& inputWindowHandles, int32_t displayId,
98 const sp<ISetInputWindowsListener>& setInputWindowsListener = nullptr) = 0;
99
100 /* Sets the focused application on the given display.
101 *
102 * This method may be called on any thread (usually by the input manager).
103 */
104 virtual void setFocusedApplication(
105 int32_t displayId, const sp<InputApplicationHandle>& inputApplicationHandle) = 0;
106
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.
132 */
133 virtual void setInTouchMode(bool inTouchMode) = 0;
134
Garfield Tane84e6f92019-08-29 17:28:41 -0700135 /* Transfers touch focus from one window to another window.
136 *
137 * Returns true on success. False if the window did not actually have touch focus.
138 */
139 virtual bool transferTouchFocus(const sp<IBinder>& fromToken, const sp<IBinder>& toToken) = 0;
140
141 /* Registers input channels that may be used as targets for input events.
142 *
143 * This method may be called on any thread (usually by the input manager).
144 */
Siarhei Vishniakou7c34b232019-10-11 19:08:48 -0700145 virtual status_t registerInputChannel(const sp<InputChannel>& inputChannel) = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -0700146
147 /* Registers input channels to be used to monitor input events.
148 *
149 * Each monitor must target a specific display and will only receive input events sent to that
150 * display. If the monitor is a gesture monitor, it will only receive pointer events on the
151 * targeted display.
152 *
153 * This method may be called on any thread (usually by the input manager).
154 */
155 virtual status_t registerInputMonitor(const sp<InputChannel>& inputChannel, int32_t displayId,
156 bool gestureMonitor) = 0;
157
158 /* Unregister input channels that will no longer receive input events.
159 *
160 * This method may be called on any thread (usually by the input manager).
161 */
162 virtual status_t unregisterInputChannel(const sp<InputChannel>& inputChannel) = 0;
163
164 /* Allows an input monitor steal the current pointer stream away from normal input windows.
165 *
166 * This method may be called on any thread (usually by the input manager).
167 */
168 virtual status_t pilferPointers(const sp<IBinder>& token) = 0;
169};
170
171} // namespace android
172
173#endif // _UI_INPUT_INPUTDISPATCHER_INPUTDISPATCHERINTERFACE_H