diff options
author | Jeff Brown <jeffbrown@google.com> | 2012-09-27 20:46:43 -0700 |
---|---|---|
committer | Jeff Brown <jeffbrown@google.com> | 2012-09-27 21:42:57 -0700 |
commit | bcc046af4ef171aa3aa3c6b64efb5cafc1e46cd3 (patch) | |
tree | 497724ac54d4a380b5f466ea48a3a96265446754 | |
parent | 580ee8b0c6e1aea1e2e1d60499b603b9168b44f0 (diff) | |
download | frameworks_base-bcc046af4ef171aa3aa3c6b64efb5cafc1e46cd3.zip frameworks_base-bcc046af4ef171aa3aa3c6b64efb5cafc1e46cd3.tar.gz frameworks_base-bcc046af4ef171aa3aa3c6b64efb5cafc1e46cd3.tar.bz2 |
Bundle correlated switch changes atomically.
This is a prerequisite for headset jack detection on Manta.
Bug: 6548391
Change-Id: I549a194344511c0cee578b00f6a9ab5fdbdfb99c
-rw-r--r-- | services/input/InputDispatcher.cpp | 6 | ||||
-rw-r--r-- | services/input/InputDispatcher.h | 2 | ||||
-rw-r--r-- | services/input/InputListener.cpp | 6 | ||||
-rw-r--r-- | services/input/InputListener.h | 6 | ||||
-rw-r--r-- | services/input/InputReader.cpp | 29 | ||||
-rw-r--r-- | services/input/InputReader.h | 6 | ||||
-rw-r--r-- | services/input/tests/InputDispatcher_test.cpp | 2 | ||||
-rw-r--r-- | services/input/tests/InputReader_test.cpp | 8 | ||||
-rw-r--r-- | services/java/com/android/server/input/InputManagerService.java | 14 | ||||
-rw-r--r-- | services/jni/com_android_server_input_InputManagerService.cpp | 12 |
10 files changed, 61 insertions, 30 deletions
diff --git a/services/input/InputDispatcher.cpp b/services/input/InputDispatcher.cpp index 87a6c1b..be0cec9 100644 --- a/services/input/InputDispatcher.cpp +++ b/services/input/InputDispatcher.cpp @@ -2485,15 +2485,15 @@ bool InputDispatcher::shouldSendMotionToInputFilterLocked(const NotifyMotionArgs void InputDispatcher::notifySwitch(const NotifySwitchArgs* args) { #if DEBUG_INBOUND_EVENT_DETAILS - ALOGD("notifySwitch - eventTime=%lld, policyFlags=0x%x, switchCode=%d, switchValue=%d", + ALOGD("notifySwitch - eventTime=%lld, policyFlags=0x%x, switchValues=0x%08x, switchMask=0x%08x", args->eventTime, args->policyFlags, - args->switchCode, args->switchValue); + args->switchValues, args->switchMask); #endif uint32_t policyFlags = args->policyFlags; policyFlags |= POLICY_FLAG_TRUSTED; mPolicy->notifySwitch(args->eventTime, - args->switchCode, args->switchValue, policyFlags); + args->switchValues, args->switchMask, policyFlags); } void InputDispatcher::notifyDeviceReset(const NotifyDeviceResetArgs* args) { diff --git a/services/input/InputDispatcher.h b/services/input/InputDispatcher.h index af7ff5e..6099c43 100644 --- a/services/input/InputDispatcher.h +++ b/services/input/InputDispatcher.h @@ -248,7 +248,7 @@ public: /* Notifies the policy about switch events. */ virtual void notifySwitch(nsecs_t when, - int32_t switchCode, int32_t switchValue, uint32_t policyFlags) = 0; + uint32_t switchValues, uint32_t switchMask, uint32_t policyFlags) = 0; /* Poke user activity for an event dispatched to a window. */ virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType) = 0; diff --git a/services/input/InputListener.cpp b/services/input/InputListener.cpp index c2705b0..85bb0ed 100644 --- a/services/input/InputListener.cpp +++ b/services/input/InputListener.cpp @@ -104,14 +104,14 @@ void NotifyMotionArgs::notify(const sp<InputListenerInterface>& listener) const // --- NotifySwitchArgs --- NotifySwitchArgs::NotifySwitchArgs(nsecs_t eventTime, uint32_t policyFlags, - int32_t switchCode, int32_t switchValue) : + uint32_t switchValues, uint32_t switchMask) : eventTime(eventTime), policyFlags(policyFlags), - switchCode(switchCode), switchValue(switchValue) { + switchValues(switchValues), switchMask(switchMask) { } NotifySwitchArgs::NotifySwitchArgs(const NotifySwitchArgs& other) : eventTime(other.eventTime), policyFlags(other.policyFlags), - switchCode(other.switchCode), switchValue(other.switchValue) { + switchValues(other.switchValues), switchMask(other.switchMask) { } void NotifySwitchArgs::notify(const sp<InputListenerInterface>& listener) const { diff --git a/services/input/InputListener.h b/services/input/InputListener.h index 486852b..cd7c25a 100644 --- a/services/input/InputListener.h +++ b/services/input/InputListener.h @@ -116,13 +116,13 @@ struct NotifyMotionArgs : public NotifyArgs { struct NotifySwitchArgs : public NotifyArgs { nsecs_t eventTime; uint32_t policyFlags; - int32_t switchCode; - int32_t switchValue; + uint32_t switchValues; + uint32_t switchMask; inline NotifySwitchArgs() { } NotifySwitchArgs(nsecs_t eventTime, uint32_t policyFlags, - int32_t switchCode, int32_t switchValue); + uint32_t switchValues, uint32_t switchMask); NotifySwitchArgs(const NotifySwitchArgs& other); diff --git a/services/input/InputReader.cpp b/services/input/InputReader.cpp index d56b9a9..cebfeb4 100644 --- a/services/input/InputReader.cpp +++ b/services/input/InputReader.cpp @@ -1800,7 +1800,7 @@ void InputMapper::dumpRawAbsoluteAxisInfo(String8& dump, // --- SwitchInputMapper --- SwitchInputMapper::SwitchInputMapper(InputDevice* device) : - InputMapper(device) { + InputMapper(device), mUpdatedSwitchValues(0), mUpdatedSwitchMask(0) { } SwitchInputMapper::~SwitchInputMapper() { @@ -1813,14 +1813,33 @@ uint32_t SwitchInputMapper::getSources() { void SwitchInputMapper::process(const RawEvent* rawEvent) { switch (rawEvent->type) { case EV_SW: - processSwitch(rawEvent->when, rawEvent->code, rawEvent->value); + processSwitch(rawEvent->code, rawEvent->value); break; + + case EV_SYN: + if (rawEvent->code == SYN_REPORT) { + sync(rawEvent->when); + } } } -void SwitchInputMapper::processSwitch(nsecs_t when, int32_t switchCode, int32_t switchValue) { - NotifySwitchArgs args(when, 0, switchCode, switchValue); - getListener()->notifySwitch(&args); +void SwitchInputMapper::processSwitch(int32_t switchCode, int32_t switchValue) { + if (switchCode >= 0 && switchCode < 32) { + if (switchValue) { + mUpdatedSwitchValues |= 1 << switchCode; + } + mUpdatedSwitchMask |= 1 << switchCode; + } +} + +void SwitchInputMapper::sync(nsecs_t when) { + if (mUpdatedSwitchMask) { + NotifySwitchArgs args(when, 0, mUpdatedSwitchValues, mUpdatedSwitchMask); + getListener()->notifySwitch(&args); + + mUpdatedSwitchValues = 0; + mUpdatedSwitchMask = 0; + } } int32_t SwitchInputMapper::getSwitchState(uint32_t sourceMask, int32_t switchCode) { diff --git a/services/input/InputReader.h b/services/input/InputReader.h index e1a8dd8..61b21e2 100644 --- a/services/input/InputReader.h +++ b/services/input/InputReader.h @@ -962,7 +962,11 @@ public: virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode); private: - void processSwitch(nsecs_t when, int32_t switchCode, int32_t switchValue); + uint32_t mUpdatedSwitchValues; + uint32_t mUpdatedSwitchMask; + + void processSwitch(int32_t switchCode, int32_t switchValue); + void sync(nsecs_t when); }; diff --git a/services/input/tests/InputDispatcher_test.cpp b/services/input/tests/InputDispatcher_test.cpp index 961566f..ed2b4a5 100644 --- a/services/input/tests/InputDispatcher_test.cpp +++ b/services/input/tests/InputDispatcher_test.cpp @@ -86,7 +86,7 @@ private: } virtual void notifySwitch(nsecs_t when, - int32_t switchCode, int32_t switchValue, uint32_t policyFlags) { + uint32_t switchValues, uint32_t switchMask, uint32_t policyFlags) { } virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType) { diff --git a/services/input/tests/InputReader_test.cpp b/services/input/tests/InputReader_test.cpp index c6dbbf3..14065d2 100644 --- a/services/input/tests/InputReader_test.cpp +++ b/services/input/tests/InputReader_test.cpp @@ -1493,12 +1493,16 @@ TEST_F(SwitchInputMapperTest, Process) { addMapperAndConfigure(mapper); process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SW, SW_LID, 1); + process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SW, SW_JACK_PHYSICAL_INSERT, 1); + process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SW, SW_HEADPHONE_INSERT, 0); + process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0); NotifySwitchArgs args; ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifySwitchWasCalled(&args)); ASSERT_EQ(ARBITRARY_TIME, args.eventTime); - ASSERT_EQ(SW_LID, args.switchCode); - ASSERT_EQ(1, args.switchValue); + ASSERT_EQ((1 << SW_LID) | (1 << SW_JACK_PHYSICAL_INSERT), args.switchValues); + ASSERT_EQ((1 << SW_LID) | (1 << SW_JACK_PHYSICAL_INSERT) | (1 << SW_HEADPHONE_INSERT), + args.switchMask); ASSERT_EQ(uint32_t(0), args.policyFlags); } diff --git a/services/java/com/android/server/input/InputManagerService.java b/services/java/com/android/server/input/InputManagerService.java index 0b4a721..7b0c452 100644 --- a/services/java/com/android/server/input/InputManagerService.java +++ b/services/java/com/android/server/input/InputManagerService.java @@ -1238,11 +1238,15 @@ public class InputManagerService extends IInputManager.Stub } // Native callback. - private void notifySwitch(long whenNanos, int switchCode, int switchValue) { - switch (switchCode) { - case SW_LID: - mWindowManagerCallbacks.notifyLidSwitchChanged(whenNanos, switchValue == 0); - break; + private void notifySwitch(long whenNanos, int switchValues, int switchMask) { + if (DEBUG) { + Slog.d(TAG, "notifySwitch: values=" + Integer.toHexString(switchValues) + + ", mask=" + Integer.toHexString(switchMask)); + } + + if ((switchMask & (1 << SW_LID)) != 0) { + final boolean lidOpen = ((switchValues & (1 << SW_LID)) == 0); + mWindowManagerCallbacks.notifyLidSwitchChanged(whenNanos, lidOpen); } } diff --git a/services/jni/com_android_server_input_InputManagerService.cpp b/services/jni/com_android_server_input_InputManagerService.cpp index 319cacd..a97becf 100644 --- a/services/jni/com_android_server_input_InputManagerService.cpp +++ b/services/jni/com_android_server_input_InputManagerService.cpp @@ -187,7 +187,7 @@ public: /* --- InputDispatcherPolicyInterface implementation --- */ - virtual void notifySwitch(nsecs_t when, int32_t switchCode, int32_t switchValue, + virtual void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask, uint32_t policyFlags); virtual void notifyConfigurationChanged(nsecs_t when); virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle, @@ -527,17 +527,17 @@ String8 NativeInputManager::getDeviceAlias(const InputDeviceIdentifier& identifi return result; } -void NativeInputManager::notifySwitch(nsecs_t when, int32_t switchCode, - int32_t switchValue, uint32_t policyFlags) { +void NativeInputManager::notifySwitch(nsecs_t when, + uint32_t switchValues, uint32_t switchMask, uint32_t policyFlags) { #if DEBUG_INPUT_DISPATCHER_POLICY - ALOGD("notifySwitch - when=%lld, switchCode=%d, switchValue=%d, policyFlags=0x%x", - when, switchCode, switchValue, policyFlags); + ALOGD("notifySwitch - when=%lld, switchValues=0x%08x, switchMask=0x%08x, policyFlags=0x%x", + when, switchValues, switchMask, policyFlags); #endif JNIEnv* env = jniEnv(); env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifySwitch, - when, switchCode, switchValue); + when, switchValues, switchMask); checkAndClearExceptionFromCallback(env, "notifySwitch"); } |