blob: 142ec0c1eadb28c89f3c4d88455a02eb1bf0a331 [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"
Siarhei Vishniakou473174e2017-12-27 16:44:42 -080026#include "InputClassifier.h"
Michael Wrightd02c5b62014-02-10 15:10:22 -080027#include "InputDispatcher.h"
Siarhei Vishniakou473174e2017-12-27 16:44:42 -080028#include "InputReader.h"
Michael Wrightd02c5b62014-02-10 15:10:22 -080029
30#include <input/Input.h>
31#include <input/InputTransport.h>
Robert Carr1cc78672018-07-31 14:25:57 -070032
33#include <input/IInputFlinger.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080034#include <utils/Errors.h>
35#include <utils/Vector.h>
36#include <utils/Timers.h>
37#include <utils/RefBase.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080038
39namespace android {
Robert Carr1c4c5592018-09-24 13:18:43 -070040class InputChannel;
Michael Wrightd02c5b62014-02-10 15:10:22 -080041
42/*
43 * The input manager is the core of the system event processing.
44 *
45 * The input manager uses two threads.
46 *
47 * 1. The InputReaderThread (called "InputReader") reads and preprocesses raw input events,
48 * applies policy, and posts messages to a queue managed by the DispatcherThread.
49 * 2. The InputDispatcherThread (called "InputDispatcher") thread waits for new events on the
50 * queue and asynchronously dispatches them to applications.
51 *
52 * By design, the InputReaderThread class and InputDispatcherThread class do not share any
53 * internal state. Moreover, all communication is done one way from the InputReaderThread
54 * into the InputDispatcherThread and never the reverse. Both classes may interact with the
55 * InputDispatchPolicy, however.
56 *
57 * The InputManager class never makes any calls into Java itself. Instead, the
58 * InputDispatchPolicy is responsible for performing all external interactions with the
59 * system, including calling DVM services.
60 */
61class InputManagerInterface : public virtual RefBase {
62protected:
63 InputManagerInterface() { }
64 virtual ~InputManagerInterface() { }
65
66public:
67 /* Starts the input manager threads. */
68 virtual status_t start() = 0;
69
70 /* Stops the input manager threads and waits for them to exit. */
71 virtual status_t stop() = 0;
72
73 /* Gets the input reader. */
74 virtual sp<InputReaderInterface> getReader() = 0;
75
76 /* Gets the input dispatcher. */
77 virtual sp<InputDispatcherInterface> getDispatcher() = 0;
78};
79
Robert Carr1cc78672018-07-31 14:25:57 -070080class InputManager : public InputManagerInterface, public BnInputFlinger {
Michael Wrightd02c5b62014-02-10 15:10:22 -080081protected:
82 virtual ~InputManager();
83
84public:
85 InputManager(
Michael Wrightd02c5b62014-02-10 15:10:22 -080086 const sp<InputReaderPolicyInterface>& readerPolicy,
87 const sp<InputDispatcherPolicyInterface>& dispatcherPolicy);
88
Michael Wrightd02c5b62014-02-10 15:10:22 -080089 virtual status_t start();
90 virtual status_t stop();
91
92 virtual sp<InputReaderInterface> getReader();
93 virtual sp<InputDispatcherInterface> getDispatcher();
94
Robert Carr1cc78672018-07-31 14:25:57 -070095 virtual void setInputWindows(const Vector<InputWindowInfo>& handles);
chaviwfbe5d9c2018-12-26 12:23:37 -080096 virtual void transferTouchFocus(const sp<IBinder>& fromToken, const sp<IBinder>& toToken);
Robert Carr1cc78672018-07-31 14:25:57 -070097
Robert Carr1c4c5592018-09-24 13:18:43 -070098 virtual void registerInputChannel(const sp<InputChannel>& channel);
99 virtual void unregisterInputChannel(const sp<InputChannel>& channel);
100
Michael Wrightd02c5b62014-02-10 15:10:22 -0800101private:
102 sp<InputReaderInterface> mReader;
103 sp<InputReaderThread> mReaderThread;
104
Siarhei Vishniakou473174e2017-12-27 16:44:42 -0800105 sp<InputClassifierInterface> mClassifier;
106
Michael Wrightd02c5b62014-02-10 15:10:22 -0800107 sp<InputDispatcherInterface> mDispatcher;
108 sp<InputDispatcherThread> mDispatcherThread;
109
110 void initialize();
111};
112
113} // namespace android
114
115#endif // _UI_INPUT_MANAGER_H