diff options
author | 2010-11-18 20:53:46 -0800 | |
---|---|---|
committer | 2010-11-30 18:50:17 -0800 | |
commit | 53c16642e2f8176b26f61b98328051f6dd1234ae (patch) | |
tree | aad37749d50f5e3bdd41946934aec27284cc4b77 | |
parent | 6688837ff6a959b4f59d9a4249aac1504f590a4b (diff) |
Ensure the ShortcutManager uses the correct key character map.
The ShortcutManager used to only receive the key code of the key event
that triggered the shortcut. This change now provides the shortcut
manager with the whole key event so it can look up the associated
character using the correct key character map.
To make this more efficient, added a mechanism for recycling
key events. At the moment it is only used by key events owned by the
system process, since clients of the existing API (such as Views)
might continue to hold on to key events after dispatch has finished so
they would break if the key event were recycled by the framework.
Deprecated KeyCharacterMap.BUILT_IN_KEYBOARD.
Change-Id: I4313725dd63f2be01c350c005a41c7fde9bc67e8
-rw-r--r-- | include/ui/Input.h | 4 | ||||
-rw-r--r-- | include/ui/InputDispatcher.h | 7 | ||||
-rw-r--r-- | libs/ui/EventHub.cpp | 4 | ||||
-rw-r--r-- | libs/ui/InputDispatcher.cpp | 49 | ||||
-rw-r--r-- | libs/ui/InputReader.cpp | 2 | ||||
-rw-r--r-- | libs/ui/tests/InputDispatcher_test.cpp | 4 |
6 files changed, 41 insertions, 29 deletions
diff --git a/include/ui/Input.h b/include/ui/Input.h index 11b798fdbc..4dc8f2a840 100644 --- a/include/ui/Input.h +++ b/include/ui/Input.h @@ -507,10 +507,8 @@ enum InputDeviceConfigurationFileType { /* * Get the path of an input device configuration file, if one is available. * Spaces in the name are replaced with underscores. + * Considers both system provided and user installed configuration files. * - * Looks in: <system-root>/usr/<type-specific-directory>/<name><extension>. - * - * TODO Also look in a user installable location. * Returns an empty string if not found. */ extern String8 getInputDeviceConfigurationFilePath( diff --git a/include/ui/InputDispatcher.h b/include/ui/InputDispatcher.h index d0812deb98..b621680ada 100644 --- a/include/ui/InputDispatcher.h +++ b/include/ui/InputDispatcher.h @@ -291,9 +291,7 @@ public: * This method is expected to set the POLICY_FLAG_PASS_TO_USER policy flag if the event * should be dispatched to applications. */ - virtual void interceptKeyBeforeQueueing(nsecs_t when, int32_t deviceId, - int32_t action, int32_t& flags, int32_t keyCode, int32_t scanCode, - uint32_t& policyFlags) = 0; + virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags) = 0; /* Intercepts a generic touch, trackball or other event before queueing it. * The policy can use this method as an opportunity to perform power management functions @@ -894,9 +892,6 @@ private: // Input channels that will receive a copy of all input events. Vector<sp<InputChannel> > mMonitoringChannels; - // Preallocated key event object used for policy inquiries. - KeyEvent mReusableKeyEvent; - // Event injection and synchronization. Condition mInjectionResultAvailableCondition; bool hasInjectionPermission(int32_t injectorPid, int32_t injectorUid); diff --git a/libs/ui/EventHub.cpp b/libs/ui/EventHub.cpp index f831086531..b312cda8ac 100644 --- a/libs/ui/EventHub.cpp +++ b/libs/ui/EventHub.cpp @@ -146,12 +146,12 @@ uint32_t EventHub::getDeviceClasses(int32_t deviceId) const } void EventHub::getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const { - outConfiguration->clear(); - AutoMutex _l(mLock); device_t* device = getDeviceLocked(deviceId); if (device && device->configuration) { *outConfiguration = *device->configuration; + } else { + outConfiguration->clear(); } } diff --git a/libs/ui/InputDispatcher.cpp b/libs/ui/InputDispatcher.cpp index db7d4487c9..07082232a3 100644 --- a/libs/ui/InputDispatcher.cpp +++ b/libs/ui/InputDispatcher.cpp @@ -2081,9 +2081,22 @@ void InputDispatcher::notifyKey(nsecs_t eventTime, int32_t deviceId, int32_t sou return; } + if ((policyFlags & POLICY_FLAG_VIRTUAL) || (flags & AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY)) { + policyFlags |= POLICY_FLAG_VIRTUAL; + flags |= AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY; + } + policyFlags |= POLICY_FLAG_TRUSTED; - mPolicy->interceptKeyBeforeQueueing(eventTime, deviceId, action, /*byref*/ flags, - keyCode, scanCode, /*byref*/ policyFlags); + + KeyEvent event; + event.initialize(deviceId, source, action, flags, keyCode, scanCode, + metaState, 0, downTime, eventTime); + + mPolicy->interceptKeyBeforeQueueing(&event, /*byref*/ policyFlags); + + if (policyFlags & POLICY_FLAG_WOKE_HERE) { + flags |= AKEY_EVENT_FLAG_WOKE_HERE; + } bool needWake; { // acquire lock @@ -2289,17 +2302,22 @@ int32_t InputDispatcher::injectInputEvent(const InputEvent* event, return INPUT_EVENT_INJECTION_FAILED; } - nsecs_t eventTime = keyEvent->getEventTime(); - int32_t deviceId = keyEvent->getDeviceId(); int32_t flags = keyEvent->getFlags(); - int32_t keyCode = keyEvent->getKeyCode(); - int32_t scanCode = keyEvent->getScanCode(); - mPolicy->interceptKeyBeforeQueueing(eventTime, deviceId, action, /*byref*/ flags, - keyCode, scanCode, /*byref*/ policyFlags); + if (flags & AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY) { + policyFlags |= POLICY_FLAG_VIRTUAL; + } + + mPolicy->interceptKeyBeforeQueueing(keyEvent, /*byref*/ policyFlags); + + if (policyFlags & POLICY_FLAG_WOKE_HERE) { + flags |= AKEY_EVENT_FLAG_WOKE_HERE; + } mLock.lock(); - injectedEntry = mAllocator.obtainKeyEntry(eventTime, deviceId, keyEvent->getSource(), - policyFlags, action, flags, keyCode, scanCode, keyEvent->getMetaState(), + injectedEntry = mAllocator.obtainKeyEntry(keyEvent->getEventTime(), + keyEvent->getDeviceId(), keyEvent->getSource(), + policyFlags, action, flags, + keyEvent->getKeyCode(), keyEvent->getScanCode(), keyEvent->getMetaState(), keyEvent->getRepeatCount(), keyEvent->getDownTime()); break; } @@ -2999,12 +3017,14 @@ void InputDispatcher::doNotifyANRLockedInterruptible( void InputDispatcher::doInterceptKeyBeforeDispatchingLockedInterruptible( CommandEntry* commandEntry) { KeyEntry* entry = commandEntry->keyEntry; - initializeKeyEvent(&mReusableKeyEvent, entry); + + KeyEvent event; + initializeKeyEvent(&event, entry); mLock.unlock(); bool consumed = mPolicy->interceptKeyBeforeDispatching(commandEntry->inputChannel, - & mReusableKeyEvent, entry->policyFlags); + &event, entry->policyFlags); mLock.lock(); @@ -3025,12 +3045,13 @@ void InputDispatcher::doDispatchCycleFinishedLockedInterruptible( && dispatchEntry->hasForegroundTarget() && dispatchEntry->eventEntry->type == EventEntry::TYPE_KEY) { KeyEntry* keyEntry = static_cast<KeyEntry*>(dispatchEntry->eventEntry); - initializeKeyEvent(&mReusableKeyEvent, keyEntry); + KeyEvent event; + initializeKeyEvent(&event, keyEntry); mLock.unlock(); mPolicy->dispatchUnhandledKey(connection->inputChannel, - & mReusableKeyEvent, keyEntry->policyFlags); + &event, keyEntry->policyFlags); mLock.lock(); } diff --git a/libs/ui/InputReader.cpp b/libs/ui/InputReader.cpp index dc9085bb3b..aa690e5fd1 100644 --- a/libs/ui/InputReader.cpp +++ b/libs/ui/InputReader.cpp @@ -2007,7 +2007,7 @@ void TouchInputMapper::dumpCalibration(String8& dump) { } if (mCalibration.haveToolSizeIsSummed) { - dump.appendFormat(INDENT4 "touch.toolSize.isSummed: %d\n", + dump.appendFormat(INDENT4 "touch.toolSize.isSummed: %s\n", toString(mCalibration.toolSizeIsSummed)); } diff --git a/libs/ui/tests/InputDispatcher_test.cpp b/libs/ui/tests/InputDispatcher_test.cpp index f352dbf6af..68f9037357 100644 --- a/libs/ui/tests/InputDispatcher_test.cpp +++ b/libs/ui/tests/InputDispatcher_test.cpp @@ -54,9 +54,7 @@ private: return 60; } - virtual void interceptKeyBeforeQueueing(nsecs_t when, int32_t deviceId, - int32_t action, int32_t& flags, int32_t keyCode, int32_t scanCode, - uint32_t& policyFlags) { + virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags) { } virtual void interceptGenericBeforeQueueing(nsecs_t when, uint32_t& policyFlags) { |