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" 25 #include "InputReaderBase.h" 26 #include "InputClassifier.h" 27 #include "InputDispatcher.h" 28 #include "InputReader.h" 29 30 #include <input/Input.h> 31 #include <input/InputTransport.h> 32 #include <input/ISetInputWindowsListener.h> 33 34 #include <input/IInputFlinger.h> 35 #include <utils/Errors.h> 36 #include <utils/Vector.h> 37 #include <utils/Timers.h> 38 #include <utils/RefBase.h> 39 40 namespace android { 41 class InputChannel; 42 43 /* 44 * The input manager is the core of the system event processing. 45 * 46 * The input manager uses two threads. 47 * 48 * 1. The InputReaderThread (called "InputReader") reads and preprocesses raw input events, 49 * applies policy, and posts messages to a queue managed by the DispatcherThread. 50 * 2. The InputDispatcherThread (called "InputDispatcher") thread waits for new events on the 51 * queue and asynchronously dispatches them to applications. 52 * 53 * By design, the InputReaderThread class and InputDispatcherThread class do not share any 54 * internal state. Moreover, all communication is done one way from the InputReaderThread 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 manager threads. */ 69 virtual status_t start() = 0; 70 71 /* Stops the input manager 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 virtual void transferTouchFocus(const sp<IBinder>& fromToken, const sp<IBinder>& toToken); 100 101 virtual void registerInputChannel(const sp<InputChannel>& channel); 102 virtual void unregisterInputChannel(const sp<InputChannel>& channel); 103 104 private: 105 sp<InputReaderInterface> mReader; 106 sp<InputReaderThread> mReaderThread; 107 108 sp<InputClassifierInterface> mClassifier; 109 110 sp<InputDispatcherInterface> mDispatcher; 111 sp<InputDispatcherThread> mDispatcherThread; 112 113 void initialize(); 114 }; 115 116 } // namespace android 117 118 #endif // _UI_INPUT_MANAGER_H 119