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 | |
| 24 | #include "EventHub.h" |
Siarhei Vishniakou | 473174e | 2017-12-27 16:44:42 -0800 | [diff] [blame] | 25 | #include "InputClassifier.h" |
Siarhei Vishniakou | 473174e | 2017-12-27 16:44:42 -0800 | [diff] [blame] | 26 | #include "InputReader.h" |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame^] | 27 | #include "InputReaderBase.h" |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 28 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame^] | 29 | #include <InputDispatcherInterface.h> |
| 30 | #include <InputDispatcherPolicyInterface.h> |
| 31 | #include <input/ISetInputWindowsListener.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 32 | #include <input/Input.h> |
| 33 | #include <input/InputTransport.h> |
Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 34 | |
| 35 | #include <input/IInputFlinger.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 36 | #include <utils/Errors.h> |
| 37 | #include <utils/Vector.h> |
| 38 | #include <utils/Timers.h> |
| 39 | #include <utils/RefBase.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 40 | |
| 41 | namespace android { |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 42 | class InputChannel; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame^] | 43 | class InputDispatcherThread; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 44 | |
| 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 | */ |
| 64 | class InputManagerInterface : public virtual RefBase { |
| 65 | protected: |
| 66 | InputManagerInterface() { } |
| 67 | virtual ~InputManagerInterface() { } |
| 68 | |
| 69 | public: |
| 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 Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 83 | class InputManager : public InputManagerInterface, public BnInputFlinger { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 84 | protected: |
| 85 | virtual ~InputManager(); |
| 86 | |
| 87 | public: |
| 88 | InputManager( |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 89 | const sp<InputReaderPolicyInterface>& readerPolicy, |
| 90 | const sp<InputDispatcherPolicyInterface>& dispatcherPolicy); |
| 91 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 92 | virtual status_t start(); |
| 93 | virtual status_t stop(); |
| 94 | |
| 95 | virtual sp<InputReaderInterface> getReader(); |
Siarhei Vishniakou | a028c44 | 2019-02-04 14:33:23 -0800 | [diff] [blame] | 96 | virtual sp<InputClassifierInterface> getClassifier(); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 97 | virtual sp<InputDispatcherInterface> getDispatcher(); |
| 98 | |
Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 99 | virtual void setInputWindows(const std::vector<InputWindowInfo>& handles, |
chaviw | 291d88a | 2019-02-14 10:33:58 -0800 | [diff] [blame] | 100 | const sp<ISetInputWindowsListener>& setInputWindowsListener); |
chaviw | fbe5d9c | 2018-12-26 12:23:37 -0800 | [diff] [blame] | 101 | virtual void transferTouchFocus(const sp<IBinder>& fromToken, const sp<IBinder>& toToken); |
Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 102 | |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 103 | virtual void registerInputChannel(const sp<InputChannel>& channel); |
| 104 | virtual void unregisterInputChannel(const sp<InputChannel>& channel); |
| 105 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 106 | private: |
| 107 | sp<InputReaderInterface> mReader; |
| 108 | sp<InputReaderThread> mReaderThread; |
| 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; |
| 113 | sp<InputDispatcherThread> mDispatcherThread; |
| 114 | |
| 115 | void initialize(); |
| 116 | }; |
| 117 | |
| 118 | } // namespace android |
| 119 | |
| 120 | #endif // _UI_INPUT_MANAGER_H |