blob: e00028364a823fdf6463a75cb8931613a71a1c59 [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"
Michael Wrightd02c5b62014-02-10 15:10:22 -080026
Garfield Tane84e6f92019-08-29 17:28:41 -070027#include <InputDispatcherInterface.h>
28#include <InputDispatcherPolicyInterface.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080029#include <input/Input.h>
30#include <input/InputTransport.h>
Robert Carr1cc78672018-07-31 14:25:57 -070031
Chris Ye0783e992020-06-02 21:34:49 -070032#include <android/os/BnInputFlinger.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080033#include <utils/Errors.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080034#include <utils/RefBase.h>
Chris Ye0783e992020-06-02 21:34:49 -070035#include <utils/Timers.h>
Chris Ye0783e992020-06-02 21:34:49 -070036
37using android::os::BnInputFlinger;
Michael Wrightd02c5b62014-02-10 15:10:22 -080038
39namespace android {
Robert Carr1c4c5592018-09-24 13:18:43 -070040class InputChannel;
Chris Ye0783e992020-06-02 21:34:49 -070041class InputDispatcherThread;
Michael Wrightd02c5b62014-02-10 15:10:22 -080042
43/*
44 * The input manager is the core of the system event processing.
45 *
Michael Wright63534162020-07-02 14:38:16 +010046 * The input manager has three components.
Michael Wrightd02c5b62014-02-10 15:10:22 -080047 *
Prabir Pradhan28efc192019-11-05 01:10:04 +000048 * 1. The InputReader class starts a thread that reads and preprocesses raw input events, applies
Michael Wright63534162020-07-02 14:38:16 +010049 * policy, and posts messages to a queue managed by the InputClassifier.
50 * 2. The InputClassifier class starts a thread to communicate with the device-specific
51 * classifiers. It then waits on the queue of events from InputReader, applies a classification
52 * to them, and queues them for the InputDispatcher.
53 * 3. The InputDispatcher class starts a thread that waits for new events on the
54 * previous queue and asynchronously dispatches them to applications.
Michael Wrightd02c5b62014-02-10 15:10:22 -080055 *
Michael Wright63534162020-07-02 14:38:16 +010056 * By design, none of these classes share any internal state. Moreover, all communication is
57 * done one way from the InputReader to the InputDispatcher and never the reverse. All
58 * classes may interact with the InputDispatchPolicy, however.
Michael Wrightd02c5b62014-02-10 15:10:22 -080059 *
60 * The InputManager class never makes any calls into Java itself. Instead, the
61 * InputDispatchPolicy is responsible for performing all external interactions with the
62 * system, including calling DVM services.
63 */
64class InputManagerInterface : public virtual RefBase {
65protected:
66 InputManagerInterface() { }
67 virtual ~InputManagerInterface() { }
68
69public:
Prabir Pradhan3608aad2019-10-02 17:08:26 -070070 /* Starts the input threads. */
Michael Wrightd02c5b62014-02-10 15:10:22 -080071 virtual status_t start() = 0;
72
Prabir Pradhan3608aad2019-10-02 17:08:26 -070073 /* Stops the input threads and waits for them to exit. */
Michael Wrightd02c5b62014-02-10 15:10:22 -080074 virtual status_t stop() = 0;
75
76 /* Gets the input reader. */
Siarhei Vishniakou18050092021-09-01 13:32:49 -070077 virtual InputReaderInterface& getReader() = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -080078
Michael Wright63534162020-07-02 14:38:16 +010079 /* Gets the input classifier */
Siarhei Vishniakou18050092021-09-01 13:32:49 -070080 virtual InputClassifierInterface& getClassifier() = 0;
Michael Wright63534162020-07-02 14:38:16 +010081
Michael Wrightd02c5b62014-02-10 15:10:22 -080082 /* Gets the input dispatcher. */
Siarhei Vishniakou18050092021-09-01 13:32:49 -070083 virtual InputDispatcherInterface& getDispatcher() = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -080084};
85
Robert Carr1cc78672018-07-31 14:25:57 -070086class InputManager : public InputManagerInterface, public BnInputFlinger {
Michael Wrightd02c5b62014-02-10 15:10:22 -080087protected:
Michael Wright63534162020-07-02 14:38:16 +010088 ~InputManager() override;
Michael Wrightd02c5b62014-02-10 15:10:22 -080089
90public:
91 InputManager(
Michael Wrightd02c5b62014-02-10 15:10:22 -080092 const sp<InputReaderPolicyInterface>& readerPolicy,
93 const sp<InputDispatcherPolicyInterface>& dispatcherPolicy);
94
Michael Wright63534162020-07-02 14:38:16 +010095 status_t start() override;
96 status_t stop() override;
Michael Wrightd02c5b62014-02-10 15:10:22 -080097
Siarhei Vishniakou18050092021-09-01 13:32:49 -070098 InputReaderInterface& getReader() override;
99 InputClassifierInterface& getClassifier() override;
100 InputDispatcherInterface& getDispatcher() override;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800101
Chris Ye0783e992020-06-02 21:34:49 -0700102 status_t dump(int fd, const Vector<String16>& args) override;
Garfield Tan15601662020-09-22 15:32:38 -0700103 binder::Status createInputChannel(const std::string& name, InputChannel* outChannel) override;
104 binder::Status removeInputChannel(const sp<IBinder>& connectionToken) override;
chaviw3277faf2021-05-19 16:45:23 -0500105 binder::Status setFocusedWindow(const gui::FocusRequest&) override;
Siarhei Vishniakouc9ac19e2020-03-19 11:55:01 -0700106
Michael Wrightd02c5b62014-02-10 15:10:22 -0800107private:
Siarhei Vishniakou18050092021-09-01 13:32:49 -0700108 std::unique_ptr<InputReaderInterface> mReader;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800109
Siarhei Vishniakou18050092021-09-01 13:32:49 -0700110 std::unique_ptr<InputClassifierInterface> mClassifier;
Siarhei Vishniakou473174e2017-12-27 16:44:42 -0800111
Siarhei Vishniakou18050092021-09-01 13:32:49 -0700112 std::unique_ptr<InputDispatcherInterface> mDispatcher;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800113};
114
115} // namespace android
116
117#endif // _UI_INPUT_MANAGER_H