blob: 0158441fd1e03af576d08b6d8e4f84e93ab834d7 [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;
Garfield Tane84e6f92019-08-29 17:28:41 -070041class InputDispatcherThread;
Michael Wrightd02c5b62014-02-10 15:10:22 -080042
43/*
44 * The input manager is the core of the system event processing.
45 *
Prabir Pradhan28efc192019-11-05 01:10:04 +000046 * The input manager has two 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
49 * policy, and posts messages to a queue managed by the InputDispatcherThread.
Prabir Pradhan3608aad2019-10-02 17:08:26 -070050 * 2. The InputDispatcher class starts a thread that waits for new events on the
Michael Wrightd02c5b62014-02-10 15:10:22 -080051 * queue and asynchronously dispatches them to applications.
52 *
Prabir Pradhan3608aad2019-10-02 17:08:26 -070053 * By design, the InputReader class and InputDispatcher class do not share any
Prabir Pradhan28efc192019-11-05 01:10:04 +000054 * internal state. Moreover, all communication is done one way from the InputReader
Michael Wrightd02c5b62014-02-10 15:10:22 -080055 * into the InputDispatcherThread and never the reverse. Both classes may interact with the
56 * InputDispatchPolicy, however.
57 *
58 * The InputManager class never makes any calls into Java itself. Instead, the
59 * InputDispatchPolicy is responsible for performing all external interactions with the
60 * system, including calling DVM services.
61 */
62class InputManagerInterface : public virtual RefBase {
63protected:
64 InputManagerInterface() { }
65 virtual ~InputManagerInterface() { }
66
67public:
Prabir Pradhan3608aad2019-10-02 17:08:26 -070068 /* Starts the input threads. */
Michael Wrightd02c5b62014-02-10 15:10:22 -080069 virtual status_t start() = 0;
70
Prabir Pradhan3608aad2019-10-02 17:08:26 -070071 /* Stops the input threads and waits for them to exit. */
Michael Wrightd02c5b62014-02-10 15:10:22 -080072 virtual status_t stop() = 0;
73
74 /* Gets the input reader. */
75 virtual sp<InputReaderInterface> getReader() = 0;
76
77 /* Gets the input dispatcher. */
78 virtual sp<InputDispatcherInterface> getDispatcher() = 0;
79};
80
Robert Carr1cc78672018-07-31 14:25:57 -070081class InputManager : public InputManagerInterface, public BnInputFlinger {
Michael Wrightd02c5b62014-02-10 15:10:22 -080082protected:
83 virtual ~InputManager();
84
85public:
86 InputManager(
Michael Wrightd02c5b62014-02-10 15:10:22 -080087 const sp<InputReaderPolicyInterface>& readerPolicy,
88 const sp<InputDispatcherPolicyInterface>& dispatcherPolicy);
89
Michael Wrightd02c5b62014-02-10 15:10:22 -080090 virtual status_t start();
91 virtual status_t stop();
92
93 virtual sp<InputReaderInterface> getReader();
Siarhei Vishniakoua028c442019-02-04 14:33:23 -080094 virtual sp<InputClassifierInterface> getClassifier();
Michael Wrightd02c5b62014-02-10 15:10:22 -080095 virtual sp<InputDispatcherInterface> getDispatcher();
96
Arthur Hung7c3ae9c2019-03-11 11:23:03 +080097 virtual void setInputWindows(const std::vector<InputWindowInfo>& handles,
chaviw291d88a2019-02-14 10:33:58 -080098 const sp<ISetInputWindowsListener>& setInputWindowsListener);
Robert Carr1cc78672018-07-31 14:25:57 -070099
Robert Carr1c4c5592018-09-24 13:18:43 -0700100 virtual void registerInputChannel(const sp<InputChannel>& channel);
101 virtual void unregisterInputChannel(const sp<InputChannel>& channel);
102
Siarhei Vishniakouc9ac19e2020-03-19 11:55:01 -0700103 void setMotionClassifierEnabled(bool enabled);
104
Michael Wrightd02c5b62014-02-10 15:10:22 -0800105private:
106 sp<InputReaderInterface> mReader;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800107
Siarhei Vishniakou473174e2017-12-27 16:44:42 -0800108 sp<InputClassifierInterface> mClassifier;
109
Michael Wrightd02c5b62014-02-10 15:10:22 -0800110 sp<InputDispatcherInterface> mDispatcher;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800111};
112
113} // namespace android
114
115#endif // _UI_INPUT_MANAGER_H