blob: ff9a0800da30b164c23554615c444369e890b8d0 [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
24#include "EventHub.h"
Prabir Pradhan29c95332018-11-14 20:14:11 -080025#include "InputReaderBase.h"
Siarhei Vishniakou473174e2017-12-27 16:44:42 -080026#include "InputClassifier.h"
Michael Wrightd02c5b62014-02-10 15:10:22 -080027#include "InputDispatcher.h"
Siarhei Vishniakou473174e2017-12-27 16:44:42 -080028#include "InputReader.h"
Michael Wrightd02c5b62014-02-10 15:10:22 -080029
30#include <input/Input.h>
31#include <input/InputTransport.h>
chaviw291d88a2019-02-14 10:33:58 -080032#include <input/ISetInputWindowsListener.h>
Robert Carr1cc78672018-07-31 14:25:57 -070033
34#include <input/IInputFlinger.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080035#include <utils/Errors.h>
36#include <utils/Vector.h>
37#include <utils/Timers.h>
38#include <utils/RefBase.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080039
40namespace android {
Robert Carr1c4c5592018-09-24 13:18:43 -070041class InputChannel;
Michael Wrightd02c5b62014-02-10 15:10:22 -080042
43/*
44 * The input manager is the core of the system event processing.
45 *
46 * The input manager uses two threads.
47 *
48 * 1. The InputReaderThread (called "InputReader") reads and preprocesses raw input events,
49 * applies policy, and posts messages to a queue managed by the DispatcherThread.
50 * 2. The InputDispatcherThread (called "InputDispatcher") thread waits for new events on the
51 * queue and asynchronously dispatches them to applications.
52 *
53 * By design, the InputReaderThread class and InputDispatcherThread class do not share any
54 * internal state. Moreover, all communication is done one way from the InputReaderThread
55 * 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:
68 /* Starts the input manager threads. */
69 virtual status_t start() = 0;
70
71 /* Stops the input manager threads and waits for them to exit. */
72 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
chaviw291d88a2019-02-14 10:33:58 -080097 virtual void setInputWindows(const Vector<InputWindowInfo>& handles,
98 const sp<ISetInputWindowsListener>& setInputWindowsListener);
chaviwfbe5d9c2018-12-26 12:23:37 -080099 virtual void transferTouchFocus(const sp<IBinder>& fromToken, const sp<IBinder>& toToken);
Robert Carr1cc78672018-07-31 14:25:57 -0700100
Robert Carr1c4c5592018-09-24 13:18:43 -0700101 virtual void registerInputChannel(const sp<InputChannel>& channel);
102 virtual void unregisterInputChannel(const sp<InputChannel>& channel);
103
Michael Wrightd02c5b62014-02-10 15:10:22 -0800104private:
105 sp<InputReaderInterface> mReader;
106 sp<InputReaderThread> mReaderThread;
107
Siarhei Vishniakou473174e2017-12-27 16:44:42 -0800108 sp<InputClassifierInterface> mClassifier;
109
Michael Wrightd02c5b62014-02-10 15:10:22 -0800110 sp<InputDispatcherInterface> mDispatcher;
111 sp<InputDispatcherThread> mDispatcherThread;
112
113 void initialize();
114};
115
116} // namespace android
117
118#endif // _UI_INPUT_MANAGER_H