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" |
Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame] | 25 | #include "InputReaderBase.h" |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 26 | #include "InputDispatcher.h" |
| 27 | |
| 28 | #include <input/Input.h> |
| 29 | #include <input/InputTransport.h> |
Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 30 | |
| 31 | #include <input/IInputFlinger.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 32 | #include <utils/Errors.h> |
| 33 | #include <utils/Vector.h> |
| 34 | #include <utils/Timers.h> |
| 35 | #include <utils/RefBase.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 36 | |
| 37 | namespace android { |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame^] | 38 | class InputChannel; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 39 | |
| 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 | */ |
| 59 | class InputManagerInterface : public virtual RefBase { |
| 60 | protected: |
| 61 | InputManagerInterface() { } |
| 62 | virtual ~InputManagerInterface() { } |
| 63 | |
| 64 | public: |
| 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 Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 78 | class InputManager : public InputManagerInterface, public BnInputFlinger { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 79 | protected: |
| 80 | virtual ~InputManager(); |
| 81 | |
| 82 | public: |
| 83 | InputManager( |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 84 | const sp<InputReaderPolicyInterface>& readerPolicy, |
| 85 | const sp<InputDispatcherPolicyInterface>& dispatcherPolicy); |
| 86 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 87 | virtual status_t start(); |
| 88 | virtual status_t stop(); |
| 89 | |
| 90 | virtual sp<InputReaderInterface> getReader(); |
| 91 | virtual sp<InputDispatcherInterface> getDispatcher(); |
| 92 | |
Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 93 | virtual void setInputWindows(const Vector<InputWindowInfo>& handles); |
| 94 | |
Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame^] | 95 | virtual void registerInputChannel(const sp<InputChannel>& channel); |
| 96 | virtual void unregisterInputChannel(const sp<InputChannel>& channel); |
| 97 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 98 | private: |
| 99 | sp<InputReaderInterface> mReader; |
| 100 | sp<InputReaderThread> mReaderThread; |
| 101 | |
| 102 | sp<InputDispatcherInterface> mDispatcher; |
| 103 | sp<InputDispatcherThread> mDispatcherThread; |
| 104 | |
| 105 | void initialize(); |
| 106 | }; |
| 107 | |
| 108 | } // namespace android |
| 109 | |
| 110 | #endif // _UI_INPUT_MANAGER_H |