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 27 #include <InputDispatcherInterface.h> 28 #include <InputDispatcherPolicyInterface.h> 29 #include <input/ISetInputWindowsListener.h> 30 #include <input/Input.h> 31 #include <input/InputTransport.h> 32 33 #include <input/IInputFlinger.h> 34 #include <utils/Errors.h> 35 #include <utils/Vector.h> 36 #include <utils/Timers.h> 37 #include <utils/RefBase.h> 38 39 namespace android { 40 class InputChannel; 41 class InputDispatcherThread; 42 43 /* 44 * The input manager is the core of the system event processing. 45 * 46 * The input manager has two components. 47 * 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. 50 * 2. The InputDispatcher class starts a thread that waits for new events on the 51 * queue and asynchronously dispatches them to applications. 52 * 53 * By design, the InputReader class and InputDispatcher class do not share any 54 * internal state. Moreover, all communication is done one way from the InputReader 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: InputManagerInterface()64 InputManagerInterface() { } ~InputManagerInterface()65 virtual ~InputManagerInterface() { } 66 67 public: 68 /* Starts the input threads. */ 69 virtual status_t start() = 0; 70 71 /* Stops the input threads and waits for them to exit. */ 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 81 class InputManager : public InputManagerInterface, public BnInputFlinger { 82 protected: 83 virtual ~InputManager(); 84 85 public: 86 InputManager( 87 const sp<InputReaderPolicyInterface>& readerPolicy, 88 const sp<InputDispatcherPolicyInterface>& dispatcherPolicy); 89 90 virtual status_t start(); 91 virtual status_t stop(); 92 93 virtual sp<InputReaderInterface> getReader(); 94 virtual sp<InputClassifierInterface> getClassifier(); 95 virtual sp<InputDispatcherInterface> getDispatcher(); 96 97 virtual void setInputWindows(const std::vector<InputWindowInfo>& handles, 98 const sp<ISetInputWindowsListener>& setInputWindowsListener); 99 100 virtual void registerInputChannel(const sp<InputChannel>& channel); 101 virtual void unregisterInputChannel(const sp<InputChannel>& channel); 102 103 void setMotionClassifierEnabled(bool enabled); 104 105 private: 106 sp<InputReaderInterface> mReader; 107 108 sp<InputClassifierInterface> mClassifier; 109 110 sp<InputDispatcherInterface> mDispatcher; 111 }; 112 113 } // namespace android 114 115 #endif // _UI_INPUT_MANAGER_H 116