blob: 8aad35bf1e6af5ff055ef40e080b7ae9511a5911 [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
17#ifndef _UI_INPUT_MANAGER_H
18#define _UI_INPUT_MANAGER_H
19
20/**
21 * Native input manager.
22 */
23
Siarhei Vishniakou473174e2017-12-27 16:44:42 -080024#include "InputClassifier.h"
Garfield Tane84e6f92019-08-29 17:28:41 -070025#include "InputReaderBase.h"
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -070026#include "include/UnwantedInteractionBlockerInterface.h"
Michael Wrightd02c5b62014-02-10 15:10:22 -080027
Garfield Tane84e6f92019-08-29 17:28:41 -070028#include <InputDispatcherInterface.h>
29#include <InputDispatcherPolicyInterface.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080030#include <input/Input.h>
31#include <input/InputTransport.h>
Robert Carr1cc78672018-07-31 14:25:57 -070032
Chris Ye0783e992020-06-02 21:34:49 -070033#include <android/os/BnInputFlinger.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080034#include <utils/Errors.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080035#include <utils/RefBase.h>
Chris Ye0783e992020-06-02 21:34:49 -070036#include <utils/Timers.h>
Chris Ye0783e992020-06-02 21:34:49 -070037
38using android::os::BnInputFlinger;
Michael Wrightd02c5b62014-02-10 15:10:22 -080039
40namespace android {
Robert Carr1c4c5592018-09-24 13:18:43 -070041class InputChannel;
Chris Ye0783e992020-06-02 21:34:49 -070042class InputDispatcherThread;
Michael Wrightd02c5b62014-02-10 15:10:22 -080043
44/*
45 * The input manager is the core of the system event processing.
46 *
Michael Wright63534162020-07-02 14:38:16 +010047 * The input manager has three components.
Michael Wrightd02c5b62014-02-10 15:10:22 -080048 *
Prabir Pradhan28efc192019-11-05 01:10:04 +000049 * 1. The InputReader class starts a thread that reads and preprocesses raw input events, applies
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -070050 * policy, and posts messages to a queue managed by the UnwantedInteractionBlocker.
51 * 2. The UnwantedInteractionBlocker is responsible for removing unwanted interactions. For example,
52 * this could be a palm on the screen. This stage would alter the event stream to remove either
53 * partially (some of the pointers) or fully (all touches) the unwanted interaction. The events
54 * are processed on the InputReader thread, without any additional queue. The events are then
55 * posted to the queue managed by the InputClassifier.
56 * 3. The InputClassifier class starts a thread to communicate with the device-specific
57 * classifiers. It then waits on the queue of events from UnwantedInteractionBlocker, applies
58 * a classification to them, and queues them for the InputDispatcher.
59 * 4. The InputDispatcher class starts a thread that waits for new events on the
Michael Wright63534162020-07-02 14:38:16 +010060 * previous queue and asynchronously dispatches them to applications.
Michael Wrightd02c5b62014-02-10 15:10:22 -080061 *
Michael Wright63534162020-07-02 14:38:16 +010062 * By design, none of these classes share any internal state. Moreover, all communication is
63 * done one way from the InputReader to the InputDispatcher and never the reverse. All
64 * classes may interact with the InputDispatchPolicy, however.
Michael Wrightd02c5b62014-02-10 15:10:22 -080065 *
66 * The InputManager class never makes any calls into Java itself. Instead, the
67 * InputDispatchPolicy is responsible for performing all external interactions with the
68 * system, including calling DVM services.
69 */
70class InputManagerInterface : public virtual RefBase {
71protected:
72 InputManagerInterface() { }
73 virtual ~InputManagerInterface() { }
74
75public:
Prabir Pradhan3608aad2019-10-02 17:08:26 -070076 /* Starts the input threads. */
Michael Wrightd02c5b62014-02-10 15:10:22 -080077 virtual status_t start() = 0;
78
Prabir Pradhan3608aad2019-10-02 17:08:26 -070079 /* Stops the input threads and waits for them to exit. */
Michael Wrightd02c5b62014-02-10 15:10:22 -080080 virtual status_t stop() = 0;
81
82 /* Gets the input reader. */
Siarhei Vishniakou18050092021-09-01 13:32:49 -070083 virtual InputReaderInterface& getReader() = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -080084
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -070085 /* Gets the unwanted interaction blocker. */
86 virtual UnwantedInteractionBlockerInterface& getUnwantedInteractionBlocker() = 0;
87
Michael Wright63534162020-07-02 14:38:16 +010088 /* Gets the input classifier */
Siarhei Vishniakou18050092021-09-01 13:32:49 -070089 virtual InputClassifierInterface& getClassifier() = 0;
Michael Wright63534162020-07-02 14:38:16 +010090
Michael Wrightd02c5b62014-02-10 15:10:22 -080091 /* Gets the input dispatcher. */
Siarhei Vishniakou18050092021-09-01 13:32:49 -070092 virtual InputDispatcherInterface& getDispatcher() = 0;
Siarhei Vishniakou9f330c52022-05-17 05:03:42 -070093
94 /* Check that the input stages have not deadlocked. */
95 virtual void monitor() = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -080096};
97
Robert Carr1cc78672018-07-31 14:25:57 -070098class InputManager : public InputManagerInterface, public BnInputFlinger {
Michael Wrightd02c5b62014-02-10 15:10:22 -080099protected:
Michael Wright63534162020-07-02 14:38:16 +0100100 ~InputManager() override;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800101
102public:
103 InputManager(
Michael Wrightd02c5b62014-02-10 15:10:22 -0800104 const sp<InputReaderPolicyInterface>& readerPolicy,
105 const sp<InputDispatcherPolicyInterface>& dispatcherPolicy);
106
Michael Wright63534162020-07-02 14:38:16 +0100107 status_t start() override;
108 status_t stop() override;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800109
Siarhei Vishniakou18050092021-09-01 13:32:49 -0700110 InputReaderInterface& getReader() override;
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700111 UnwantedInteractionBlockerInterface& getUnwantedInteractionBlocker() override;
Siarhei Vishniakou18050092021-09-01 13:32:49 -0700112 InputClassifierInterface& getClassifier() override;
113 InputDispatcherInterface& getDispatcher() override;
Siarhei Vishniakou9f330c52022-05-17 05:03:42 -0700114 void monitor() override;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800115
Chris Ye0783e992020-06-02 21:34:49 -0700116 status_t dump(int fd, const Vector<String16>& args) override;
Garfield Tan15601662020-09-22 15:32:38 -0700117 binder::Status createInputChannel(const std::string& name, InputChannel* outChannel) override;
118 binder::Status removeInputChannel(const sp<IBinder>& connectionToken) override;
chaviw3277faf2021-05-19 16:45:23 -0500119 binder::Status setFocusedWindow(const gui::FocusRequest&) override;
Siarhei Vishniakouc9ac19e2020-03-19 11:55:01 -0700120
Michael Wrightd02c5b62014-02-10 15:10:22 -0800121private:
Siarhei Vishniakou18050092021-09-01 13:32:49 -0700122 std::unique_ptr<InputReaderInterface> mReader;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800123
Siarhei Vishniakou9f330c52022-05-17 05:03:42 -0700124 std::unique_ptr<UnwantedInteractionBlockerInterface> mBlocker;
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700125
Siarhei Vishniakou18050092021-09-01 13:32:49 -0700126 std::unique_ptr<InputClassifierInterface> mClassifier;
Siarhei Vishniakou473174e2017-12-27 16:44:42 -0800127
Siarhei Vishniakou18050092021-09-01 13:32:49 -0700128 std::unique_ptr<InputDispatcherInterface> mDispatcher;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800129};
130
131} // namespace android
132
133#endif // _UI_INPUT_MANAGER_H