Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a7ed637b authored by Henry Barnor's avatar Henry Barnor
Browse files

Wake device from alphanumeric keyboards

Internal alphanumeric keyboards used to not wake the device by default.
This changes the behavior such that any key down from an alphanumeric
keyboard should wake the device.

Bug: 352856881
Test: atest inputflinger_test
Test: m checkinput
Test: Manually on device
Flag: com.android.input.flags.enable_alphabetic_keyboard_wake
Change-Id: I368bb09972d109e115cbb2063e40cf3a7e395922
parent 2a10ab9b
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -214,3 +214,13 @@ flag {
  description: "Set input device's power/wakeup sysfs node"
  bug: "372812925"
}

flag {
  name: "enable_alphabetic_keyboard_wake"
  namespace: "input"
  description: "Enable wake from alphabetic keyboards."
  bug: "352856881"
  metadata {
    purpose: PURPOSE_BUGFIX
  }
}
+9 −3
Original line number Diff line number Diff line
@@ -344,12 +344,14 @@ std::list<NotifyArgs> KeyboardInputMapper::processKey(nsecs_t when, nsecs_t read
    }

    KeyboardType keyboardType = getDeviceContext().getKeyboardType();
    // Any key down on an external keyboard should wake the device.
    // We don't do this for internal keyboards to prevent them from waking up in your pocket.
    // Any key down on an external keyboard or internal alphanumeric keyboard should wake the
    // device. We don't do this for non-alphanumeric internal keyboards to prevent them from
    // waking up in your pocket.
    // 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.
    if (down && getDeviceContext().isExternal() && !mParameters.doNotWakeByDefault &&
    if (down && !mParameters.doNotWakeByDefault &&
        (getDeviceContext().isExternal() || wakeOnAlphabeticKeyboard(keyboardType)) &&
        !(keyboardType != KeyboardType::ALPHABETIC && isMediaKey(keyCode))) {
        policyFlags |= POLICY_FLAG_WAKE;
    }
@@ -507,4 +509,8 @@ uint32_t KeyboardInputMapper::getEventSource() const {
    return deviceSources & ALL_KEYBOARD_SOURCES;
}

bool KeyboardInputMapper::wakeOnAlphabeticKeyboard(const KeyboardType keyboardType) const {
    return mEnableAlphabeticKeyboardWakeFlag && (KeyboardType::ALPHABETIC == keyboardType);
}

} // namespace android
+8 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

#pragma once

#include <com_android_input_flags.h>

#include "HidUsageAccumulator.h"
#include "InputMapper.h"

@@ -85,6 +87,10 @@ private:
        bool doNotWakeByDefault{};
    } mParameters{};

    // Store the value of enable wake for alphanumeric keyboard flag.
    const bool mEnableAlphabeticKeyboardWakeFlag =
            com::android::input::flags::enable_alphabetic_keyboard_wake();

    KeyboardInputMapper(InputDeviceContext& deviceContext,
                        const InputReaderConfiguration& readerConfig, uint32_t source);
    void configureParameters();
@@ -109,6 +115,8 @@ private:
    [[nodiscard]] std::list<NotifyArgs> cancelAllDownKeys(nsecs_t when);
    void onKeyDownProcessed(nsecs_t downTime);
    uint32_t getEventSource() const;

    bool wakeOnAlphabeticKeyboard(const KeyboardType keyboardType) const;
};

} // namespace android
+39 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@
#include <UinputDevice.h>
#include <android-base/thread_annotations.h>
#include <com_android_input_flags.h>
#include <flag_macros.h>
#include <ftl/enum.h>
#include <gtest/gtest.h>
#include <ui/Rotation.h>
@@ -4019,6 +4020,44 @@ TEST_F(KeyboardInputMapperTest, Process_GesureEventToSetFlagKeepTouchMode) {
    ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_KEEP_TOUCH_MODE, args.flags);
}

TEST_F_WITH_FLAGS(KeyboardInputMapperTest, WakeBehavior_AlphabeticKeyboard,
                  REQUIRES_FLAGS_ENABLED(ACONFIG_FLAG(com::android::input::flags,
                                                      enable_alphabetic_keyboard_wake))) {
    // For internal alphabetic devices, keys will trigger wake on key down.

    mFakeEventHub->addKey(EVENTHUB_ID, KEY_A, 0, AKEYCODE_A, 0);
    mFakeEventHub->addKey(EVENTHUB_ID, KEY_HOME, 0, AKEYCODE_HOME, 0);
    mFakeEventHub->addKey(EVENTHUB_ID, KEY_PLAYPAUSE, 0, AKEYCODE_MEDIA_PLAY_PAUSE, 0);

    KeyboardInputMapper& mapper =
            constructAndAddMapper<KeyboardInputMapper>(AINPUT_SOURCE_KEYBOARD);

    process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_A, 1);
    NotifyKeyArgs args;
    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
    ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags);

    process(mapper, ARBITRARY_TIME + 1, READ_TIME, EV_KEY, KEY_A, 0);
    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
    ASSERT_EQ(uint32_t(0), args.policyFlags);

    process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_HOME, 1);
    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
    ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags);

    process(mapper, ARBITRARY_TIME + 1, READ_TIME, EV_KEY, KEY_HOME, 0);
    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
    ASSERT_EQ(uint32_t(0), args.policyFlags);

    process(mapper, ARBITRARY_TIME, READ_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, READ_TIME, EV_KEY, KEY_PLAYPAUSE, 0);
    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
    ASSERT_EQ(uint32_t(0), args.policyFlags);
}

/**
 * When there is more than one KeyboardInputMapper for an InputDevice, each mapper should produce
 * events that use the shared keyboard source across all mappers. This is to ensure that each