From 9c3cda04d969912bc46184f2b326d1db95e0aba5 Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Tue, 15 Jun 2010 01:31:58 -0700 Subject: More work in progress on native events. Refactored the code to eliminate potential deadlocks due to re-entrant calls from the policy into the dispatcher. Also added some plumbing that will be used to notify the framework about ANRs. Change-Id: Iba7a10de0cb3c56cd7520d6ce716db52fdcc94ff --- libs/ui/InputManager.cpp | 65 +++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 37 deletions(-) (limited to 'libs/ui/InputManager.cpp') diff --git a/libs/ui/InputManager.cpp b/libs/ui/InputManager.cpp index ab354a5da11c..7538dd01d37f 100644 --- a/libs/ui/InputManager.cpp +++ b/libs/ui/InputManager.cpp @@ -14,29 +14,30 @@ namespace android { -InputManager::InputManager(const sp& eventHub, - const sp& policy) : - mEventHub(eventHub), mPolicy(policy) { - mDispatcher = new InputDispatcher(policy); - mReader = new InputReader(eventHub, policy, mDispatcher); - - mDispatcherThread = new InputDispatcherThread(mDispatcher); - mReaderThread = new InputReaderThread(mReader); +InputManager::InputManager( + const sp& eventHub, + const sp& readerPolicy, + const sp& dispatcherPolicy) { + mDispatcher = new InputDispatcher(dispatcherPolicy); + mReader = new InputReader(eventHub, readerPolicy, mDispatcher); + initialize(); +} - configureExcludedDevices(); +InputManager::InputManager( + const sp& reader, + const sp& dispatcher) : + mReader(reader), + mDispatcher(dispatcher) { + initialize(); } InputManager::~InputManager() { stop(); } -void InputManager::configureExcludedDevices() { - Vector excludedDeviceNames; - mPolicy->getExcludedDeviceNames(excludedDeviceNames); - - for (size_t i = 0; i < excludedDeviceNames.size(); i++) { - mEventHub->addExcludedDevice(excludedDeviceNames[i]); - } +void InputManager::initialize() { + mReaderThread = new InputReaderThread(mReader); + mDispatcherThread = new InputDispatcherThread(mDispatcher); } status_t InputManager::start() { @@ -79,36 +80,26 @@ status_t InputManager::unregisterInputChannel(const sp& inputChann return mDispatcher->unregisterInputChannel(inputChannel); } -int32_t InputManager::getScanCodeState(int32_t deviceId, int32_t deviceClasses, int32_t scanCode) - const { - int32_t vkKeyCode, vkScanCode; - if (mReader->getCurrentVirtualKey(& vkKeyCode, & vkScanCode)) { - if (vkScanCode == scanCode) { - return KEY_STATE_VIRTUAL; - } - } - - return mEventHub->getScanCodeState(deviceId, deviceClasses, scanCode); +void InputManager::getInputConfiguration(InputConfiguration* outConfiguration) const { + mReader->getCurrentInputConfiguration(outConfiguration); } -int32_t InputManager::getKeyCodeState(int32_t deviceId, int32_t deviceClasses, int32_t keyCode) - const { - int32_t vkKeyCode, vkScanCode; - if (mReader->getCurrentVirtualKey(& vkKeyCode, & vkScanCode)) { - if (vkKeyCode == keyCode) { - return KEY_STATE_VIRTUAL; - } - } +int32_t InputManager::getScanCodeState(int32_t deviceId, int32_t deviceClasses, + int32_t scanCode) const { + return mReader->getCurrentScanCodeState(deviceId, deviceClasses, scanCode); +} - return mEventHub->getKeyCodeState(deviceId, deviceClasses, keyCode); +int32_t InputManager::getKeyCodeState(int32_t deviceId, int32_t deviceClasses, + int32_t keyCode) const { + return mReader->getCurrentKeyCodeState(deviceId, deviceClasses, keyCode); } int32_t InputManager::getSwitchState(int32_t deviceId, int32_t deviceClasses, int32_t sw) const { - return mEventHub->getSwitchState(deviceId, deviceClasses, sw); + return mReader->getCurrentSwitchState(deviceId, deviceClasses, sw); } bool InputManager::hasKeys(size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags) const { - return mEventHub->hasKeys(numCodes, keyCodes, outFlags); + return mReader->hasKeys(numCodes, keyCodes, outFlags); } } // namespace android -- cgit v1.2.3-59-g8ed1b