Skip to content

Commit bcc046a

Browse files
author
Jeff Brown
committed
Bundle correlated switch changes atomically.
This is a prerequisite for headset jack detection on Manta. Bug: 6548391 Change-Id: I549a194344511c0cee578b00f6a9ab5fdbdfb99c
1 parent 580ee8b commit bcc046a

File tree

10 files changed

+61
-30
lines changed

10 files changed

+61
-30
lines changed

services/input/InputDispatcher.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2485,15 +2485,15 @@ bool InputDispatcher::shouldSendMotionToInputFilterLocked(const NotifyMotionArgs
24852485

24862486
void InputDispatcher::notifySwitch(const NotifySwitchArgs* args) {
24872487
#if DEBUG_INBOUND_EVENT_DETAILS
2488-
ALOGD("notifySwitch - eventTime=%lld, policyFlags=0x%x, switchCode=%d, switchValue=%d",
2488+
ALOGD("notifySwitch - eventTime=%lld, policyFlags=0x%x, switchValues=0x%08x, switchMask=0x%08x",
24892489
args->eventTime, args->policyFlags,
2490-
args->switchCode, args->switchValue);
2490+
args->switchValues, args->switchMask);
24912491
#endif
24922492

24932493
uint32_t policyFlags = args->policyFlags;
24942494
policyFlags |= POLICY_FLAG_TRUSTED;
24952495
mPolicy->notifySwitch(args->eventTime,
2496-
args->switchCode, args->switchValue, policyFlags);
2496+
args->switchValues, args->switchMask, policyFlags);
24972497
}
24982498

24992499
void InputDispatcher::notifyDeviceReset(const NotifyDeviceResetArgs* args) {

services/input/InputDispatcher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class InputDispatcherPolicyInterface : public virtual RefBase {
248248
/* Notifies the policy about switch events.
249249
*/
250250
virtual void notifySwitch(nsecs_t when,
251-
int32_t switchCode, int32_t switchValue, uint32_t policyFlags) = 0;
251+
uint32_t switchValues, uint32_t switchMask, uint32_t policyFlags) = 0;
252252

253253
/* Poke user activity for an event dispatched to a window. */
254254
virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType) = 0;

services/input/InputListener.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ void NotifyMotionArgs::notify(const sp<InputListenerInterface>& listener) const
104104
// --- NotifySwitchArgs ---
105105

106106
NotifySwitchArgs::NotifySwitchArgs(nsecs_t eventTime, uint32_t policyFlags,
107-
int32_t switchCode, int32_t switchValue) :
107+
uint32_t switchValues, uint32_t switchMask) :
108108
eventTime(eventTime), policyFlags(policyFlags),
109-
switchCode(switchCode), switchValue(switchValue) {
109+
switchValues(switchValues), switchMask(switchMask) {
110110
}
111111

112112
NotifySwitchArgs::NotifySwitchArgs(const NotifySwitchArgs& other) :
113113
eventTime(other.eventTime), policyFlags(other.policyFlags),
114-
switchCode(other.switchCode), switchValue(other.switchValue) {
114+
switchValues(other.switchValues), switchMask(other.switchMask) {
115115
}
116116

117117
void NotifySwitchArgs::notify(const sp<InputListenerInterface>& listener) const {

services/input/InputListener.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ struct NotifyMotionArgs : public NotifyArgs {
116116
struct NotifySwitchArgs : public NotifyArgs {
117117
nsecs_t eventTime;
118118
uint32_t policyFlags;
119-
int32_t switchCode;
120-
int32_t switchValue;
119+
uint32_t switchValues;
120+
uint32_t switchMask;
121121

122122
inline NotifySwitchArgs() { }
123123

124124
NotifySwitchArgs(nsecs_t eventTime, uint32_t policyFlags,
125-
int32_t switchCode, int32_t switchValue);
125+
uint32_t switchValues, uint32_t switchMask);
126126

127127
NotifySwitchArgs(const NotifySwitchArgs& other);
128128

services/input/InputReader.cpp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,7 +1800,7 @@ void InputMapper::dumpRawAbsoluteAxisInfo(String8& dump,
18001800
// --- SwitchInputMapper ---
18011801

18021802
SwitchInputMapper::SwitchInputMapper(InputDevice* device) :
1803-
InputMapper(device) {
1803+
InputMapper(device), mUpdatedSwitchValues(0), mUpdatedSwitchMask(0) {
18041804
}
18051805

18061806
SwitchInputMapper::~SwitchInputMapper() {
@@ -1813,14 +1813,33 @@ uint32_t SwitchInputMapper::getSources() {
18131813
void SwitchInputMapper::process(const RawEvent* rawEvent) {
18141814
switch (rawEvent->type) {
18151815
case EV_SW:
1816-
processSwitch(rawEvent->when, rawEvent->code, rawEvent->value);
1816+
processSwitch(rawEvent->code, rawEvent->value);
18171817
break;
1818+
1819+
case EV_SYN:
1820+
if (rawEvent->code == SYN_REPORT) {
1821+
sync(rawEvent->when);
1822+
}
18181823
}
18191824
}
18201825

1821-
void SwitchInputMapper::processSwitch(nsecs_t when, int32_t switchCode, int32_t switchValue) {
1822-
NotifySwitchArgs args(when, 0, switchCode, switchValue);
1823-
getListener()->notifySwitch(&args);
1826+
void SwitchInputMapper::processSwitch(int32_t switchCode, int32_t switchValue) {
1827+
if (switchCode >= 0 && switchCode < 32) {
1828+
if (switchValue) {
1829+
mUpdatedSwitchValues |= 1 << switchCode;
1830+
}
1831+
mUpdatedSwitchMask |= 1 << switchCode;
1832+
}
1833+
}
1834+
1835+
void SwitchInputMapper::sync(nsecs_t when) {
1836+
if (mUpdatedSwitchMask) {
1837+
NotifySwitchArgs args(when, 0, mUpdatedSwitchValues, mUpdatedSwitchMask);
1838+
getListener()->notifySwitch(&args);
1839+
1840+
mUpdatedSwitchValues = 0;
1841+
mUpdatedSwitchMask = 0;
1842+
}
18241843
}
18251844

18261845
int32_t SwitchInputMapper::getSwitchState(uint32_t sourceMask, int32_t switchCode) {

services/input/InputReader.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,11 @@ class SwitchInputMapper : public InputMapper {
962962
virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
963963

964964
private:
965-
void processSwitch(nsecs_t when, int32_t switchCode, int32_t switchValue);
965+
uint32_t mUpdatedSwitchValues;
966+
uint32_t mUpdatedSwitchMask;
967+
968+
void processSwitch(int32_t switchCode, int32_t switchValue);
969+
void sync(nsecs_t when);
966970
};
967971

968972

services/input/tests/InputDispatcher_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class FakeInputDispatcherPolicy : public InputDispatcherPolicyInterface {
8686
}
8787

8888
virtual void notifySwitch(nsecs_t when,
89-
int32_t switchCode, int32_t switchValue, uint32_t policyFlags) {
89+
uint32_t switchValues, uint32_t switchMask, uint32_t policyFlags) {
9090
}
9191

9292
virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType) {

services/input/tests/InputReader_test.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,12 +1493,16 @@ TEST_F(SwitchInputMapperTest, Process) {
14931493
addMapperAndConfigure(mapper);
14941494

14951495
process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SW, SW_LID, 1);
1496+
process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SW, SW_JACK_PHYSICAL_INSERT, 1);
1497+
process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SW, SW_HEADPHONE_INSERT, 0);
1498+
process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
14961499

14971500
NotifySwitchArgs args;
14981501
ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifySwitchWasCalled(&args));
14991502
ASSERT_EQ(ARBITRARY_TIME, args.eventTime);
1500-
ASSERT_EQ(SW_LID, args.switchCode);
1501-
ASSERT_EQ(1, args.switchValue);
1503+
ASSERT_EQ((1 << SW_LID) | (1 << SW_JACK_PHYSICAL_INSERT), args.switchValues);
1504+
ASSERT_EQ((1 << SW_LID) | (1 << SW_JACK_PHYSICAL_INSERT) | (1 << SW_HEADPHONE_INSERT),
1505+
args.switchMask);
15021506
ASSERT_EQ(uint32_t(0), args.policyFlags);
15031507
}
15041508

services/java/com/android/server/input/InputManagerService.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,11 +1238,15 @@ private void notifyInputDevicesChanged(InputDevice[] inputDevices) {
12381238
}
12391239

12401240
// Native callback.
1241-
private void notifySwitch(long whenNanos, int switchCode, int switchValue) {
1242-
switch (switchCode) {
1243-
case SW_LID:
1244-
mWindowManagerCallbacks.notifyLidSwitchChanged(whenNanos, switchValue == 0);
1245-
break;
1241+
private void notifySwitch(long whenNanos, int switchValues, int switchMask) {
1242+
if (DEBUG) {
1243+
Slog.d(TAG, "notifySwitch: values=" + Integer.toHexString(switchValues)
1244+
+ ", mask=" + Integer.toHexString(switchMask));
1245+
}
1246+
1247+
if ((switchMask & (1 << SW_LID)) != 0) {
1248+
final boolean lidOpen = ((switchValues & (1 << SW_LID)) == 0);
1249+
mWindowManagerCallbacks.notifyLidSwitchChanged(whenNanos, lidOpen);
12461250
}
12471251
}
12481252

services/jni/com_android_server_input_InputManagerService.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class NativeInputManager : public virtual RefBase,
187187

188188
/* --- InputDispatcherPolicyInterface implementation --- */
189189

190-
virtual void notifySwitch(nsecs_t when, int32_t switchCode, int32_t switchValue,
190+
virtual void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask,
191191
uint32_t policyFlags);
192192
virtual void notifyConfigurationChanged(nsecs_t when);
193193
virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
@@ -527,17 +527,17 @@ String8 NativeInputManager::getDeviceAlias(const InputDeviceIdentifier& identifi
527527
return result;
528528
}
529529

530-
void NativeInputManager::notifySwitch(nsecs_t when, int32_t switchCode,
531-
int32_t switchValue, uint32_t policyFlags) {
530+
void NativeInputManager::notifySwitch(nsecs_t when,
531+
uint32_t switchValues, uint32_t switchMask, uint32_t policyFlags) {
532532
#if DEBUG_INPUT_DISPATCHER_POLICY
533-
ALOGD("notifySwitch - when=%lld, switchCode=%d, switchValue=%d, policyFlags=0x%x",
534-
when, switchCode, switchValue, policyFlags);
533+
ALOGD("notifySwitch - when=%lld, switchValues=0x%08x, switchMask=0x%08x, policyFlags=0x%x",
534+
when, switchValues, switchMask, policyFlags);
535535
#endif
536536

537537
JNIEnv* env = jniEnv();
538538

539539
env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifySwitch,
540-
when, switchCode, switchValue);
540+
when, switchValues, switchMask);
541541
checkAndClearExceptionFromCallback(env, "notifySwitch");
542542
}
543543

0 commit comments

Comments
 (0)