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