blob: c479aaf9b6492330deeb263fa4f12a521604be2d [file] [log] [blame]
Michael Wrightd02c5b62014-02-10 15:10:22 -08001/*
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 Pradhan48108662022-09-09 21:22:04 +000017#pragma once
Michael Wrightd02c5b62014-02-10 15:10:22 -080018
19/**
20 * Native input manager.
21 */
22
Prabir Pradhanaddf8e92023-04-06 00:28:48 +000023#include "InputDeviceMetricsCollector.h"
Vaibhav Devmurari5766aee2023-11-03 17:21:25 +000024#include "InputFilter.h"
Siarhei Vishniakou98996032022-08-03 11:54:47 -070025#include "InputProcessor.h"
Garfield Tane84e6f92019-08-29 17:28:41 -070026#include "InputReaderBase.h"
Prabir Pradhanb56e92c2023-06-09 23:40:37 +000027#include "PointerChoreographer.h"
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -070028#include "include/UnwantedInteractionBlockerInterface.h"
Michael Wrightd02c5b62014-02-10 15:10:22 -080029
Garfield Tane84e6f92019-08-29 17:28:41 -070030#include <InputDispatcherInterface.h>
31#include <InputDispatcherPolicyInterface.h>
Vaibhav Devmurarie948d4b2023-12-28 13:41:32 +000032#include <InputFilterPolicyInterface.h>
Prabir Pradhanb56e92c2023-06-09 23:40:37 +000033#include <PointerChoreographerPolicyInterface.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080034#include <input/Input.h>
35#include <input/InputTransport.h>
Robert Carr1cc78672018-07-31 14:25:57 -070036
Prabir Pradhan44e6e832023-06-06 00:03:25 +000037#include <aidl/com/android/server/inputflinger/IInputFlingerRust.h>
Chris Ye0783e992020-06-02 21:34:49 -070038#include <android/os/BnInputFlinger.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080039#include <utils/Errors.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080040#include <utils/RefBase.h>
Chris Ye0783e992020-06-02 21:34:49 -070041#include <utils/Timers.h>
Chris Ye0783e992020-06-02 21:34:49 -070042
43using android::os::BnInputFlinger;
Michael Wrightd02c5b62014-02-10 15:10:22 -080044
Vaibhav Devmurari5766aee2023-11-03 17:21:25 +000045using aidl::com::android::server::inputflinger::IInputFilter;
Prabir Pradhan44e6e832023-06-06 00:03:25 +000046using aidl::com::android::server::inputflinger::IInputFlingerRust;
47
Michael Wrightd02c5b62014-02-10 15:10:22 -080048namespace android {
Robert Carr1c4c5592018-09-24 13:18:43 -070049class InputChannel;
Chris Ye0783e992020-06-02 21:34:49 -070050class InputDispatcherThread;
Michael Wrightd02c5b62014-02-10 15:10:22 -080051
52/*
53 * The input manager is the core of the system event processing.
54 *
Michael Wright63534162020-07-02 14:38:16 +010055 * The input manager has three components.
Michael Wrightd02c5b62014-02-10 15:10:22 -080056 *
Prabir Pradhan28efc192019-11-05 01:10:04 +000057 * 1. The InputReader class starts a thread that reads and preprocesses raw input events, applies
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -070058 * policy, and posts messages to a queue managed by the UnwantedInteractionBlocker.
59 * 2. The UnwantedInteractionBlocker is responsible for removing unwanted interactions. For example,
60 * this could be a palm on the screen. This stage would alter the event stream to remove either
61 * partially (some of the pointers) or fully (all touches) the unwanted interaction. The events
62 * are processed on the InputReader thread, without any additional queue. The events are then
Siarhei Vishniakou98996032022-08-03 11:54:47 -070063 * posted to the queue managed by the InputProcessor.
64 * 3. The InputProcessor class starts a thread to communicate with the device-specific
65 * IInputProcessor HAL. It then waits on the queue of events from UnwantedInteractionBlocker,
66 * processes the events (for example, applies a classification to the events), and queues them
67 * for the InputDispatcher.
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -070068 * 4. The InputDispatcher class starts a thread that waits for new events on the
Michael Wright63534162020-07-02 14:38:16 +010069 * previous queue and asynchronously dispatches them to applications.
Michael Wrightd02c5b62014-02-10 15:10:22 -080070 *
Michael Wright63534162020-07-02 14:38:16 +010071 * By design, none of these classes share any internal state. Moreover, all communication is
72 * done one way from the InputReader to the InputDispatcher and never the reverse. All
73 * classes may interact with the InputDispatchPolicy, however.
Michael Wrightd02c5b62014-02-10 15:10:22 -080074 *
75 * The InputManager class never makes any calls into Java itself. Instead, the
76 * InputDispatchPolicy is responsible for performing all external interactions with the
77 * system, including calling DVM services.
78 */
79class InputManagerInterface : public virtual RefBase {
80protected:
81 InputManagerInterface() { }
82 virtual ~InputManagerInterface() { }
83
84public:
Prabir Pradhan3608aad2019-10-02 17:08:26 -070085 /* Starts the input threads. */
Michael Wrightd02c5b62014-02-10 15:10:22 -080086 virtual status_t start() = 0;
87
Prabir Pradhan3608aad2019-10-02 17:08:26 -070088 /* Stops the input threads and waits for them to exit. */
Michael Wrightd02c5b62014-02-10 15:10:22 -080089 virtual status_t stop() = 0;
90
91 /* Gets the input reader. */
Siarhei Vishniakou18050092021-09-01 13:32:49 -070092 virtual InputReaderInterface& getReader() = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -080093
Prabir Pradhanb56e92c2023-06-09 23:40:37 +000094 /* Gets the PointerChoreographer. */
95 virtual PointerChoreographerInterface& getChoreographer() = 0;
96
Prabir Pradhanaddf8e92023-04-06 00:28:48 +000097 /* Gets the input processor. */
Siarhei Vishniakou98996032022-08-03 11:54:47 -070098 virtual InputProcessorInterface& getProcessor() = 0;
Michael Wright63534162020-07-02 14:38:16 +010099
Prabir Pradhan8ede1d12023-05-08 19:37:44 +0000100 /* Gets the metrics collector. */
101 virtual InputDeviceMetricsCollectorInterface& getMetricsCollector() = 0;
102
Michael Wrightd02c5b62014-02-10 15:10:22 -0800103 /* Gets the input dispatcher. */
Siarhei Vishniakou18050092021-09-01 13:32:49 -0700104 virtual InputDispatcherInterface& getDispatcher() = 0;
Siarhei Vishniakou9f330c52022-05-17 05:03:42 -0700105
Vaibhav Devmurari953e6a42023-11-21 18:24:19 +0000106 /* Gets the input filter */
107 virtual InputFilterInterface& getInputFilter() = 0;
108
Siarhei Vishniakou9f330c52022-05-17 05:03:42 -0700109 /* Check that the input stages have not deadlocked. */
110 virtual void monitor() = 0;
Prabir Pradhan370dbc92023-04-06 00:02:05 +0000111
112 /* Dump the state of the components controlled by the input manager. */
113 virtual void dump(std::string& dump) = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800114};
115
Robert Carr1cc78672018-07-31 14:25:57 -0700116class InputManager : public InputManagerInterface, public BnInputFlinger {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800117protected:
Michael Wright63534162020-07-02 14:38:16 +0100118 ~InputManager() override;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800119
120public:
Prabir Pradhana41d2442023-04-20 21:30:40 +0000121 InputManager(const sp<InputReaderPolicyInterface>& readerPolicy,
Prabir Pradhanb56e92c2023-06-09 23:40:37 +0000122 InputDispatcherPolicyInterface& dispatcherPolicy,
Vaibhav Devmurarie948d4b2023-12-28 13:41:32 +0000123 PointerChoreographerPolicyInterface& choreographerPolicy,
124 InputFilterPolicyInterface& inputFilterPolicy);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800125
Michael Wright63534162020-07-02 14:38:16 +0100126 status_t start() override;
127 status_t stop() override;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800128
Siarhei Vishniakou18050092021-09-01 13:32:49 -0700129 InputReaderInterface& getReader() override;
Prabir Pradhanb56e92c2023-06-09 23:40:37 +0000130 PointerChoreographerInterface& getChoreographer() override;
Siarhei Vishniakou98996032022-08-03 11:54:47 -0700131 InputProcessorInterface& getProcessor() override;
Prabir Pradhan8ede1d12023-05-08 19:37:44 +0000132 InputDeviceMetricsCollectorInterface& getMetricsCollector() override;
Siarhei Vishniakou18050092021-09-01 13:32:49 -0700133 InputDispatcherInterface& getDispatcher() override;
Vaibhav Devmurari953e6a42023-11-21 18:24:19 +0000134 InputFilterInterface& getInputFilter() override;
Siarhei Vishniakou9f330c52022-05-17 05:03:42 -0700135 void monitor() override;
Prabir Pradhan370dbc92023-04-06 00:02:05 +0000136 void dump(std::string& dump) override;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800137
Chris Ye0783e992020-06-02 21:34:49 -0700138 status_t dump(int fd, const Vector<String16>& args) override;
Siarhei Vishniakou8d660132024-01-11 16:48:44 -0800139 binder::Status createInputChannel(const std::string& name,
140 android::os::InputChannelCore* outChannel) override;
Garfield Tan15601662020-09-22 15:32:38 -0700141 binder::Status removeInputChannel(const sp<IBinder>& connectionToken) override;
chaviw3277faf2021-05-19 16:45:23 -0500142 binder::Status setFocusedWindow(const gui::FocusRequest&) override;
Siarhei Vishniakouc9ac19e2020-03-19 11:55:01 -0700143
Michael Wrightd02c5b62014-02-10 15:10:22 -0800144private:
Siarhei Vishniakou18050092021-09-01 13:32:49 -0700145 std::unique_ptr<InputReaderInterface> mReader;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800146
Siarhei Vishniakou9f330c52022-05-17 05:03:42 -0700147 std::unique_ptr<UnwantedInteractionBlockerInterface> mBlocker;
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700148
Vaibhav Devmurari5766aee2023-11-03 17:21:25 +0000149 std::unique_ptr<InputFilterInterface> mInputFilter;
150
Prabir Pradhanb56e92c2023-06-09 23:40:37 +0000151 std::unique_ptr<PointerChoreographerInterface> mChoreographer;
152
Siarhei Vishniakou98996032022-08-03 11:54:47 -0700153 std::unique_ptr<InputProcessorInterface> mProcessor;
Siarhei Vishniakou473174e2017-12-27 16:44:42 -0800154
Prabir Pradhanaddf8e92023-04-06 00:28:48 +0000155 std::unique_ptr<InputDeviceMetricsCollectorInterface> mCollector;
156
Siarhei Vishniakou18050092021-09-01 13:32:49 -0700157 std::unique_ptr<InputDispatcherInterface> mDispatcher;
Prabir Pradhan44e6e832023-06-06 00:03:25 +0000158
159 std::shared_ptr<IInputFlingerRust> mInputFlingerRust;
Prabir Pradhan274aa2c2023-08-18 17:27:07 +0000160
161 std::vector<std::unique_ptr<TracedInputListener>> mTracingStages;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800162};
163
164} // namespace android