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