Input: Support set power/wakeup node of device
power/wakeup attribute allows the userspace to check
if the device is enabled to wake up the kernel from
sleep states. Devices support "wakeup" events can send
hardware signal to resume systems.
This change follows kernel doc:
"In that cases the user space can change the setting
represented by the contents of this file by writing
either "enabled", or "disabled" to it."
DD: go/configure-al-kernel-wake
Bug: 372812925
Test: atest inputflinger_tests
Test: Plug in USB mouse with the set of changes:
power/wakeup of mouse becomes enabled and it can wake
up from "echo mem > /sys/power/state".
Flag: com.android.input.flags.set_input_device_kernel_wake
Change-Id: I188c34cc645e9582d35a00a267653a0ca9c1da6e
diff --git a/services/inputflinger/tests/FakeEventHub.cpp b/services/inputflinger/tests/FakeEventHub.cpp
index 943de6e..e72c440 100644
--- a/services/inputflinger/tests/FakeEventHub.cpp
+++ b/services/inputflinger/tests/FakeEventHub.cpp
@@ -650,4 +650,25 @@
}
}
+bool FakeEventHub::setKernelWakeEnabled(int32_t deviceId, bool enabled) {
+ Device* device = getDevice(deviceId);
+ if (device == nullptr) {
+ return false;
+ }
+ mKernelWakeup.emplace(deviceId, enabled);
+ return true;
+}
+
+bool FakeEventHub::fakeReadKernelWakeup(int32_t deviceId) const {
+ Device* device = getDevice(deviceId);
+ if (device == nullptr) {
+ return false;
+ }
+ auto it = mKernelWakeup.find(deviceId);
+ if (it == mKernelWakeup.end()) {
+ return false;
+ }
+ return it->second;
+}
+
} // namespace android
diff --git a/services/inputflinger/tests/FakeEventHub.h b/services/inputflinger/tests/FakeEventHub.h
index 2dfbb23..143b93b 100644
--- a/services/inputflinger/tests/FakeEventHub.h
+++ b/services/inputflinger/tests/FakeEventHub.h
@@ -94,6 +94,8 @@
// Simulates a device light intensities, from light id to light intensities map.
std::unordered_map<int32_t /* lightId */, std::unordered_map<LightColor, int32_t>>
mLightIntensities;
+ // fake sysfs node path and value.
+ std::unordered_map<int32_t /*deviceId*/, bool /* wakeupNode*/> mKernelWakeup;
public:
static constexpr int32_t DEFAULT_BATTERY = 1;
@@ -158,6 +160,8 @@
void setMtSlotValues(int32_t deviceId, int32_t axis, const std::vector<int32_t>& values);
base::Result<std::vector<int32_t>> getMtSlotValues(int32_t deviceId, int32_t axis,
size_t slotCount) const override;
+ bool setKernelWakeEnabled(int32_t deviceId, bool enabled) override;
+ bool fakeReadKernelWakeup(int32_t deviceId) const;
private:
Device* getDevice(int32_t deviceId) const;
diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp
index 6c8b65c..19b738e 100644
--- a/services/inputflinger/tests/InputReader_test.cpp
+++ b/services/inputflinger/tests/InputReader_test.cpp
@@ -1392,6 +1392,20 @@
ASSERT_EQ(mReader->getLightColor(deviceId, /*lightId=*/1), LIGHT_BRIGHTNESS);
}
+TEST_F(InputReaderTest, SetPowerWakeUp) {
+ ASSERT_NO_FATAL_FAILURE(addDevice(1, "1st", InputDeviceClass::KEYBOARD, nullptr));
+ ASSERT_NO_FATAL_FAILURE(addDevice(2, "2nd", InputDeviceClass::KEYBOARD, nullptr));
+ ASSERT_NO_FATAL_FAILURE(addDevice(3, "3rd", InputDeviceClass::KEYBOARD, nullptr));
+
+ ASSERT_EQ(mFakeEventHub->fakeReadKernelWakeup(1), false);
+
+ ASSERT_TRUE(mFakeEventHub->setKernelWakeEnabled(2, true));
+ ASSERT_EQ(mFakeEventHub->fakeReadKernelWakeup(2), true);
+
+ ASSERT_TRUE(mFakeEventHub->setKernelWakeEnabled(3, false));
+ ASSERT_EQ(mFakeEventHub->fakeReadKernelWakeup(3), false);
+}
+
// --- InputReaderIntegrationTest ---
// These tests create and interact with the InputReader only through its interface.
diff --git a/services/inputflinger/tests/InterfaceMocks.h b/services/inputflinger/tests/InterfaceMocks.h
index a43e4e4..25e2b45 100644
--- a/services/inputflinger/tests/InterfaceMocks.h
+++ b/services/inputflinger/tests/InterfaceMocks.h
@@ -180,6 +180,7 @@
MOCK_METHOD(status_t, enableDevice, (int32_t deviceId), (override));
MOCK_METHOD(status_t, disableDevice, (int32_t deviceId), (override));
MOCK_METHOD(void, sysfsNodeChanged, (const std::string& sysfsNodePath), (override));
+ MOCK_METHOD(bool, setKernelWakeEnabled, (int32_t deviceId, bool enabled), (override));
};
class MockPointerChoreographerPolicyInterface : public PointerChoreographerPolicyInterface {
diff --git a/services/inputflinger/tests/fuzzers/InputReaderFuzzer.cpp b/services/inputflinger/tests/fuzzers/InputReaderFuzzer.cpp
index 5442a65..64f3c27 100644
--- a/services/inputflinger/tests/fuzzers/InputReaderFuzzer.cpp
+++ b/services/inputflinger/tests/fuzzers/InputReaderFuzzer.cpp
@@ -171,6 +171,10 @@
void notifyMouseCursorFadedOnTyping() override { reader->notifyMouseCursorFadedOnTyping(); }
+ bool setKernelWakeEnabled(int32_t deviceId, bool enabled) override {
+ return reader->setKernelWakeEnabled(deviceId, enabled);
+ }
+
private:
std::unique_ptr<InputReaderInterface> reader;
};
diff --git a/services/inputflinger/tests/fuzzers/MapperHelpers.h b/services/inputflinger/tests/fuzzers/MapperHelpers.h
index fa8270a..60c676d 100644
--- a/services/inputflinger/tests/fuzzers/MapperHelpers.h
+++ b/services/inputflinger/tests/fuzzers/MapperHelpers.h
@@ -269,6 +269,9 @@
status_t enableDevice(int32_t deviceId) override { return mFdp->ConsumeIntegral<status_t>(); }
status_t disableDevice(int32_t deviceId) override { return mFdp->ConsumeIntegral<status_t>(); }
void sysfsNodeChanged(const std::string& sysfsNodePath) override {}
+ bool setKernelWakeEnabled(int32_t deviceId, bool enabled) override {
+ return mFdp->ConsumeBool();
+ }
};
class FuzzInputReaderPolicy : public InputReaderPolicyInterface {