Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2010 The Android Open Source Project |
| 3 | // |
| 4 | // The input manager. |
| 5 | // |
| 6 | #define LOG_TAG "InputManager" |
| 7 | |
| 8 | //#define LOG_NDEBUG 0 |
| 9 | |
| 10 | #include <cutils/log.h> |
| 11 | #include <ui/InputManager.h> |
| 12 | #include <ui/InputReader.h> |
| 13 | #include <ui/InputDispatcher.h> |
| 14 | |
| 15 | namespace android { |
| 16 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 17 | InputManager::InputManager( |
| 18 | const sp<EventHubInterface>& eventHub, |
| 19 | const sp<InputReaderPolicyInterface>& readerPolicy, |
| 20 | const sp<InputDispatcherPolicyInterface>& dispatcherPolicy) { |
| 21 | mDispatcher = new InputDispatcher(dispatcherPolicy); |
| 22 | mReader = new InputReader(eventHub, readerPolicy, mDispatcher); |
| 23 | initialize(); |
| 24 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 25 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 26 | InputManager::InputManager( |
| 27 | const sp<InputReaderInterface>& reader, |
| 28 | const sp<InputDispatcherInterface>& dispatcher) : |
| 29 | mReader(reader), |
| 30 | mDispatcher(dispatcher) { |
| 31 | initialize(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | InputManager::~InputManager() { |
| 35 | stop(); |
| 36 | } |
| 37 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 38 | void InputManager::initialize() { |
| 39 | mReaderThread = new InputReaderThread(mReader); |
| 40 | mDispatcherThread = new InputDispatcherThread(mDispatcher); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | status_t InputManager::start() { |
| 44 | status_t result = mDispatcherThread->run("InputDispatcher", PRIORITY_URGENT_DISPLAY); |
| 45 | if (result) { |
| 46 | LOGE("Could not start InputDispatcher thread due to error %d.", result); |
| 47 | return result; |
| 48 | } |
| 49 | |
| 50 | result = mReaderThread->run("InputReader", PRIORITY_URGENT_DISPLAY); |
| 51 | if (result) { |
| 52 | LOGE("Could not start InputReader thread due to error %d.", result); |
| 53 | |
| 54 | mDispatcherThread->requestExit(); |
| 55 | return result; |
| 56 | } |
| 57 | |
| 58 | return OK; |
| 59 | } |
| 60 | |
| 61 | status_t InputManager::stop() { |
| 62 | status_t result = mReaderThread->requestExitAndWait(); |
| 63 | if (result) { |
| 64 | LOGW("Could not stop InputReader thread due to error %d.", result); |
| 65 | } |
| 66 | |
| 67 | result = mDispatcherThread->requestExitAndWait(); |
| 68 | if (result) { |
| 69 | LOGW("Could not stop InputDispatcher thread due to error %d.", result); |
| 70 | } |
| 71 | |
| 72 | return OK; |
| 73 | } |
| 74 | |
| 75 | status_t InputManager::registerInputChannel(const sp<InputChannel>& inputChannel) { |
| 76 | return mDispatcher->registerInputChannel(inputChannel); |
| 77 | } |
| 78 | |
| 79 | status_t InputManager::unregisterInputChannel(const sp<InputChannel>& inputChannel) { |
| 80 | return mDispatcher->unregisterInputChannel(inputChannel); |
| 81 | } |
| 82 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 83 | int32_t InputManager::injectInputEvent(const InputEvent* event, |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 84 | int32_t injectorPid, int32_t injectorUid, int32_t syncMode, int32_t timeoutMillis) { |
| 85 | return mDispatcher->injectInputEvent(event, injectorPid, injectorUid, syncMode, timeoutMillis); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 88 | void InputManager::preemptInputDispatch() { |
| 89 | mDispatcher->preemptInputDispatch(); |
| 90 | } |
| 91 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 92 | void InputManager::getInputConfiguration(InputConfiguration* outConfiguration) { |
| 93 | mReader->getInputConfiguration(outConfiguration); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 96 | status_t InputManager::getInputDeviceInfo(int32_t deviceId, InputDeviceInfo* outDeviceInfo) { |
| 97 | return mReader->getInputDeviceInfo(deviceId, outDeviceInfo); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 98 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 99 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 100 | void InputManager::getInputDeviceIds(Vector<int32_t>& outDeviceIds) { |
| 101 | mReader->getInputDeviceIds(outDeviceIds); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 104 | int32_t InputManager::getScanCodeState(int32_t deviceId, uint32_t sourceMask, |
| 105 | int32_t scanCode) { |
| 106 | return mReader->getScanCodeState(deviceId, sourceMask, scanCode); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 109 | int32_t InputManager::getKeyCodeState(int32_t deviceId, uint32_t sourceMask, |
| 110 | int32_t keyCode) { |
| 111 | return mReader->getKeyCodeState(deviceId, sourceMask, keyCode); |
| 112 | } |
| 113 | |
| 114 | int32_t InputManager::getSwitchState(int32_t deviceId, uint32_t sourceMask, int32_t sw) { |
| 115 | return mReader->getSwitchState(deviceId, sourceMask, sw); |
| 116 | } |
| 117 | |
| 118 | bool InputManager::hasKeys(int32_t deviceId, uint32_t sourceMask, |
| 119 | size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags) { |
| 120 | return mReader->hasKeys(deviceId, sourceMask, numCodes, keyCodes, outFlags); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | } // namespace android |