blob: ba0b28786bf3fedbe19dec126310a53e3458bd32 [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"
Siarhei Vishniakou473174e2017-12-27 16:44:42 -080025#include "InputClassifier.h"
Siarhei Vishniakou473174e2017-12-27 16:44:42 -080026#include "InputReader.h"
Garfield Tane84e6f92019-08-29 17:28:41 -070027#include "InputReaderBase.h"
Michael Wrightd02c5b62014-02-10 15:10:22 -080028
Garfield Tane84e6f92019-08-29 17:28:41 -070029#include <InputDispatcherInterface.h>
30#include <InputDispatcherPolicyInterface.h>
31#include <input/ISetInputWindowsListener.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080032#include <input/Input.h>
33#include <input/InputTransport.h>
Robert Carr1cc78672018-07-31 14:25:57 -070034
35#include <input/IInputFlinger.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080036#include <utils/Errors.h>
37#include <utils/Vector.h>
38#include <utils/Timers.h>
39#include <utils/RefBase.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080040
41namespace android {
Robert Carr1c4c5592018-09-24 13:18:43 -070042class InputChannel;
Garfield Tane84e6f92019-08-29 17:28:41 -070043class InputDispatcherThread;
Michael Wrightd02c5b62014-02-10 15:10:22 -080044
45/*
46 * The input manager is the core of the system event processing.
47 *
48 * The input manager uses two threads.
49 *
50 * 1. The InputReaderThread (called "InputReader") reads and preprocesses raw input events,
51 * applies policy, and posts messages to a queue managed by the DispatcherThread.
52 * 2. The InputDispatcherThread (called "InputDispatcher") thread waits for new events on the
53 * queue and asynchronously dispatches them to applications.
54 *
55 * By design, the InputReaderThread class and InputDispatcherThread class do not share any
56 * internal state. Moreover, all communication is done one way from the InputReaderThread
57 * into the InputDispatcherThread and never the reverse. Both classes may interact with the
58 * InputDispatchPolicy, however.
59 *
60 * The InputManager class never makes any calls into Java itself. Instead, the
61 * InputDispatchPolicy is responsible for performing all external interactions with the
62 * system, including calling DVM services.
63 */
64class InputManagerInterface : public virtual RefBase {
65protected:
66 InputManagerInterface() { }
67 virtual ~InputManagerInterface() { }
68
69public:
70 /* Starts the input manager threads. */
71 virtual status_t start() = 0;
72
73 /* Stops the input manager threads and waits for them to exit. */
74 virtual status_t stop() = 0;
75
76 /* Gets the input reader. */
77 virtual sp<InputReaderInterface> getReader() = 0;
78
79 /* Gets the input dispatcher. */
80 virtual sp<InputDispatcherInterface> getDispatcher() = 0;
81};
82
Robert Carr1cc78672018-07-31 14:25:57 -070083class InputManager : public InputManagerInterface, public BnInputFlinger {
Michael Wrightd02c5b62014-02-10 15:10:22 -080084protected:
85 virtual ~InputManager();
86
87public:
88 InputManager(
Michael Wrightd02c5b62014-02-10 15:10:22 -080089 const sp<InputReaderPolicyInterface>& readerPolicy,
90 const sp<InputDispatcherPolicyInterface>& dispatcherPolicy);
91
Michael Wrightd02c5b62014-02-10 15:10:22 -080092 virtual status_t start();
93 virtual status_t stop();
94
95 virtual sp<InputReaderInterface> getReader();
Siarhei Vishniakoua028c442019-02-04 14:33:23 -080096 virtual sp<InputClassifierInterface> getClassifier();
Michael Wrightd02c5b62014-02-10 15:10:22 -080097 virtual sp<InputDispatcherInterface> getDispatcher();
98
Arthur Hung7c3ae9c2019-03-11 11:23:03 +080099 virtual void setInputWindows(const std::vector<InputWindowInfo>& handles,
chaviw291d88a2019-02-14 10:33:58 -0800100 const sp<ISetInputWindowsListener>& setInputWindowsListener);
chaviwfbe5d9c2018-12-26 12:23:37 -0800101 virtual void transferTouchFocus(const sp<IBinder>& fromToken, const sp<IBinder>& toToken);
Robert Carr1cc78672018-07-31 14:25:57 -0700102
Robert Carr1c4c5592018-09-24 13:18:43 -0700103 virtual void registerInputChannel(const sp<InputChannel>& channel);
104 virtual void unregisterInputChannel(const sp<InputChannel>& channel);
105
Michael Wrightd02c5b62014-02-10 15:10:22 -0800106private:
107 sp<InputReaderInterface> mReader;
108 sp<InputReaderThread> mReaderThread;
109
Siarhei Vishniakou473174e2017-12-27 16:44:42 -0800110 sp<InputClassifierInterface> mClassifier;
111
Michael Wrightd02c5b62014-02-10 15:10:22 -0800112 sp<InputDispatcherInterface> mDispatcher;
113 sp<InputDispatcherThread> mDispatcherThread;
114
115 void initialize();
116};
117
118} // namespace android
119
120#endif // _UI_INPUT_MANAGER_H