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