blob: 575b3d7059834460637d7e88da89c51ac4bee172 [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_INPUTDISPATCHERPOLICYINTERFACE_H
18#define _UI_INPUT_INPUTDISPATCHER_INPUTDISPATCHERPOLICYINTERFACE_H
19
20#include "InputDispatcherConfiguration.h"
21
22#include <binder/IBinder.h>
chaviw98318de2021-05-19 16:45:23 -050023#include <gui/InputApplication.h>
Garfield Tane84e6f92019-08-29 17:28:41 -070024#include <input/Input.h>
25#include <utils/RefBase.h>
26
27namespace android {
28
Garfield Tane84e6f92019-08-29 17:28:41 -070029
30/*
31 * Input dispatcher policy interface.
32 *
33 * The input reader policy is used by the input reader to interact with the Window Manager
34 * and other system components.
35 *
36 * The actual implementation is partially supported by callbacks into the DVM
37 * via JNI. This interface is also mocked in the unit tests.
38 */
39class InputDispatcherPolicyInterface : public virtual RefBase {
40protected:
41 InputDispatcherPolicyInterface() {}
42 virtual ~InputDispatcherPolicyInterface() {}
43
44public:
45 /* Notifies the system that a configuration change has occurred. */
46 virtual void notifyConfigurationChanged(nsecs_t when) = 0;
47
Siarhei Vishniakou234129c2020-10-22 22:28:12 -050048 /* Notifies the system that an application does not have a focused window.
49 */
50 virtual void notifyNoFocusedWindowAnr(
51 const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle) = 0;
52
Siarhei Vishniakou3c63fa42020-12-15 02:59:54 +000053 /* Notifies the system that a window just became unresponsive. This indicates that ANR
Prabir Pradhanedd96402022-02-15 01:46:16 -080054 * should be raised for this window. The window can be identified via its input token and the
55 * pid of the owner. The string reason contains information about the input event that we
56 * haven't received a response for.
Siarhei Vishniakou234129c2020-10-22 22:28:12 -050057 */
Prabir Pradhanedd96402022-02-15 01:46:16 -080058 virtual void notifyWindowUnresponsive(const sp<IBinder>& token, std::optional<int32_t> pid,
59 const std::string& reason) = 0;
Siarhei Vishniakou234129c2020-10-22 22:28:12 -050060
Siarhei Vishniakou3c63fa42020-12-15 02:59:54 +000061 /* Notifies the system that a window just became responsive. This is only called after the
62 * window was first marked "unresponsive". This indicates that ANR dialog (if any) should
63 * no longer should be shown to the user. The window is eligible to cause a new ANR in the
Siarhei Vishniakou234129c2020-10-22 22:28:12 -050064 * future.
65 */
Prabir Pradhanedd96402022-02-15 01:46:16 -080066 virtual void notifyWindowResponsive(const sp<IBinder>& token, std::optional<int32_t> pid) = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -070067
68 /* Notifies the system that an input channel is unrecoverably broken. */
69 virtual void notifyInputChannelBroken(const sp<IBinder>& token) = 0;
70 virtual void notifyFocusChanged(const sp<IBinder>& oldToken, const sp<IBinder>& newToken) = 0;
Chris Yef59a2f42020-10-16 12:55:26 -070071 virtual void notifySensorEvent(int32_t deviceId, InputDeviceSensorType sensorType,
72 InputDeviceSensorAccuracy accuracy, nsecs_t timestamp,
73 const std::vector<float>& values) = 0;
74 virtual void notifySensorAccuracy(int32_t deviceId, InputDeviceSensorType sensorType,
75 InputDeviceSensorAccuracy accuracy) = 0;
Chris Yefb552902021-02-03 17:18:37 -080076 virtual void notifyVibratorState(int32_t deviceId, bool isOn) = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -070077
Bernardo Rufino2e1f6512020-10-08 13:42:07 +000078 /* Notifies the system that an untrusted touch occurred. */
79 virtual void notifyUntrustedTouch(const std::string& obscuringPackage) = 0;
80
Garfield Tane84e6f92019-08-29 17:28:41 -070081 /* Gets the input dispatcher configuration. */
82 virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) = 0;
83
84 /* Filters an input event.
85 * Return true to dispatch the event unmodified, false to consume the event.
86 * A filter can also transform and inject events later by passing POLICY_FLAG_FILTERED
87 * to injectInputEvent.
88 */
89 virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) = 0;
90
91 /* Intercepts a key event immediately before queueing it.
92 * The policy can use this method as an opportunity to perform power management functions
93 * and early event preprocessing such as updating policy flags.
94 *
95 * This method is expected to set the POLICY_FLAG_PASS_TO_USER policy flag if the event
96 * should be dispatched to applications.
97 */
98 virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags) = 0;
99
100 /* Intercepts a touch, trackball or other motion event before queueing it.
101 * The policy can use this method as an opportunity to perform power management functions
102 * and early event preprocessing such as updating policy flags.
103 *
104 * This method is expected to set the POLICY_FLAG_PASS_TO_USER policy flag if the event
105 * should be dispatched to applications.
106 */
107 virtual void interceptMotionBeforeQueueing(const int32_t displayId, nsecs_t when,
108 uint32_t& policyFlags) = 0;
109
110 /* Allows the policy a chance to intercept a key before dispatching. */
111 virtual nsecs_t interceptKeyBeforeDispatching(const sp<IBinder>& token,
112 const KeyEvent* keyEvent,
113 uint32_t policyFlags) = 0;
114
115 /* Allows the policy a chance to perform default processing for an unhandled key.
116 * Returns an alternate keycode to redispatch as a fallback, or 0 to give up. */
117 virtual bool dispatchUnhandledKey(const sp<IBinder>& token, const KeyEvent* keyEvent,
118 uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) = 0;
119
120 /* Notifies the policy about switch events.
121 */
122 virtual void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask,
123 uint32_t policyFlags) = 0;
124
125 /* Poke user activity for an event dispatched to a window. */
Sean Stoutb4e0a592021-02-23 07:34:53 -0800126 virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType, int32_t displayId) = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -0700127
Garfield Tane84e6f92019-08-29 17:28:41 -0700128 /* Notifies the policy that a pointer down event has occurred outside the current focused
129 * window.
130 *
131 * The touchedToken passed as an argument is the window that received the input event.
132 */
133 virtual void onPointerDownOutsideFocus(const sp<IBinder>& touchedToken) = 0;
Prabir Pradhan99987712020-11-10 18:43:05 -0800134
135 /* Change the Pointer Capture state in InputReader.
136 *
137 * InputDispatcher is solely responsible for updating the Pointer Capture state.
138 */
Prabir Pradhan5cc1a692021-08-06 14:01:18 +0000139 virtual void setPointerCapture(const PointerCaptureRequest&) = 0;
arthurhungf452d0b2021-01-06 00:19:52 +0800140
141 /* Notifies the policy that the drag window has moved over to another window */
142 virtual void notifyDropWindow(const sp<IBinder>& token, float x, float y) = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -0700143};
144
145} // namespace android
146
147#endif // _UI_INPUT_INPUTDISPATCHER_INPUTDISPATCHERPOLICYINTERFACE_H