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