1 /* 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 #pragma once 18 19 #include "InputDispatcherConfiguration.h" 20 21 #include <binder/IBinder.h> 22 #include <gui/InputApplication.h> 23 #include <input/Input.h> 24 #include <utils/RefBase.h> 25 #include <set> 26 27 namespace android { 28 29 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 */ 39 class InputDispatcherPolicyInterface { 40 public: 41 InputDispatcherPolicyInterface() = default; 42 virtual ~InputDispatcherPolicyInterface() = default; 43 44 /* Notifies the system that a configuration change has occurred. */ 45 virtual void notifyConfigurationChanged(nsecs_t when) = 0; 46 47 /* Notifies the system that an application does not have a focused window. 48 */ 49 virtual void notifyNoFocusedWindowAnr( 50 const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle) = 0; 51 52 /* Notifies the system that a window just became unresponsive. This indicates that ANR 53 * should be raised for this window. The window can be identified via its input token and the 54 * pid of the owner. The string reason contains information about the input event that we 55 * haven't received a response for. 56 */ 57 virtual void notifyWindowUnresponsive(const sp<IBinder>& token, std::optional<gui::Pid> pid, 58 const std::string& reason) = 0; 59 60 /* Notifies the system that a window just became responsive. This is only called after the 61 * window was first marked "unresponsive". This indicates that ANR dialog (if any) should 62 * no longer should be shown to the user. The window is eligible to cause a new ANR in the 63 * future. 64 */ 65 virtual void notifyWindowResponsive(const sp<IBinder>& token, std::optional<gui::Pid> pid) = 0; 66 67 /* Notifies the system that an input channel is unrecoverably broken. */ 68 virtual void notifyInputChannelBroken(const sp<IBinder>& token) = 0; 69 virtual void notifyFocusChanged(const sp<IBinder>& oldToken, const sp<IBinder>& newToken) = 0; 70 virtual void notifySensorEvent(int32_t deviceId, InputDeviceSensorType sensorType, 71 InputDeviceSensorAccuracy accuracy, nsecs_t timestamp, 72 const std::vector<float>& values) = 0; 73 virtual void notifySensorAccuracy(int32_t deviceId, InputDeviceSensorType sensorType, 74 InputDeviceSensorAccuracy accuracy) = 0; 75 virtual void notifyVibratorState(int32_t deviceId, bool isOn) = 0; 76 77 /* Gets the input dispatcher configuration. */ 78 virtual InputDispatcherConfiguration getDispatcherConfiguration() = 0; 79 80 /* Filters an input event. 81 * Return true to dispatch the event unmodified, false to consume the event. 82 * A filter can also transform and inject events later by passing POLICY_FLAG_FILTERED 83 * to injectInputEvent. 84 */ 85 virtual bool filterInputEvent(const InputEvent& inputEvent, uint32_t policyFlags) = 0; 86 87 /* Intercepts a key event immediately before queueing it. 88 * The policy can use this method as an opportunity to perform power management functions 89 * and early event preprocessing such as updating policy flags. 90 * 91 * This method is expected to set the POLICY_FLAG_PASS_TO_USER policy flag if the event 92 * should be dispatched to applications. 93 */ 94 virtual void interceptKeyBeforeQueueing(const KeyEvent& keyEvent, uint32_t& policyFlags) = 0; 95 96 /* Intercepts a touch, trackball or other motion event before queueing it. 97 * The policy can use this method as an opportunity to perform power management functions 98 * and early event preprocessing such as updating policy flags. 99 * 100 * This method is expected to set the POLICY_FLAG_PASS_TO_USER policy flag if the event 101 * should be dispatched to applications. 102 */ 103 virtual void interceptMotionBeforeQueueing(int32_t displayId, nsecs_t when, 104 uint32_t& policyFlags) = 0; 105 106 /* Allows the policy a chance to intercept a key before dispatching. */ 107 virtual nsecs_t interceptKeyBeforeDispatching(const sp<IBinder>& token, 108 const KeyEvent& keyEvent, 109 uint32_t policyFlags) = 0; 110 111 /* Allows the policy a chance to perform default processing for an unhandled key. 112 * Returns an alternate key event to redispatch as a fallback, if needed. */ 113 virtual std::optional<KeyEvent> dispatchUnhandledKey(const sp<IBinder>& token, 114 const KeyEvent& keyEvent, 115 uint32_t policyFlags) = 0; 116 117 /* Notifies the policy about switch events. 118 */ 119 virtual void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask, 120 uint32_t policyFlags) = 0; 121 122 /* Poke user activity for an event dispatched to a window. */ 123 virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType, int32_t displayId) = 0; 124 125 /* Notifies the policy that a pointer down event has occurred outside the current focused 126 * window. 127 * 128 * The touchedToken passed as an argument is the window that received the input event. 129 */ 130 virtual void onPointerDownOutsideFocus(const sp<IBinder>& touchedToken) = 0; 131 132 /* Change the Pointer Capture state in InputReader. 133 * 134 * InputDispatcher is solely responsible for updating the Pointer Capture state. 135 */ 136 virtual void setPointerCapture(const PointerCaptureRequest&) = 0; 137 138 /* Notifies the policy that the drag window has moved over to another window */ 139 virtual void notifyDropWindow(const sp<IBinder>& token, float x, float y) = 0; 140 141 /* Notifies the policy that there was an input device interaction with apps. */ 142 virtual void notifyDeviceInteraction(int32_t deviceId, nsecs_t timestamp, 143 const std::set<gui::Uid>& uids) = 0; 144 }; 145 146 } // namespace android 147