blob: 1173fa165f8fa82fc02ab22fd52f9ea8c5b52e25 [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"
Michael Wrightd02c5b62014-02-10 15:10:22 -080026#include "InputDispatcher.h"
27
28#include <input/Input.h>
29#include <input/InputTransport.h>
Robert Carr1cc78672018-07-31 14:25:57 -070030
31#include <input/IInputFlinger.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080032#include <utils/Errors.h>
33#include <utils/Vector.h>
34#include <utils/Timers.h>
35#include <utils/RefBase.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080036
37namespace android {
38
39/*
40 * The input manager is the core of the system event processing.
41 *
42 * The input manager uses two threads.
43 *
44 * 1. The InputReaderThread (called "InputReader") reads and preprocesses raw input events,
45 * applies policy, and posts messages to a queue managed by the DispatcherThread.
46 * 2. The InputDispatcherThread (called "InputDispatcher") thread waits for new events on the
47 * queue and asynchronously dispatches them to applications.
48 *
49 * By design, the InputReaderThread class and InputDispatcherThread class do not share any
50 * internal state. Moreover, all communication is done one way from the InputReaderThread
51 * into the InputDispatcherThread and never the reverse. Both classes may interact with the
52 * InputDispatchPolicy, however.
53 *
54 * The InputManager class never makes any calls into Java itself. Instead, the
55 * InputDispatchPolicy is responsible for performing all external interactions with the
56 * system, including calling DVM services.
57 */
58class InputManagerInterface : public virtual RefBase {
59protected:
60 InputManagerInterface() { }
61 virtual ~InputManagerInterface() { }
62
63public:
64 /* Starts the input manager threads. */
65 virtual status_t start() = 0;
66
67 /* Stops the input manager threads and waits for them to exit. */
68 virtual status_t stop() = 0;
69
70 /* Gets the input reader. */
71 virtual sp<InputReaderInterface> getReader() = 0;
72
73 /* Gets the input dispatcher. */
74 virtual sp<InputDispatcherInterface> getDispatcher() = 0;
75};
76
Robert Carr1cc78672018-07-31 14:25:57 -070077class InputManager : public InputManagerInterface, public BnInputFlinger {
Michael Wrightd02c5b62014-02-10 15:10:22 -080078protected:
79 virtual ~InputManager();
80
81public:
82 InputManager(
Michael Wrightd02c5b62014-02-10 15:10:22 -080083 const sp<InputReaderPolicyInterface>& readerPolicy,
84 const sp<InputDispatcherPolicyInterface>& dispatcherPolicy);
85
Michael Wrightd02c5b62014-02-10 15:10:22 -080086 virtual status_t start();
87 virtual status_t stop();
88
89 virtual sp<InputReaderInterface> getReader();
90 virtual sp<InputDispatcherInterface> getDispatcher();
91
Robert Carr1cc78672018-07-31 14:25:57 -070092 virtual void setInputWindows(const Vector<InputWindowInfo>& handles);
93
Michael Wrightd02c5b62014-02-10 15:10:22 -080094private:
95 sp<InputReaderInterface> mReader;
96 sp<InputReaderThread> mReaderThread;
97
98 sp<InputDispatcherInterface> mDispatcher;
99 sp<InputDispatcherThread> mDispatcherThread;
100
101 void initialize();
102};
103
104} // namespace android
105
106#endif // _UI_INPUT_MANAGER_H