| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2010 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 | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 18 |  | 
|  | 19 | /** | 
|  | 20 | * Native input manager. | 
|  | 21 | */ | 
|  | 22 |  | 
| Prabir Pradhan | addf8e9 | 2023-04-06 00:28:48 +0000 | [diff] [blame] | 23 | #include "InputDeviceMetricsCollector.h" | 
| Vaibhav Devmurari | 5766aee | 2023-11-03 17:21:25 +0000 | [diff] [blame^] | 24 | #include "InputFilter.h" | 
| Siarhei Vishniakou | 9899603 | 2022-08-03 11:54:47 -0700 | [diff] [blame] | 25 | #include "InputProcessor.h" | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 26 | #include "InputReaderBase.h" | 
| Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 27 | #include "PointerChoreographer.h" | 
| Siarhei Vishniakou | ba0a875 | 2021-09-14 14:43:25 -0700 | [diff] [blame] | 28 | #include "include/UnwantedInteractionBlockerInterface.h" | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 29 |  | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 30 | #include <InputDispatcherInterface.h> | 
|  | 31 | #include <InputDispatcherPolicyInterface.h> | 
| Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 32 | #include <PointerChoreographerPolicyInterface.h> | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 33 | #include <input/Input.h> | 
|  | 34 | #include <input/InputTransport.h> | 
| Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 35 |  | 
| Prabir Pradhan | 44e6e83 | 2023-06-06 00:03:25 +0000 | [diff] [blame] | 36 | #include <aidl/com/android/server/inputflinger/IInputFlingerRust.h> | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 37 | #include <android/os/BnInputFlinger.h> | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 38 | #include <utils/Errors.h> | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 39 | #include <utils/RefBase.h> | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 40 | #include <utils/Timers.h> | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 41 |  | 
|  | 42 | using android::os::BnInputFlinger; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 43 |  | 
| Vaibhav Devmurari | 5766aee | 2023-11-03 17:21:25 +0000 | [diff] [blame^] | 44 | using aidl::com::android::server::inputflinger::IInputFilter; | 
| Prabir Pradhan | 44e6e83 | 2023-06-06 00:03:25 +0000 | [diff] [blame] | 45 | using aidl::com::android::server::inputflinger::IInputFlingerRust; | 
|  | 46 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 47 | namespace android { | 
| Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 48 | class InputChannel; | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 49 | class InputDispatcherThread; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 50 |  | 
|  | 51 | /* | 
|  | 52 | * The input manager is the core of the system event processing. | 
|  | 53 | * | 
| Michael Wright | 6353416 | 2020-07-02 14:38:16 +0100 | [diff] [blame] | 54 | * The input manager has three components. | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 55 | * | 
| Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 56 | * 1. The InputReader class starts a thread that reads and preprocesses raw input events, applies | 
| Siarhei Vishniakou | ba0a875 | 2021-09-14 14:43:25 -0700 | [diff] [blame] | 57 | *    policy, and posts messages to a queue managed by the UnwantedInteractionBlocker. | 
|  | 58 | * 2. The UnwantedInteractionBlocker is responsible for removing unwanted interactions. For example, | 
|  | 59 | *    this could be a palm on the screen. This stage would alter the event stream to remove either | 
|  | 60 | *    partially (some of the pointers) or fully (all touches) the unwanted interaction. The events | 
|  | 61 | *    are processed on the InputReader thread, without any additional queue. The events are then | 
| Siarhei Vishniakou | 9899603 | 2022-08-03 11:54:47 -0700 | [diff] [blame] | 62 | *    posted to the queue managed by the InputProcessor. | 
|  | 63 | * 3. The InputProcessor class starts a thread to communicate with the device-specific | 
|  | 64 | *    IInputProcessor HAL. It then waits on the queue of events from UnwantedInteractionBlocker, | 
|  | 65 | *    processes the events (for example, applies a classification to the events), and queues them | 
|  | 66 | *    for the InputDispatcher. | 
| Siarhei Vishniakou | ba0a875 | 2021-09-14 14:43:25 -0700 | [diff] [blame] | 67 | * 4. The InputDispatcher class starts a thread that waits for new events on the | 
| Michael Wright | 6353416 | 2020-07-02 14:38:16 +0100 | [diff] [blame] | 68 | *    previous queue and asynchronously dispatches them to applications. | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 69 | * | 
| Michael Wright | 6353416 | 2020-07-02 14:38:16 +0100 | [diff] [blame] | 70 | * By design, none of these classes share any internal state.  Moreover, all communication is | 
|  | 71 | * done one way from the InputReader to the InputDispatcher and never the reverse.  All | 
|  | 72 | * classes may interact with the InputDispatchPolicy, however. | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 73 | * | 
|  | 74 | * The InputManager class never makes any calls into Java itself.  Instead, the | 
|  | 75 | * InputDispatchPolicy is responsible for performing all external interactions with the | 
|  | 76 | * system, including calling DVM services. | 
|  | 77 | */ | 
|  | 78 | class InputManagerInterface : public virtual RefBase { | 
|  | 79 | protected: | 
|  | 80 | InputManagerInterface() { } | 
|  | 81 | virtual ~InputManagerInterface() { } | 
|  | 82 |  | 
|  | 83 | public: | 
| Prabir Pradhan | 3608aad | 2019-10-02 17:08:26 -0700 | [diff] [blame] | 84 | /* Starts the input threads. */ | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 85 | virtual status_t start() = 0; | 
|  | 86 |  | 
| Prabir Pradhan | 3608aad | 2019-10-02 17:08:26 -0700 | [diff] [blame] | 87 | /* Stops the input threads and waits for them to exit. */ | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 88 | virtual status_t stop() = 0; | 
|  | 89 |  | 
|  | 90 | /* Gets the input reader. */ | 
| Siarhei Vishniakou | 1805009 | 2021-09-01 13:32:49 -0700 | [diff] [blame] | 91 | virtual InputReaderInterface& getReader() = 0; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 92 |  | 
| Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 93 | /* Gets the PointerChoreographer. */ | 
|  | 94 | virtual PointerChoreographerInterface& getChoreographer() = 0; | 
|  | 95 |  | 
| Prabir Pradhan | addf8e9 | 2023-04-06 00:28:48 +0000 | [diff] [blame] | 96 | /* Gets the input processor. */ | 
| Siarhei Vishniakou | 9899603 | 2022-08-03 11:54:47 -0700 | [diff] [blame] | 97 | virtual InputProcessorInterface& getProcessor() = 0; | 
| Michael Wright | 6353416 | 2020-07-02 14:38:16 +0100 | [diff] [blame] | 98 |  | 
| Prabir Pradhan | 8ede1d1 | 2023-05-08 19:37:44 +0000 | [diff] [blame] | 99 | /* Gets the metrics collector. */ | 
|  | 100 | virtual InputDeviceMetricsCollectorInterface& getMetricsCollector() = 0; | 
|  | 101 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 102 | /* Gets the input dispatcher. */ | 
| Siarhei Vishniakou | 1805009 | 2021-09-01 13:32:49 -0700 | [diff] [blame] | 103 | virtual InputDispatcherInterface& getDispatcher() = 0; | 
| Siarhei Vishniakou | 9f330c5 | 2022-05-17 05:03:42 -0700 | [diff] [blame] | 104 |  | 
|  | 105 | /* Check that the input stages have not deadlocked. */ | 
|  | 106 | virtual void monitor() = 0; | 
| Prabir Pradhan | 370dbc9 | 2023-04-06 00:02:05 +0000 | [diff] [blame] | 107 |  | 
|  | 108 | /* Dump the state of the components controlled by the input manager. */ | 
|  | 109 | virtual void dump(std::string& dump) = 0; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 110 | }; | 
|  | 111 |  | 
| Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 112 | class InputManager : public InputManagerInterface, public BnInputFlinger { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 113 | protected: | 
| Michael Wright | 6353416 | 2020-07-02 14:38:16 +0100 | [diff] [blame] | 114 | ~InputManager() override; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 115 |  | 
|  | 116 | public: | 
| Prabir Pradhan | a41d244 | 2023-04-20 21:30:40 +0000 | [diff] [blame] | 117 | InputManager(const sp<InputReaderPolicyInterface>& readerPolicy, | 
| Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 118 | InputDispatcherPolicyInterface& dispatcherPolicy, | 
|  | 119 | PointerChoreographerPolicyInterface& choreographerPolicy); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 120 |  | 
| Michael Wright | 6353416 | 2020-07-02 14:38:16 +0100 | [diff] [blame] | 121 | status_t start() override; | 
|  | 122 | status_t stop() override; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 123 |  | 
| Siarhei Vishniakou | 1805009 | 2021-09-01 13:32:49 -0700 | [diff] [blame] | 124 | InputReaderInterface& getReader() override; | 
| Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 125 | PointerChoreographerInterface& getChoreographer() override; | 
| Siarhei Vishniakou | 9899603 | 2022-08-03 11:54:47 -0700 | [diff] [blame] | 126 | InputProcessorInterface& getProcessor() override; | 
| Prabir Pradhan | 8ede1d1 | 2023-05-08 19:37:44 +0000 | [diff] [blame] | 127 | InputDeviceMetricsCollectorInterface& getMetricsCollector() override; | 
| Siarhei Vishniakou | 1805009 | 2021-09-01 13:32:49 -0700 | [diff] [blame] | 128 | InputDispatcherInterface& getDispatcher() override; | 
| Siarhei Vishniakou | 9f330c5 | 2022-05-17 05:03:42 -0700 | [diff] [blame] | 129 | void monitor() override; | 
| Prabir Pradhan | 370dbc9 | 2023-04-06 00:02:05 +0000 | [diff] [blame] | 130 | void dump(std::string& dump) override; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 131 |  | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 132 | status_t dump(int fd, const Vector<String16>& args) override; | 
| Garfield Tan | 1560166 | 2020-09-22 15:32:38 -0700 | [diff] [blame] | 133 | binder::Status createInputChannel(const std::string& name, InputChannel* outChannel) override; | 
|  | 134 | binder::Status removeInputChannel(const sp<IBinder>& connectionToken) override; | 
| chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 135 | binder::Status setFocusedWindow(const gui::FocusRequest&) override; | 
| Siarhei Vishniakou | c9ac19e | 2020-03-19 11:55:01 -0700 | [diff] [blame] | 136 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 137 | private: | 
| Siarhei Vishniakou | 1805009 | 2021-09-01 13:32:49 -0700 | [diff] [blame] | 138 | std::unique_ptr<InputReaderInterface> mReader; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 139 |  | 
| Siarhei Vishniakou | 9f330c5 | 2022-05-17 05:03:42 -0700 | [diff] [blame] | 140 | std::unique_ptr<UnwantedInteractionBlockerInterface> mBlocker; | 
| Siarhei Vishniakou | ba0a875 | 2021-09-14 14:43:25 -0700 | [diff] [blame] | 141 |  | 
| Vaibhav Devmurari | 5766aee | 2023-11-03 17:21:25 +0000 | [diff] [blame^] | 142 | std::unique_ptr<InputFilterInterface> mInputFilter; | 
|  | 143 |  | 
| Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 144 | std::unique_ptr<PointerChoreographerInterface> mChoreographer; | 
|  | 145 |  | 
| Siarhei Vishniakou | 9899603 | 2022-08-03 11:54:47 -0700 | [diff] [blame] | 146 | std::unique_ptr<InputProcessorInterface> mProcessor; | 
| Siarhei Vishniakou | 473174e | 2017-12-27 16:44:42 -0800 | [diff] [blame] | 147 |  | 
| Prabir Pradhan | addf8e9 | 2023-04-06 00:28:48 +0000 | [diff] [blame] | 148 | std::unique_ptr<InputDeviceMetricsCollectorInterface> mCollector; | 
|  | 149 |  | 
| Siarhei Vishniakou | 1805009 | 2021-09-01 13:32:49 -0700 | [diff] [blame] | 150 | std::unique_ptr<InputDispatcherInterface> mDispatcher; | 
| Prabir Pradhan | 44e6e83 | 2023-06-06 00:03:25 +0000 | [diff] [blame] | 151 |  | 
|  | 152 | std::shared_ptr<IInputFlingerRust> mInputFlingerRust; | 
| Prabir Pradhan | 274aa2c | 2023-08-18 17:27:07 +0000 | [diff] [blame] | 153 |  | 
|  | 154 | std::vector<std::unique_ptr<TracedInputListener>> mTracingStages; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 155 | }; | 
|  | 156 |  | 
|  | 157 | } // namespace android |