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 | |
Prabir Pradhan | 4810866 | 2022-09-09 21:22:04 +0000 | [diff] [blame] | 17 | #pragma once |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 18 | |
| 19 | #include "InputDispatcherConfiguration.h" |
| 20 | |
| 21 | #include <binder/IBinder.h> |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 22 | #include <gui/InputApplication.h> |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 23 | #include <input/Input.h> |
| 24 | #include <utils/RefBase.h> |
| 25 | |
| 26 | namespace android { |
| 27 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 28 | /* |
| 29 | * Input dispatcher policy interface. |
| 30 | * |
viktor | 8a47878 | 2023-06-17 09:06:40 +0800 | [diff] [blame] | 31 | * The input dispatcher policy is used by the input dispatcher to interact with the Window Manager |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 32 | * and other system components. |
| 33 | * |
| 34 | * The actual implementation is partially supported by callbacks into the DVM |
| 35 | * via JNI. This interface is also mocked in the unit tests. |
| 36 | */ |
Prabir Pradhan | a41d244 | 2023-04-20 21:30:40 +0000 | [diff] [blame] | 37 | class InputDispatcherPolicyInterface { |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 38 | public: |
Prabir Pradhan | a41d244 | 2023-04-20 21:30:40 +0000 | [diff] [blame] | 39 | InputDispatcherPolicyInterface() = default; |
| 40 | virtual ~InputDispatcherPolicyInterface() = default; |
| 41 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 42 | /* Notifies the system that a configuration change has occurred. */ |
| 43 | virtual void notifyConfigurationChanged(nsecs_t when) = 0; |
| 44 | |
Siarhei Vishniakou | 234129c | 2020-10-22 22:28:12 -0500 | [diff] [blame] | 45 | /* Notifies the system that an application does not have a focused window. |
| 46 | */ |
| 47 | virtual void notifyNoFocusedWindowAnr( |
| 48 | const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle) = 0; |
| 49 | |
Siarhei Vishniakou | 3c63fa4 | 2020-12-15 02:59:54 +0000 | [diff] [blame] | 50 | /* Notifies the system that a window just became unresponsive. This indicates that ANR |
Prabir Pradhan | edd9640 | 2022-02-15 01:46:16 -0800 | [diff] [blame] | 51 | * should be raised for this window. The window can be identified via its input token and the |
| 52 | * pid of the owner. The string reason contains information about the input event that we |
| 53 | * haven't received a response for. |
Siarhei Vishniakou | 234129c | 2020-10-22 22:28:12 -0500 | [diff] [blame] | 54 | */ |
Prabir Pradhan | edd9640 | 2022-02-15 01:46:16 -0800 | [diff] [blame] | 55 | virtual void notifyWindowUnresponsive(const sp<IBinder>& token, std::optional<int32_t> pid, |
| 56 | const std::string& reason) = 0; |
Siarhei Vishniakou | 234129c | 2020-10-22 22:28:12 -0500 | [diff] [blame] | 57 | |
Siarhei Vishniakou | 3c63fa4 | 2020-12-15 02:59:54 +0000 | [diff] [blame] | 58 | /* Notifies the system that a window just became responsive. This is only called after the |
| 59 | * window was first marked "unresponsive". This indicates that ANR dialog (if any) should |
| 60 | * 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] | 61 | * future. |
| 62 | */ |
Prabir Pradhan | edd9640 | 2022-02-15 01:46:16 -0800 | [diff] [blame] | 63 | virtual void notifyWindowResponsive(const sp<IBinder>& token, std::optional<int32_t> pid) = 0; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 64 | |
| 65 | /* Notifies the system that an input channel is unrecoverably broken. */ |
| 66 | virtual void notifyInputChannelBroken(const sp<IBinder>& token) = 0; |
| 67 | virtual void notifyFocusChanged(const sp<IBinder>& oldToken, const sp<IBinder>& newToken) = 0; |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 68 | virtual void notifySensorEvent(int32_t deviceId, InputDeviceSensorType sensorType, |
| 69 | InputDeviceSensorAccuracy accuracy, nsecs_t timestamp, |
| 70 | const std::vector<float>& values) = 0; |
| 71 | virtual void notifySensorAccuracy(int32_t deviceId, InputDeviceSensorType sensorType, |
| 72 | InputDeviceSensorAccuracy accuracy) = 0; |
Chris Ye | fb55290 | 2021-02-03 17:18:37 -0800 | [diff] [blame] | 73 | virtual void notifyVibratorState(int32_t deviceId, bool isOn) = 0; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 74 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 75 | /* Gets the input dispatcher configuration. */ |
Prabir Pradhan | a41d244 | 2023-04-20 21:30:40 +0000 | [diff] [blame] | 76 | virtual InputDispatcherConfiguration getDispatcherConfiguration() = 0; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 77 | |
| 78 | /* Filters an input event. |
| 79 | * Return true to dispatch the event unmodified, false to consume the event. |
| 80 | * A filter can also transform and inject events later by passing POLICY_FLAG_FILTERED |
| 81 | * to injectInputEvent. |
| 82 | */ |
Prabir Pradhan | a41d244 | 2023-04-20 21:30:40 +0000 | [diff] [blame] | 83 | virtual bool filterInputEvent(const InputEvent& inputEvent, uint32_t policyFlags) = 0; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 84 | |
| 85 | /* Intercepts a key event immediately before queueing it. |
| 86 | * The policy can use this method as an opportunity to perform power management functions |
| 87 | * and early event preprocessing such as updating policy flags. |
| 88 | * |
| 89 | * This method is expected to set the POLICY_FLAG_PASS_TO_USER policy flag if the event |
| 90 | * should be dispatched to applications. |
| 91 | */ |
Prabir Pradhan | a41d244 | 2023-04-20 21:30:40 +0000 | [diff] [blame] | 92 | virtual void interceptKeyBeforeQueueing(const KeyEvent& keyEvent, uint32_t& policyFlags) = 0; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 93 | |
| 94 | /* Intercepts a touch, trackball or other motion event before queueing it. |
| 95 | * The policy can use this method as an opportunity to perform power management functions |
| 96 | * and early event preprocessing such as updating policy flags. |
| 97 | * |
| 98 | * This method is expected to set the POLICY_FLAG_PASS_TO_USER policy flag if the event |
| 99 | * should be dispatched to applications. |
| 100 | */ |
Prabir Pradhan | a41d244 | 2023-04-20 21:30:40 +0000 | [diff] [blame] | 101 | virtual void interceptMotionBeforeQueueing(int32_t displayId, nsecs_t when, |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 102 | uint32_t& policyFlags) = 0; |
| 103 | |
| 104 | /* Allows the policy a chance to intercept a key before dispatching. */ |
| 105 | virtual nsecs_t interceptKeyBeforeDispatching(const sp<IBinder>& token, |
Prabir Pradhan | a41d244 | 2023-04-20 21:30:40 +0000 | [diff] [blame] | 106 | const KeyEvent& keyEvent, |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 107 | uint32_t policyFlags) = 0; |
| 108 | |
| 109 | /* Allows the policy a chance to perform default processing for an unhandled key. |
Prabir Pradhan | a41d244 | 2023-04-20 21:30:40 +0000 | [diff] [blame] | 110 | * Returns an alternate key event to redispatch as a fallback, if needed. */ |
| 111 | virtual std::optional<KeyEvent> dispatchUnhandledKey(const sp<IBinder>& token, |
| 112 | const KeyEvent& keyEvent, |
| 113 | uint32_t policyFlags) = 0; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 114 | |
| 115 | /* Notifies the policy about switch events. |
| 116 | */ |
| 117 | virtual void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask, |
| 118 | uint32_t policyFlags) = 0; |
| 119 | |
| 120 | /* Poke user activity for an event dispatched to a window. */ |
Sean Stout | b4e0a59 | 2021-02-23 07:34:53 -0800 | [diff] [blame] | 121 | 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] | 122 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 123 | /* Notifies the policy that a pointer down event has occurred outside the current focused |
| 124 | * window. |
| 125 | * |
| 126 | * The touchedToken passed as an argument is the window that received the input event. |
| 127 | */ |
| 128 | virtual void onPointerDownOutsideFocus(const sp<IBinder>& touchedToken) = 0; |
Prabir Pradhan | 9998771 | 2020-11-10 18:43:05 -0800 | [diff] [blame] | 129 | |
| 130 | /* Change the Pointer Capture state in InputReader. |
| 131 | * |
| 132 | * InputDispatcher is solely responsible for updating the Pointer Capture state. |
| 133 | */ |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 134 | virtual void setPointerCapture(const PointerCaptureRequest&) = 0; |
arthurhung | f452d0b | 2021-01-06 00:19:52 +0800 | [diff] [blame] | 135 | |
| 136 | /* Notifies the policy that the drag window has moved over to another window */ |
| 137 | virtual void notifyDropWindow(const sp<IBinder>& token, float x, float y) = 0; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | } // namespace android |