blob: 035a9a32f74af546e20d2121460dd654568ca997 [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>
Chris Ye0783e992020-06-02 21:34:49 -070029#include <android/os/ISetInputWindowsListener.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>
34#include <android/os/IInputFlinger.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080035#include <utils/Errors.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080036#include <utils/RefBase.h>
Chris Ye0783e992020-06-02 21:34:49 -070037#include <utils/Timers.h>
38#include <utils/Vector.h>
39
40using android::os::BnInputFlinger;
41using android::os::ISetInputWindowsListener;
Michael Wrightd02c5b62014-02-10 15:10:22 -080042
43namespace android {
Robert Carr1c4c5592018-09-24 13:18:43 -070044class InputChannel;
Chris Ye0783e992020-06-02 21:34:49 -070045class InputDispatcherThread;
Michael Wrightd02c5b62014-02-10 15:10:22 -080046
47/*
48 * The input manager is the core of the system event processing.
49 *
Michael Wright63534162020-07-02 14:38:16 +010050 * The input manager has three components.
Michael Wrightd02c5b62014-02-10 15:10:22 -080051 *
Prabir Pradhan28efc192019-11-05 01:10:04 +000052 * 1. The InputReader class starts a thread that reads and preprocesses raw input events, applies
Michael Wright63534162020-07-02 14:38:16 +010053 * policy, and posts messages to a queue managed by the InputClassifier.
54 * 2. The InputClassifier class starts a thread to communicate with the device-specific
55 * classifiers. It then waits on the queue of events from InputReader, applies a classification
56 * to them, and queues them for the InputDispatcher.
57 * 3. The InputDispatcher class starts a thread that waits for new events on the
58 * previous queue and asynchronously dispatches them to applications.
Michael Wrightd02c5b62014-02-10 15:10:22 -080059 *
Michael Wright63534162020-07-02 14:38:16 +010060 * By design, none of these classes share any internal state. Moreover, all communication is
61 * done one way from the InputReader to the InputDispatcher and never the reverse. All
62 * classes may interact with the InputDispatchPolicy, however.
Michael Wrightd02c5b62014-02-10 15:10:22 -080063 *
64 * The InputManager class never makes any calls into Java itself. Instead, the
65 * InputDispatchPolicy is responsible for performing all external interactions with the
66 * system, including calling DVM services.
67 */
68class InputManagerInterface : public virtual RefBase {
69protected:
70 InputManagerInterface() { }
71 virtual ~InputManagerInterface() { }
72
73public:
Prabir Pradhan3608aad2019-10-02 17:08:26 -070074 /* Starts the input threads. */
Michael Wrightd02c5b62014-02-10 15:10:22 -080075 virtual status_t start() = 0;
76
Prabir Pradhan3608aad2019-10-02 17:08:26 -070077 /* Stops the input threads and waits for them to exit. */
Michael Wrightd02c5b62014-02-10 15:10:22 -080078 virtual status_t stop() = 0;
79
80 /* Gets the input reader. */
81 virtual sp<InputReaderInterface> getReader() = 0;
82
Michael Wright63534162020-07-02 14:38:16 +010083 /* Gets the input classifier */
84 virtual sp<InputClassifierInterface> getClassifier() = 0;
85
Michael Wrightd02c5b62014-02-10 15:10:22 -080086 /* Gets the input dispatcher. */
87 virtual sp<InputDispatcherInterface> getDispatcher() = 0;
88};
89
Robert Carr1cc78672018-07-31 14:25:57 -070090class InputManager : public InputManagerInterface, public BnInputFlinger {
Michael Wrightd02c5b62014-02-10 15:10:22 -080091protected:
Michael Wright63534162020-07-02 14:38:16 +010092 ~InputManager() override;
Michael Wrightd02c5b62014-02-10 15:10:22 -080093
94public:
95 InputManager(
Michael Wrightd02c5b62014-02-10 15:10:22 -080096 const sp<InputReaderPolicyInterface>& readerPolicy,
97 const sp<InputDispatcherPolicyInterface>& dispatcherPolicy);
98
Michael Wright63534162020-07-02 14:38:16 +010099 status_t start() override;
100 status_t stop() override;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800101
Michael Wright63534162020-07-02 14:38:16 +0100102 sp<InputReaderInterface> getReader() override;
103 sp<InputClassifierInterface> getClassifier() override;
104 sp<InputDispatcherInterface> getDispatcher() override;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800105
Chris Ye0783e992020-06-02 21:34:49 -0700106 status_t dump(int fd, const Vector<String16>& args) override;
107 binder::Status setInputWindows(
chaviw3277faf2021-05-19 16:45:23 -0500108 const std::vector<gui::WindowInfo>& handles,
Chris Ye0783e992020-06-02 21:34:49 -0700109 const sp<ISetInputWindowsListener>& setInputWindowsListener) override;
Robert Carr1cc78672018-07-31 14:25:57 -0700110
Garfield Tan15601662020-09-22 15:32:38 -0700111 binder::Status createInputChannel(const std::string& name, InputChannel* outChannel) override;
112 binder::Status removeInputChannel(const sp<IBinder>& connectionToken) override;
chaviw3277faf2021-05-19 16:45:23 -0500113 binder::Status setFocusedWindow(const gui::FocusRequest&) override;
Siarhei Vishniakouc9ac19e2020-03-19 11:55:01 -0700114
Michael Wrightd02c5b62014-02-10 15:10:22 -0800115private:
116 sp<InputReaderInterface> mReader;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800117
Siarhei Vishniakou473174e2017-12-27 16:44:42 -0800118 sp<InputClassifierInterface> mClassifier;
119
Michael Wrightd02c5b62014-02-10 15:10:22 -0800120 sp<InputDispatcherInterface> mDispatcher;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800121};
122
123} // namespace android
124
125#endif // _UI_INPUT_MANAGER_H