blob: ab309b1888e877d25c3ea6b71f5365a1f447ea77 [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 {
Robert Carr1c4c5592018-09-24 13:18:43 -070038class InputChannel;
Michael Wrightd02c5b62014-02-10 15:10:22 -080039
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 /* Gets the input reader. */
72 virtual sp<InputReaderInterface> getReader() = 0;
73
74 /* Gets the input dispatcher. */
75 virtual sp<InputDispatcherInterface> getDispatcher() = 0;
76};
77
Robert Carr1cc78672018-07-31 14:25:57 -070078class InputManager : public InputManagerInterface, public BnInputFlinger {
Michael Wrightd02c5b62014-02-10 15:10:22 -080079protected:
80 virtual ~InputManager();
81
82public:
83 InputManager(
Michael Wrightd02c5b62014-02-10 15:10:22 -080084 const sp<InputReaderPolicyInterface>& readerPolicy,
85 const sp<InputDispatcherPolicyInterface>& dispatcherPolicy);
86
Michael Wrightd02c5b62014-02-10 15:10:22 -080087 virtual status_t start();
88 virtual status_t stop();
89
90 virtual sp<InputReaderInterface> getReader();
91 virtual sp<InputDispatcherInterface> getDispatcher();
92
Robert Carr1cc78672018-07-31 14:25:57 -070093 virtual void setInputWindows(const Vector<InputWindowInfo>& handles);
chaviwfbe5d9c2018-12-26 12:23:37 -080094 virtual void transferTouchFocus(const sp<IBinder>& fromToken, const sp<IBinder>& toToken);
Robert Carr1cc78672018-07-31 14:25:57 -070095
Robert Carr1c4c5592018-09-24 13:18:43 -070096 virtual void registerInputChannel(const sp<InputChannel>& channel);
97 virtual void unregisterInputChannel(const sp<InputChannel>& channel);
98
Michael Wrightd02c5b62014-02-10 15:10:22 -080099private:
100 sp<InputReaderInterface> mReader;
101 sp<InputReaderThread> mReaderThread;
102
103 sp<InputDispatcherInterface> mDispatcher;
104 sp<InputDispatcherThread> mDispatcherThread;
105
106 void initialize();
107};
108
109} // namespace android
110
111#endif // _UI_INPUT_MANAGER_H