| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 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 | #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 Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 24 | #include <input/InputApplication.h> | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 25 | #include <utils/RefBase.h> | 
 | 26 |  | 
 | 27 | namespace android { | 
 | 28 |  | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 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 : public virtual RefBase { | 
 | 40 | protected: | 
 | 41 |     InputDispatcherPolicyInterface() {} | 
 | 42 |     virtual ~InputDispatcherPolicyInterface() {} | 
 | 43 |  | 
 | 44 | public: | 
 | 45 |     /* Notifies the system that a configuration change has occurred. */ | 
 | 46 |     virtual void notifyConfigurationChanged(nsecs_t when) = 0; | 
 | 47 |  | 
| Siarhei Vishniakou | 234129c | 2020-10-22 22:28:12 -0500 | [diff] [blame] | 48 |     /* 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 Vishniakou | 3c63fa4 | 2020-12-15 02:59:54 +0000 | [diff] [blame] | 53 |     /* Notifies the system that a window just became unresponsive. This indicates that ANR | 
 | 54 |      * should be raised for this window. The window is identified via token. | 
| Siarhei Vishniakou | 234129c | 2020-10-22 22:28:12 -0500 | [diff] [blame] | 55 |      * The string reason contains information about the input event that we haven't received | 
 | 56 |      * a response for. | 
 | 57 |      */ | 
| Siarhei Vishniakou | 3c63fa4 | 2020-12-15 02:59:54 +0000 | [diff] [blame] | 58 |     virtual void notifyWindowUnresponsive(const sp<IBinder>& token, const std::string& reason) = 0; | 
 | 59 |     /* Notifies the system that a monitor just became unresponsive. This indicates that ANR | 
 | 60 |      * should be raised for this monitor. The monitor is identified via its pid. | 
 | 61 |      * The string reason contains information about the input event that we haven't received | 
 | 62 |      * a response for. | 
 | 63 |      */ | 
 | 64 |     virtual void notifyMonitorUnresponsive(int32_t pid, const std::string& reason) = 0; | 
| Siarhei Vishniakou | 234129c | 2020-10-22 22:28:12 -0500 | [diff] [blame] | 65 |  | 
| Siarhei Vishniakou | 3c63fa4 | 2020-12-15 02:59:54 +0000 | [diff] [blame] | 66 |     /* Notifies the system that a window just became responsive. This is only called after the | 
 | 67 |      * window was first marked "unresponsive". This indicates that ANR dialog (if any) should | 
 | 68 |      * no longer should be shown to the user. The window is eligible to cause a new ANR in the | 
| Siarhei Vishniakou | 234129c | 2020-10-22 22:28:12 -0500 | [diff] [blame] | 69 |      * future. | 
 | 70 |      */ | 
| Siarhei Vishniakou | 3c63fa4 | 2020-12-15 02:59:54 +0000 | [diff] [blame] | 71 |     virtual void notifyWindowResponsive(const sp<IBinder>& token) = 0; | 
 | 72 |     /* Notifies the system that a monitor just became responsive. This is only called after the | 
 | 73 |      * monitor was first marked "unresponsive". This indicates that ANR dialog (if any) should | 
 | 74 |      * no longer should be shown to the user. The monitor is eligible to cause a new ANR in the | 
 | 75 |      * future. | 
 | 76 |      */ | 
 | 77 |     virtual void notifyMonitorResponsive(int32_t pid) = 0; | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 78 |  | 
 | 79 |     /* Notifies the system that an input channel is unrecoverably broken. */ | 
 | 80 |     virtual void notifyInputChannelBroken(const sp<IBinder>& token) = 0; | 
 | 81 |     virtual void notifyFocusChanged(const sp<IBinder>& oldToken, const sp<IBinder>& newToken) = 0; | 
| Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 82 |     virtual void notifySensorEvent(int32_t deviceId, InputDeviceSensorType sensorType, | 
 | 83 |                                    InputDeviceSensorAccuracy accuracy, nsecs_t timestamp, | 
 | 84 |                                    const std::vector<float>& values) = 0; | 
 | 85 |     virtual void notifySensorAccuracy(int32_t deviceId, InputDeviceSensorType sensorType, | 
 | 86 |                                       InputDeviceSensorAccuracy accuracy) = 0; | 
| Chris Ye | fb55290 | 2021-02-03 17:18:37 -0800 | [diff] [blame] | 87 |     virtual void notifyVibratorState(int32_t deviceId, bool isOn) = 0; | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 88 |  | 
| Bernardo Rufino | 2e1f651 | 2020-10-08 13:42:07 +0000 | [diff] [blame] | 89 |     /* Notifies the system that an untrusted touch occurred. */ | 
 | 90 |     virtual void notifyUntrustedTouch(const std::string& obscuringPackage) = 0; | 
 | 91 |  | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 92 |     /* Gets the input dispatcher configuration. */ | 
 | 93 |     virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) = 0; | 
 | 94 |  | 
 | 95 |     /* Filters an input event. | 
 | 96 |      * Return true to dispatch the event unmodified, false to consume the event. | 
 | 97 |      * A filter can also transform and inject events later by passing POLICY_FLAG_FILTERED | 
 | 98 |      * to injectInputEvent. | 
 | 99 |      */ | 
 | 100 |     virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) = 0; | 
 | 101 |  | 
 | 102 |     /* Intercepts a key event immediately before queueing it. | 
 | 103 |      * The policy can use this method as an opportunity to perform power management functions | 
 | 104 |      * and early event preprocessing such as updating policy flags. | 
 | 105 |      * | 
 | 106 |      * This method is expected to set the POLICY_FLAG_PASS_TO_USER policy flag if the event | 
 | 107 |      * should be dispatched to applications. | 
 | 108 |      */ | 
 | 109 |     virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags) = 0; | 
 | 110 |  | 
 | 111 |     /* Intercepts a touch, trackball or other motion event before queueing it. | 
 | 112 |      * The policy can use this method as an opportunity to perform power management functions | 
 | 113 |      * and early event preprocessing such as updating policy flags. | 
 | 114 |      * | 
 | 115 |      * This method is expected to set the POLICY_FLAG_PASS_TO_USER policy flag if the event | 
 | 116 |      * should be dispatched to applications. | 
 | 117 |      */ | 
 | 118 |     virtual void interceptMotionBeforeQueueing(const int32_t displayId, nsecs_t when, | 
 | 119 |                                                uint32_t& policyFlags) = 0; | 
 | 120 |  | 
 | 121 |     /* Allows the policy a chance to intercept a key before dispatching. */ | 
 | 122 |     virtual nsecs_t interceptKeyBeforeDispatching(const sp<IBinder>& token, | 
 | 123 |                                                   const KeyEvent* keyEvent, | 
 | 124 |                                                   uint32_t policyFlags) = 0; | 
 | 125 |  | 
 | 126 |     /* Allows the policy a chance to perform default processing for an unhandled key. | 
 | 127 |      * Returns an alternate keycode to redispatch as a fallback, or 0 to give up. */ | 
 | 128 |     virtual bool dispatchUnhandledKey(const sp<IBinder>& token, const KeyEvent* keyEvent, | 
 | 129 |                                       uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) = 0; | 
 | 130 |  | 
 | 131 |     /* Notifies the policy about switch events. | 
 | 132 |      */ | 
 | 133 |     virtual void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask, | 
 | 134 |                               uint32_t policyFlags) = 0; | 
 | 135 |  | 
 | 136 |     /* Poke user activity for an event dispatched to a window. */ | 
| Sean Stout | b4e0a59 | 2021-02-23 07:34:53 -0800 | [diff] [blame] | 137 |     virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType, int32_t displayId) = 0; | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 138 |  | 
 | 139 |     /* Checks whether a given application pid/uid has permission to inject input events | 
 | 140 |      * into other applications. | 
 | 141 |      * | 
 | 142 |      * This method is special in that its implementation promises to be non-reentrant and | 
 | 143 |      * is safe to call while holding other locks.  (Most other methods make no such guarantees!) | 
 | 144 |      */ | 
 | 145 |     virtual bool checkInjectEventsPermissionNonReentrant(int32_t injectorPid, | 
 | 146 |                                                          int32_t injectorUid) = 0; | 
 | 147 |  | 
 | 148 |     /* Notifies the policy that a pointer down event has occurred outside the current focused | 
 | 149 |      * window. | 
 | 150 |      * | 
 | 151 |      * The touchedToken passed as an argument is the window that received the input event. | 
 | 152 |      */ | 
 | 153 |     virtual void onPointerDownOutsideFocus(const sp<IBinder>& touchedToken) = 0; | 
| Prabir Pradhan | 9998771 | 2020-11-10 18:43:05 -0800 | [diff] [blame] | 154 |  | 
 | 155 |     /* Change the Pointer Capture state in InputReader. | 
 | 156 |      * | 
 | 157 |      * InputDispatcher is solely responsible for updating the Pointer Capture state. | 
 | 158 |      */ | 
 | 159 |     virtual void setPointerCapture(bool enabled) = 0; | 
| arthurhung | f452d0b | 2021-01-06 00:19:52 +0800 | [diff] [blame] | 160 |  | 
 | 161 |     /* Notifies the policy that the drag window has moved over to another window */ | 
 | 162 |     virtual void notifyDropWindow(const sp<IBinder>& token, float x, float y) = 0; | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 163 | }; | 
 | 164 |  | 
 | 165 | } // namespace android | 
 | 166 |  | 
 | 167 | #endif // _UI_INPUT_INPUTDISPATCHER_INPUTDISPATCHERPOLICYINTERFACE_H |