Loading include/input/InputEventLabels.h +5 −6 Original line number Diff line number Diff line Loading @@ -405,13 +405,12 @@ static const InputEventLabel LEDS[] = { { nullptr, 0 } }; static const InputEventLabel FLAGS[] = { DEFINE_FLAG(VIRTUAL), static const InputEventLabel FLAGS[] = {DEFINE_FLAG(VIRTUAL), DEFINE_FLAG(FUNCTION), DEFINE_FLAG(GESTURE), DEFINE_FLAG(WAKE), { nullptr, 0 } }; {nullptr, 0}}; static int lookupValueByLabel(const char* literal, const InputEventLabel *list) { while (list->literal) { Loading services/inputflinger/reader/mapper/KeyboardInputMapper.cpp +8 −3 Original line number Diff line number Diff line Loading @@ -183,6 +183,9 @@ void KeyboardInputMapper::configureParameters() { mParameters.handlesKeyRepeat = false; config.tryGetProperty(String8("keyboard.handlesKeyRepeat"), mParameters.handlesKeyRepeat); mParameters.doNotWakeByDefault = false; config.tryGetProperty(String8("keyboard.doNotWakeByDefault"), mParameters.doNotWakeByDefault); } void KeyboardInputMapper::dumpParameters(std::string& dump) { Loading Loading @@ -331,10 +334,12 @@ void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t scanCode, // Key down on external an keyboard should wake the device. // We don't do this for internal keyboards to prevent them from waking up in your pocket. // For internal keyboards, the key layout file should specify the policy flags for // each wake key individually. // For internal keyboards and devices for which the default wake behavior is explicitly // prevented (e.g. TV remotes), the key layout file should specify the policy flags for each // wake key individually. // TODO: Use the input device configuration to control this behavior more finely. if (down && getDevice()->isExternal() && !isMediaKey(keyCode)) { if (down && getDevice()->isExternal() && !mParameters.doNotWakeByDefault && !isMediaKey(keyCode)) { policyFlags |= POLICY_FLAG_WAKE; } Loading services/inputflinger/reader/mapper/KeyboardInputMapper.h +1 −0 Original line number Diff line number Diff line Loading @@ -73,6 +73,7 @@ private: struct Parameters { bool orientationAware; bool handlesKeyRepeat; bool doNotWakeByDefault; } mParameters; void configureParameters(); Loading services/inputflinger/tests/InputReader_test.cpp +78 −0 Original line number Diff line number Diff line Loading @@ -2580,6 +2580,84 @@ TEST_F(KeyboardInputMapperTest, Configure_AssignsDisplayPort) { AKEYCODE_DPAD_LEFT, newDisplayId)); } TEST_F(KeyboardInputMapperTest, ExternalDevice_WakeBehavior) { // For external devices, non-media keys will trigger wake on key down. Media keys need to be // marked as WAKE in the keylayout file to trigger wake. mDevice->setExternal(true); mFakeEventHub->addKey(DEVICE_ID, KEY_HOME, 0, AKEYCODE_HOME, 0); mFakeEventHub->addKey(DEVICE_ID, KEY_PLAY, 0, AKEYCODE_MEDIA_PLAY, 0); mFakeEventHub->addKey(DEVICE_ID, KEY_PLAYPAUSE, 0, AKEYCODE_MEDIA_PLAY_PAUSE, POLICY_FLAG_WAKE); KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); addMapperAndConfigure(mapper); process(mapper, ARBITRARY_TIME, EV_KEY, KEY_HOME, 1); NotifyKeyArgs args; ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags); process(mapper, ARBITRARY_TIME + 1, EV_KEY, KEY_HOME, 0); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); ASSERT_EQ(uint32_t(0), args.policyFlags); process(mapper, ARBITRARY_TIME, EV_KEY, KEY_PLAY, 1); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); ASSERT_EQ(uint32_t(0), args.policyFlags); process(mapper, ARBITRARY_TIME + 1, EV_KEY, KEY_PLAY, 0); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); ASSERT_EQ(uint32_t(0), args.policyFlags); process(mapper, ARBITRARY_TIME, EV_KEY, KEY_PLAYPAUSE, 1); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags); process(mapper, ARBITRARY_TIME + 1, EV_KEY, KEY_PLAYPAUSE, 0); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags); } TEST_F(KeyboardInputMapperTest, ExternalDevice_DoNotWakeByDefaultBehavior) { // Tv Remote key's wake behavior is prescribed by the keylayout file. mDevice->setExternal(true); mFakeEventHub->addKey(DEVICE_ID, KEY_HOME, 0, AKEYCODE_HOME, POLICY_FLAG_WAKE); mFakeEventHub->addKey(DEVICE_ID, KEY_DOWN, 0, AKEYCODE_DPAD_DOWN, 0); mFakeEventHub->addKey(DEVICE_ID, KEY_PLAY, 0, AKEYCODE_MEDIA_PLAY, POLICY_FLAG_WAKE); KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); addConfigurationProperty("keyboard.doNotWakeByDefault", "1"); addMapperAndConfigure(mapper); process(mapper, ARBITRARY_TIME, EV_KEY, KEY_HOME, 1); NotifyKeyArgs args; ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags); process(mapper, ARBITRARY_TIME + 1, EV_KEY, KEY_HOME, 0); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags); process(mapper, ARBITRARY_TIME, EV_KEY, KEY_DOWN, 1); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); ASSERT_EQ(uint32_t(0), args.policyFlags); process(mapper, ARBITRARY_TIME + 1, EV_KEY, KEY_DOWN, 0); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); ASSERT_EQ(uint32_t(0), args.policyFlags); process(mapper, ARBITRARY_TIME, EV_KEY, KEY_PLAY, 1); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags); process(mapper, ARBITRARY_TIME + 1, EV_KEY, KEY_PLAY, 0); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags); } // --- CursorInputMapperTest --- class CursorInputMapperTest : public InputMapperTest { Loading Loading
include/input/InputEventLabels.h +5 −6 Original line number Diff line number Diff line Loading @@ -405,13 +405,12 @@ static const InputEventLabel LEDS[] = { { nullptr, 0 } }; static const InputEventLabel FLAGS[] = { DEFINE_FLAG(VIRTUAL), static const InputEventLabel FLAGS[] = {DEFINE_FLAG(VIRTUAL), DEFINE_FLAG(FUNCTION), DEFINE_FLAG(GESTURE), DEFINE_FLAG(WAKE), { nullptr, 0 } }; {nullptr, 0}}; static int lookupValueByLabel(const char* literal, const InputEventLabel *list) { while (list->literal) { Loading
services/inputflinger/reader/mapper/KeyboardInputMapper.cpp +8 −3 Original line number Diff line number Diff line Loading @@ -183,6 +183,9 @@ void KeyboardInputMapper::configureParameters() { mParameters.handlesKeyRepeat = false; config.tryGetProperty(String8("keyboard.handlesKeyRepeat"), mParameters.handlesKeyRepeat); mParameters.doNotWakeByDefault = false; config.tryGetProperty(String8("keyboard.doNotWakeByDefault"), mParameters.doNotWakeByDefault); } void KeyboardInputMapper::dumpParameters(std::string& dump) { Loading Loading @@ -331,10 +334,12 @@ void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t scanCode, // Key down on external an keyboard should wake the device. // We don't do this for internal keyboards to prevent them from waking up in your pocket. // For internal keyboards, the key layout file should specify the policy flags for // each wake key individually. // For internal keyboards and devices for which the default wake behavior is explicitly // prevented (e.g. TV remotes), the key layout file should specify the policy flags for each // wake key individually. // TODO: Use the input device configuration to control this behavior more finely. if (down && getDevice()->isExternal() && !isMediaKey(keyCode)) { if (down && getDevice()->isExternal() && !mParameters.doNotWakeByDefault && !isMediaKey(keyCode)) { policyFlags |= POLICY_FLAG_WAKE; } Loading
services/inputflinger/reader/mapper/KeyboardInputMapper.h +1 −0 Original line number Diff line number Diff line Loading @@ -73,6 +73,7 @@ private: struct Parameters { bool orientationAware; bool handlesKeyRepeat; bool doNotWakeByDefault; } mParameters; void configureParameters(); Loading
services/inputflinger/tests/InputReader_test.cpp +78 −0 Original line number Diff line number Diff line Loading @@ -2580,6 +2580,84 @@ TEST_F(KeyboardInputMapperTest, Configure_AssignsDisplayPort) { AKEYCODE_DPAD_LEFT, newDisplayId)); } TEST_F(KeyboardInputMapperTest, ExternalDevice_WakeBehavior) { // For external devices, non-media keys will trigger wake on key down. Media keys need to be // marked as WAKE in the keylayout file to trigger wake. mDevice->setExternal(true); mFakeEventHub->addKey(DEVICE_ID, KEY_HOME, 0, AKEYCODE_HOME, 0); mFakeEventHub->addKey(DEVICE_ID, KEY_PLAY, 0, AKEYCODE_MEDIA_PLAY, 0); mFakeEventHub->addKey(DEVICE_ID, KEY_PLAYPAUSE, 0, AKEYCODE_MEDIA_PLAY_PAUSE, POLICY_FLAG_WAKE); KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); addMapperAndConfigure(mapper); process(mapper, ARBITRARY_TIME, EV_KEY, KEY_HOME, 1); NotifyKeyArgs args; ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags); process(mapper, ARBITRARY_TIME + 1, EV_KEY, KEY_HOME, 0); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); ASSERT_EQ(uint32_t(0), args.policyFlags); process(mapper, ARBITRARY_TIME, EV_KEY, KEY_PLAY, 1); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); ASSERT_EQ(uint32_t(0), args.policyFlags); process(mapper, ARBITRARY_TIME + 1, EV_KEY, KEY_PLAY, 0); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); ASSERT_EQ(uint32_t(0), args.policyFlags); process(mapper, ARBITRARY_TIME, EV_KEY, KEY_PLAYPAUSE, 1); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags); process(mapper, ARBITRARY_TIME + 1, EV_KEY, KEY_PLAYPAUSE, 0); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags); } TEST_F(KeyboardInputMapperTest, ExternalDevice_DoNotWakeByDefaultBehavior) { // Tv Remote key's wake behavior is prescribed by the keylayout file. mDevice->setExternal(true); mFakeEventHub->addKey(DEVICE_ID, KEY_HOME, 0, AKEYCODE_HOME, POLICY_FLAG_WAKE); mFakeEventHub->addKey(DEVICE_ID, KEY_DOWN, 0, AKEYCODE_DPAD_DOWN, 0); mFakeEventHub->addKey(DEVICE_ID, KEY_PLAY, 0, AKEYCODE_MEDIA_PLAY, POLICY_FLAG_WAKE); KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice, AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); addConfigurationProperty("keyboard.doNotWakeByDefault", "1"); addMapperAndConfigure(mapper); process(mapper, ARBITRARY_TIME, EV_KEY, KEY_HOME, 1); NotifyKeyArgs args; ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags); process(mapper, ARBITRARY_TIME + 1, EV_KEY, KEY_HOME, 0); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags); process(mapper, ARBITRARY_TIME, EV_KEY, KEY_DOWN, 1); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); ASSERT_EQ(uint32_t(0), args.policyFlags); process(mapper, ARBITRARY_TIME + 1, EV_KEY, KEY_DOWN, 0); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); ASSERT_EQ(uint32_t(0), args.policyFlags); process(mapper, ARBITRARY_TIME, EV_KEY, KEY_PLAY, 1); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags); process(mapper, ARBITRARY_TIME + 1, EV_KEY, KEY_PLAY, 0); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags); } // --- CursorInputMapperTest --- class CursorInputMapperTest : public InputMapperTest { Loading