blob: eb275132e59f275d53e274276a876d2c2c95ddf0 [file] [log] [blame]
Jeff Browne839a582010-04-22 18:58:52 -07001/*
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 <ui/EventHub.h>
25#include <ui/Input.h>
26#include <ui/InputDispatchPolicy.h>
27#include <utils/Errors.h>
28#include <utils/Vector.h>
29#include <utils/Timers.h>
30#include <utils/RefBase.h>
31#include <utils/String8.h>
32
33namespace android {
34
35class InputReader;
36class InputDispatcher;
37class InputReaderThread;
38class InputDispatcherThread;
39
40/*
41 * The input manager is the core of the system event processing.
42 *
43 * The input manager uses two threads.
44 *
45 * 1. The InputReaderThread (called "InputReader") reads and preprocesses raw input events,
46 * applies policy, and posts messages to a queue managed by the DispatcherThread.
47 * 2. The InputDispatcherThread (called "InputDispatcher") thread waits for new events on the
48 * queue and asynchronously dispatches them to applications.
49 *
50 * By design, the InputReaderThread class and InputDispatcherThread class do not share any
51 * internal state. Moreover, all communication is done one way from the InputReaderThread
52 * into the InputDispatcherThread and never the reverse. Both classes may interact with the
53 * InputDispatchPolicy, however.
54 *
55 * The InputManager class never makes any calls into Java itself. Instead, the
56 * InputDispatchPolicy is responsible for performing all external interactions with the
57 * system, including calling DVM services.
58 */
59class InputManagerInterface : public virtual RefBase {
60protected:
61 InputManagerInterface() { }
62 virtual ~InputManagerInterface() { }
63
64public:
65 /* Starts the input manager threads. */
66 virtual status_t start() = 0;
67
68 /* Stops the input manager threads and waits for them to exit. */
69 virtual status_t stop() = 0;
70
71 /* Registers an input channel prior to using it as the target of an event. */
72 virtual status_t registerInputChannel(const sp<InputChannel>& inputChannel) = 0;
73
74 /* Unregisters an input channel. */
75 virtual status_t unregisterInputChannel(const sp<InputChannel>& inputChannel) = 0;
76
77 /*
78 * Query current input state.
79 * deviceId may be -1 to search for the device automatically, filtered by class.
80 * deviceClasses may be -1 to ignore device class while searching.
81 */
82 virtual int32_t getScanCodeState(int32_t deviceId, int32_t deviceClasses,
83 int32_t scanCode) const = 0;
84 virtual int32_t getKeyCodeState(int32_t deviceId, int32_t deviceClasses,
85 int32_t keyCode) const = 0;
86 virtual int32_t getSwitchState(int32_t deviceId, int32_t deviceClasses,
87 int32_t sw) const = 0;
88
89 /* Determine whether physical keys exist for the given framework-domain key codes. */
90 virtual bool hasKeys(size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags) const = 0;
91};
92
93class InputManager : public InputManagerInterface {
94protected:
95 virtual ~InputManager();
96
97public:
98 /*
99 * Creates an input manager that reads events from the given
100 * event hub and applies the given input dispatch policy.
101 */
102 InputManager(const sp<EventHubInterface>& eventHub,
103 const sp<InputDispatchPolicyInterface>& policy);
104
105 virtual status_t start();
106 virtual status_t stop();
107
108 virtual status_t registerInputChannel(const sp<InputChannel>& inputChannel);
109 virtual status_t unregisterInputChannel(const sp<InputChannel>& inputChannel);
110
111 virtual int32_t getScanCodeState(int32_t deviceId, int32_t deviceClasses,
112 int32_t scanCode) const;
113 virtual int32_t getKeyCodeState(int32_t deviceId, int32_t deviceClasses,
114 int32_t keyCode) const;
115 virtual int32_t getSwitchState(int32_t deviceId, int32_t deviceClasses,
116 int32_t sw) const;
117 virtual bool hasKeys(size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags) const;
118
119private:
120 sp<EventHubInterface> mEventHub;
121 sp<InputDispatchPolicyInterface> mPolicy;
122
123 sp<InputDispatcher> mDispatcher;
124 sp<InputDispatcherThread> mDispatcherThread;
125
126 sp<InputReader> mReader;
127 sp<InputReaderThread> mReaderThread;
128
129 void configureExcludedDevices();
130};
131
132} // namespace android
133
134#endif // _UI_INPUT_MANAGER_H