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 "InputClassifier.h" 25 #include "InputReaderBase.h" 26 #include "include/UnwantedInteractionBlockerInterface.h" 27 28 #include <InputDispatcherInterface.h> 29 #include <InputDispatcherPolicyInterface.h> 30 #include <input/Input.h> 31 #include <input/InputTransport.h> 32 33 #include <android/os/BnInputFlinger.h> 34 #include <utils/Errors.h> 35 #include <utils/RefBase.h> 36 #include <utils/Timers.h> 37 38 using android::os::BnInputFlinger; 39 40 namespace android { 41 class InputChannel; 42 class InputDispatcherThread; 43 44 /* 45 * The input manager is the core of the system event processing. 46 * 47 * The input manager has three components. 48 * 49 * 1. The InputReader class starts a thread that reads and preprocesses raw input events, applies 50 * policy, and posts messages to a queue managed by the UnwantedInteractionBlocker. 51 * 2. The UnwantedInteractionBlocker is responsible for removing unwanted interactions. For example, 52 * this could be a palm on the screen. This stage would alter the event stream to remove either 53 * partially (some of the pointers) or fully (all touches) the unwanted interaction. The events 54 * are processed on the InputReader thread, without any additional queue. The events are then 55 * posted to the queue managed by the InputClassifier. 56 * 3. The InputClassifier class starts a thread to communicate with the device-specific 57 * classifiers. It then waits on the queue of events from UnwantedInteractionBlocker, applies 58 * a classification to them, and queues them for the InputDispatcher. 59 * 4. The InputDispatcher class starts a thread that waits for new events on the 60 * previous queue and asynchronously dispatches them to applications. 61 * 62 * By design, none of these classes share any internal state. Moreover, all communication is 63 * done one way from the InputReader to the InputDispatcher and never the reverse. All 64 * classes may interact with the InputDispatchPolicy, however. 65 * 66 * The InputManager class never makes any calls into Java itself. Instead, the 67 * InputDispatchPolicy is responsible for performing all external interactions with the 68 * system, including calling DVM services. 69 */ 70 class InputManagerInterface : public virtual RefBase { 71 protected: InputManagerInterface()72 InputManagerInterface() { } ~InputManagerInterface()73 virtual ~InputManagerInterface() { } 74 75 public: 76 /* Starts the input threads. */ 77 virtual status_t start() = 0; 78 79 /* Stops the input threads and waits for them to exit. */ 80 virtual status_t stop() = 0; 81 82 /* Gets the input reader. */ 83 virtual InputReaderInterface& getReader() = 0; 84 85 /* Gets the unwanted interaction blocker. */ 86 virtual UnwantedInteractionBlockerInterface& getUnwantedInteractionBlocker() = 0; 87 88 /* Gets the input classifier */ 89 virtual InputClassifierInterface& getClassifier() = 0; 90 91 /* Gets the input dispatcher. */ 92 virtual InputDispatcherInterface& getDispatcher() = 0; 93 94 /* Check that the input stages have not deadlocked. */ 95 virtual void monitor() = 0; 96 }; 97 98 class InputManager : public InputManagerInterface, public BnInputFlinger { 99 protected: 100 ~InputManager() override; 101 102 public: 103 InputManager( 104 const sp<InputReaderPolicyInterface>& readerPolicy, 105 const sp<InputDispatcherPolicyInterface>& dispatcherPolicy); 106 107 status_t start() override; 108 status_t stop() override; 109 110 InputReaderInterface& getReader() override; 111 UnwantedInteractionBlockerInterface& getUnwantedInteractionBlocker() override; 112 InputClassifierInterface& getClassifier() override; 113 InputDispatcherInterface& getDispatcher() override; 114 void monitor() override; 115 116 status_t dump(int fd, const Vector<String16>& args) override; 117 binder::Status createInputChannel(const std::string& name, InputChannel* outChannel) override; 118 binder::Status removeInputChannel(const sp<IBinder>& connectionToken) override; 119 binder::Status setFocusedWindow(const gui::FocusRequest&) override; 120 121 private: 122 std::unique_ptr<InputReaderInterface> mReader; 123 124 std::unique_ptr<UnwantedInteractionBlockerInterface> mBlocker; 125 126 std::unique_ptr<InputClassifierInterface> mClassifier; 127 128 std::unique_ptr<InputDispatcherInterface> mDispatcher; 129 }; 130 131 } // namespace android 132 133 #endif // _UI_INPUT_MANAGER_H 134