Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
Siarhei Vishniakou | 473174e | 2017-12-27 16:44:42 -0800 | [diff] [blame] | 24 | #include "InputClassifier.h" |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 25 | #include "InputReaderBase.h" |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 26 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 27 | #include <InputDispatcherInterface.h> |
| 28 | #include <InputDispatcherPolicyInterface.h> |
| 29 | #include <input/ISetInputWindowsListener.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 30 | #include <input/Input.h> |
| 31 | #include <input/InputTransport.h> |
Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 32 | |
| 33 | #include <input/IInputFlinger.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 34 | #include <utils/Errors.h> |
| 35 | #include <utils/Vector.h> |
| 36 | #include <utils/Timers.h> |
| 37 | #include <utils/RefBase.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 38 | |
| 39 | namespace android { |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 40 | class InputChannel; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 41 | |
| 42 | /* |
| 43 | * The input manager is the core of the system event processing. |
| 44 | * |
Michael Wright | 6353416 | 2020-07-02 14:38:16 +0100 | [diff] [blame^] | 45 | * The input manager has three components. |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 46 | * |
Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 47 | * 1. The InputReader class starts a thread that reads and preprocesses raw input events, applies |
Michael Wright | 6353416 | 2020-07-02 14:38:16 +0100 | [diff] [blame^] | 48 | * policy, and posts messages to a queue managed by the InputClassifier. |
| 49 | * 2. The InputClassifier class starts a thread to communicate with the device-specific |
| 50 | * classifiers. It then waits on the queue of events from InputReader, applies a classification |
| 51 | * to them, and queues them for the InputDispatcher. |
| 52 | * 3. The InputDispatcher class starts a thread that waits for new events on the |
| 53 | * previous queue and asynchronously dispatches them to applications. |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 54 | * |
Michael Wright | 6353416 | 2020-07-02 14:38:16 +0100 | [diff] [blame^] | 55 | * By design, none of these classes share any internal state. Moreover, all communication is |
| 56 | * done one way from the InputReader to the InputDispatcher and never the reverse. All |
| 57 | * classes may interact with the InputDispatchPolicy, however. |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 58 | * |
| 59 | * The InputManager class never makes any calls into Java itself. Instead, the |
| 60 | * InputDispatchPolicy is responsible for performing all external interactions with the |
| 61 | * system, including calling DVM services. |
| 62 | */ |
| 63 | class InputManagerInterface : public virtual RefBase { |
| 64 | protected: |
| 65 | InputManagerInterface() { } |
| 66 | virtual ~InputManagerInterface() { } |
| 67 | |
| 68 | public: |
Prabir Pradhan | 3608aad | 2019-10-02 17:08:26 -0700 | [diff] [blame] | 69 | /* Starts the input threads. */ |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 70 | virtual status_t start() = 0; |
| 71 | |
Prabir Pradhan | 3608aad | 2019-10-02 17:08:26 -0700 | [diff] [blame] | 72 | /* Stops the input threads and waits for them to exit. */ |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 73 | virtual status_t stop() = 0; |
| 74 | |
| 75 | /* Gets the input reader. */ |
| 76 | virtual sp<InputReaderInterface> getReader() = 0; |
| 77 | |
Michael Wright | 6353416 | 2020-07-02 14:38:16 +0100 | [diff] [blame^] | 78 | /* Gets the input classifier */ |
| 79 | virtual sp<InputClassifierInterface> getClassifier() = 0; |
| 80 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 81 | /* Gets the input dispatcher. */ |
| 82 | virtual sp<InputDispatcherInterface> getDispatcher() = 0; |
| 83 | }; |
| 84 | |
Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 85 | class InputManager : public InputManagerInterface, public BnInputFlinger { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 86 | protected: |
Michael Wright | 6353416 | 2020-07-02 14:38:16 +0100 | [diff] [blame^] | 87 | ~InputManager() override; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 88 | |
| 89 | public: |
| 90 | InputManager( |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 91 | const sp<InputReaderPolicyInterface>& readerPolicy, |
| 92 | const sp<InputDispatcherPolicyInterface>& dispatcherPolicy); |
| 93 | |
Michael Wright | 6353416 | 2020-07-02 14:38:16 +0100 | [diff] [blame^] | 94 | status_t start() override; |
| 95 | status_t stop() override; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 96 | |
Michael Wright | 6353416 | 2020-07-02 14:38:16 +0100 | [diff] [blame^] | 97 | sp<InputReaderInterface> getReader() override; |
| 98 | sp<InputClassifierInterface> getClassifier() override; |
| 99 | sp<InputDispatcherInterface> getDispatcher() override; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 100 | |
Michael Wright | 6353416 | 2020-07-02 14:38:16 +0100 | [diff] [blame^] | 101 | void setInputWindows(const std::vector<InputWindowInfo>& handles, |
| 102 | const sp<ISetInputWindowsListener>& setInputWindowsListener) override; |
Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 103 | |
Michael Wright | 6353416 | 2020-07-02 14:38:16 +0100 | [diff] [blame^] | 104 | void registerInputChannel(const sp<InputChannel>& channel) override; |
| 105 | void unregisterInputChannel(const sp<InputChannel>& channel) override; |
Siarhei Vishniakou | c9ac19e | 2020-03-19 11:55:01 -0700 | [diff] [blame] | 106 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 107 | private: |
| 108 | sp<InputReaderInterface> mReader; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 109 | |
Siarhei Vishniakou | 473174e | 2017-12-27 16:44:42 -0800 | [diff] [blame] | 110 | sp<InputClassifierInterface> mClassifier; |
| 111 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 112 | sp<InputDispatcherInterface> mDispatcher; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | } // namespace android |
| 116 | |
| 117 | #endif // _UI_INPUT_MANAGER_H |