| 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" | 
| Siarhei Vishniakou | 473174e | 2017-12-27 16:44:42 -0800 | [diff] [blame] | 26 | #include "InputClassifier.h" | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 27 | #include "InputDispatcher.h" | 
| Siarhei Vishniakou | 473174e | 2017-12-27 16:44:42 -0800 | [diff] [blame] | 28 | #include "InputReader.h" | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 29 |  | 
 | 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 |  * | 
 | 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 |  */ | 
 | 61 | class InputManagerInterface : public virtual RefBase { | 
 | 62 | protected: | 
 | 63 |     InputManagerInterface() { } | 
 | 64 |     virtual ~InputManagerInterface() { } | 
 | 65 |  | 
 | 66 | public: | 
 | 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 Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 80 | class InputManager : public InputManagerInterface, public BnInputFlinger { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 81 | protected: | 
 | 82 |     virtual ~InputManager(); | 
 | 83 |  | 
 | 84 | public: | 
 | 85 |     InputManager( | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 86 |             const sp<InputReaderPolicyInterface>& readerPolicy, | 
 | 87 |             const sp<InputDispatcherPolicyInterface>& dispatcherPolicy); | 
 | 88 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 89 |     virtual status_t start(); | 
 | 90 |     virtual status_t stop(); | 
 | 91 |  | 
 | 92 |     virtual sp<InputReaderInterface> getReader(); | 
| Siarhei Vishniakou | a028c44 | 2019-02-04 14:33:23 -0800 | [diff] [blame] | 93 |     virtual sp<InputClassifierInterface> getClassifier(); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 94 |     virtual sp<InputDispatcherInterface> getDispatcher(); | 
 | 95 |  | 
| Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 96 |     virtual void setInputWindows(const Vector<InputWindowInfo>& handles); | 
| chaviw | fbe5d9c | 2018-12-26 12:23:37 -0800 | [diff] [blame] | 97 |     virtual void transferTouchFocus(const sp<IBinder>& fromToken, const sp<IBinder>& toToken); | 
| Robert Carr | 1cc7867 | 2018-07-31 14:25:57 -0700 | [diff] [blame] | 98 |  | 
| Robert Carr | 1c4c559 | 2018-09-24 13:18:43 -0700 | [diff] [blame] | 99 |     virtual void registerInputChannel(const sp<InputChannel>& channel); | 
 | 100 |     virtual void unregisterInputChannel(const sp<InputChannel>& channel); | 
 | 101 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 102 | private: | 
 | 103 |     sp<InputReaderInterface> mReader; | 
 | 104 |     sp<InputReaderThread> mReaderThread; | 
 | 105 |  | 
| Siarhei Vishniakou | 473174e | 2017-12-27 16:44:42 -0800 | [diff] [blame] | 106 |     sp<InputClassifierInterface> mClassifier; | 
 | 107 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 108 |     sp<InputDispatcherInterface> mDispatcher; | 
 | 109 |     sp<InputDispatcherThread> mDispatcherThread; | 
 | 110 |  | 
 | 111 |     void initialize(); | 
 | 112 | }; | 
 | 113 |  | 
 | 114 | } // namespace android | 
 | 115 |  | 
 | 116 | #endif // _UI_INPUT_MANAGER_H |