blob: c886bee263c8374652806afbbf928382548347db [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>
23#include <input/Input.h>
Chris Ye0783e992020-06-02 21:34:49 -070024#include <input/InputApplication.h>
Garfield Tane84e6f92019-08-29 17:28:41 -070025#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
48 /* Notifies the system that an application is not responding.
49 * Returns a new timeout to continue waiting, or 0 to abort dispatch. */
Siarhei Vishniakouc1ae5562020-06-30 14:22:57 -050050 virtual std::chrono::nanoseconds notifyAnr(
51 const sp<InputApplicationHandle>& inputApplicationHandle, const sp<IBinder>& token,
52 const std::string& reason) = 0;
Garfield Tane84e6f92019-08-29 17:28:41 -070053
54 /* Notifies the system that an input channel is unrecoverably broken. */
55 virtual void notifyInputChannelBroken(const sp<IBinder>& token) = 0;
56 virtual void notifyFocusChanged(const sp<IBinder>& oldToken, const sp<IBinder>& newToken) = 0;
57
58 /* Gets the input dispatcher configuration. */
59 virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) = 0;
60
61 /* Filters an input event.
62 * Return true to dispatch the event unmodified, false to consume the event.
63 * A filter can also transform and inject events later by passing POLICY_FLAG_FILTERED
64 * to injectInputEvent.
65 */
66 virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) = 0;
67
68 /* Intercepts a key event immediately before queueing it.
69 * The policy can use this method as an opportunity to perform power management functions
70 * and early event preprocessing such as updating policy flags.
71 *
72 * This method is expected to set the POLICY_FLAG_PASS_TO_USER policy flag if the event
73 * should be dispatched to applications.
74 */
75 virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags) = 0;
76
77 /* Intercepts a touch, trackball or other motion event before queueing it.
78 * The policy can use this method as an opportunity to perform power management functions
79 * and early event preprocessing such as updating policy flags.
80 *
81 * This method is expected to set the POLICY_FLAG_PASS_TO_USER policy flag if the event
82 * should be dispatched to applications.
83 */
84 virtual void interceptMotionBeforeQueueing(const int32_t displayId, nsecs_t when,
85 uint32_t& policyFlags) = 0;
86
87 /* Allows the policy a chance to intercept a key before dispatching. */
88 virtual nsecs_t interceptKeyBeforeDispatching(const sp<IBinder>& token,
89 const KeyEvent* keyEvent,
90 uint32_t policyFlags) = 0;
91
92 /* Allows the policy a chance to perform default processing for an unhandled key.
93 * Returns an alternate keycode to redispatch as a fallback, or 0 to give up. */
94 virtual bool dispatchUnhandledKey(const sp<IBinder>& token, const KeyEvent* keyEvent,
95 uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) = 0;
96
97 /* Notifies the policy about switch events.
98 */
99 virtual void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask,
100 uint32_t policyFlags) = 0;
101
102 /* Poke user activity for an event dispatched to a window. */
103 virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType) = 0;
104
105 /* Checks whether a given application pid/uid has permission to inject input events
106 * into other applications.
107 *
108 * This method is special in that its implementation promises to be non-reentrant and
109 * is safe to call while holding other locks. (Most other methods make no such guarantees!)
110 */
111 virtual bool checkInjectEventsPermissionNonReentrant(int32_t injectorPid,
112 int32_t injectorUid) = 0;
113
114 /* Notifies the policy that a pointer down event has occurred outside the current focused
115 * window.
116 *
117 * The touchedToken passed as an argument is the window that received the input event.
118 */
119 virtual void onPointerDownOutsideFocus(const sp<IBinder>& touchedToken) = 0;
120};
121
122} // namespace android
123
124#endif // _UI_INPUT_INPUTDISPATCHER_INPUTDISPATCHERPOLICYINTERFACE_H