blob: d0e4cb02be0a858d48cb21a62d67fb49460796a5 [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"
25#include "InputReader.h"
26#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(
83 const sp<EventHubInterface>& eventHub,
84 const sp<InputReaderPolicyInterface>& readerPolicy,
85 const sp<InputDispatcherPolicyInterface>& dispatcherPolicy);
86
87 // (used for testing purposes)
88 InputManager(
89 const sp<InputReaderInterface>& reader,
90 const sp<InputDispatcherInterface>& dispatcher);
91
92 virtual status_t start();
93 virtual status_t stop();
94
95 virtual sp<InputReaderInterface> getReader();
96 virtual sp<InputDispatcherInterface> getDispatcher();
97
Robert Carr1cc78672018-07-31 14:25:57 -070098 virtual void setInputWindows(const Vector<InputWindowInfo>& handles);
99
Michael Wrightd02c5b62014-02-10 15:10:22 -0800100private:
101 sp<InputReaderInterface> mReader;
102 sp<InputReaderThread> mReaderThread;
103
104 sp<InputDispatcherInterface> mDispatcher;
105 sp<InputDispatcherThread> mDispatcherThread;
106
107 void initialize();
108};
109
110} // namespace android
111
112#endif // _UI_INPUT_MANAGER_H