blob: 41d94781476dd102033decd1e4c777241bc41be4 [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>
29#include <input/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
33#include <input/IInputFlinger.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080034#include <utils/Errors.h>
35#include <utils/Vector.h>
36#include <utils/Timers.h>
37#include <utils/RefBase.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080038
39namespace android {
Robert Carr1c4c5592018-09-24 13:18:43 -070040class InputChannel;
Michael Wrightd02c5b62014-02-10 15:10:22 -080041
42/*
43 * The input manager is the core of the system event processing.
44 *
Michael Wright63534162020-07-02 14:38:16 +010045 * The input manager has three components.
Michael Wrightd02c5b62014-02-10 15:10:22 -080046 *
Prabir Pradhan28efc192019-11-05 01:10:04 +000047 * 1. The InputReader class starts a thread that reads and preprocesses raw input events, applies
Michael Wright63534162020-07-02 14:38:16 +010048 * policy, and posts messages to a queue managed by the InputClassifier.
49 * 2. The InputClassifier class starts a thread to communicate with the device-specific
50 * classifiers. It then waits on the queue of events from InputReader, applies a classification
51 * to them, and queues them for the InputDispatcher.
52 * 3. The InputDispatcher class starts a thread that waits for new events on the
53 * previous queue and asynchronously dispatches them to applications.
Michael Wrightd02c5b62014-02-10 15:10:22 -080054 *
Michael Wright63534162020-07-02 14:38:16 +010055 * By design, none of these classes share any internal state. Moreover, all communication is
56 * done one way from the InputReader to the InputDispatcher and never the reverse. All
57 * classes may interact with the InputDispatchPolicy, however.
Michael Wrightd02c5b62014-02-10 15:10:22 -080058 *
59 * The InputManager class never makes any calls into Java itself. Instead, the
60 * InputDispatchPolicy is responsible for performing all external interactions with the
61 * system, including calling DVM services.
62 */
63class InputManagerInterface : public virtual RefBase {
64protected:
65 InputManagerInterface() { }
66 virtual ~InputManagerInterface() { }
67
68public:
Prabir Pradhan3608aad2019-10-02 17:08:26 -070069 /* Starts the input threads. */
Michael Wrightd02c5b62014-02-10 15:10:22 -080070 virtual status_t start() = 0;
71
Prabir Pradhan3608aad2019-10-02 17:08:26 -070072 /* Stops the input threads and waits for them to exit. */
Michael Wrightd02c5b62014-02-10 15:10:22 -080073 virtual status_t stop() = 0;
74
75 /* Gets the input reader. */
76 virtual sp<InputReaderInterface> getReader() = 0;
77
Michael Wright63534162020-07-02 14:38:16 +010078 /* Gets the input classifier */
79 virtual sp<InputClassifierInterface> getClassifier() = 0;
80
Michael Wrightd02c5b62014-02-10 15:10:22 -080081 /* Gets the input dispatcher. */
82 virtual sp<InputDispatcherInterface> getDispatcher() = 0;
83};
84
Robert Carr1cc78672018-07-31 14:25:57 -070085class InputManager : public InputManagerInterface, public BnInputFlinger {
Michael Wrightd02c5b62014-02-10 15:10:22 -080086protected:
Michael Wright63534162020-07-02 14:38:16 +010087 ~InputManager() override;
Michael Wrightd02c5b62014-02-10 15:10:22 -080088
89public:
90 InputManager(
Michael Wrightd02c5b62014-02-10 15:10:22 -080091 const sp<InputReaderPolicyInterface>& readerPolicy,
92 const sp<InputDispatcherPolicyInterface>& dispatcherPolicy);
93
Michael Wright63534162020-07-02 14:38:16 +010094 status_t start() override;
95 status_t stop() override;
Michael Wrightd02c5b62014-02-10 15:10:22 -080096
Michael Wright63534162020-07-02 14:38:16 +010097 sp<InputReaderInterface> getReader() override;
98 sp<InputClassifierInterface> getClassifier() override;
99 sp<InputDispatcherInterface> getDispatcher() override;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800100
Michael Wright63534162020-07-02 14:38:16 +0100101 void setInputWindows(const std::vector<InputWindowInfo>& handles,
102 const sp<ISetInputWindowsListener>& setInputWindowsListener) override;
Robert Carr1cc78672018-07-31 14:25:57 -0700103
Michael Wright63534162020-07-02 14:38:16 +0100104 void registerInputChannel(const sp<InputChannel>& channel) override;
105 void unregisterInputChannel(const sp<InputChannel>& channel) override;
Siarhei Vishniakouc9ac19e2020-03-19 11:55:01 -0700106
Michael Wrightd02c5b62014-02-10 15:10:22 -0800107private:
108 sp<InputReaderInterface> mReader;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800109
Siarhei Vishniakou473174e2017-12-27 16:44:42 -0800110 sp<InputClassifierInterface> mClassifier;
111
Michael Wrightd02c5b62014-02-10 15:10:22 -0800112 sp<InputDispatcherInterface> mDispatcher;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800113};
114
115} // namespace android
116
117#endif // _UI_INPUT_MANAGER_H