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/reader/EventHub.cpp b/services/inputflinger/reader/EventHub.cpp
index f8cd973..8dec9e5 100644
--- a/services/inputflinger/reader/EventHub.cpp
+++ b/services/inputflinger/reader/EventHub.cpp
@@ -2848,6 +2848,35 @@
     mNeedToReopenDevices = true;
 }
 
+bool EventHub::setKernelWakeEnabled(int32_t deviceId, bool enabled) {
+    std::scoped_lock _l(mLock);
+    std::string enabledStr = enabled ? "enabled" : "disabled";
+    Device* device = getDeviceLocked(deviceId);
+    if (device == nullptr) {
+        ALOGE("Device Id %d does not exist for setting power wakeup", deviceId);
+        return false;
+    }
+    if (device->associatedDevice == nullptr) {
+        return false;
+    }
+    std::filesystem::path currentPath = device->associatedDevice->sysfsRootPath;
+    while (!currentPath.empty() && currentPath != "/") {
+        std::string nodePath = currentPath / "power/wakeup";
+        if (std::filesystem::exists(nodePath)) {
+            if (base::WriteStringToFile(enabledStr, nodePath)) {
+                return true;
+
+            }
+            // No need to continue searching in parent directories as power/wakeup nodes
+            // higher up may control other subdevices.
+            ALOGW("Failed to set power/wakeup node at %s", nodePath.c_str());
+            return false;
+        }
+        currentPath = currentPath.parent_path();
+    }
+    return false;
+}
+
 void EventHub::dump(std::string& dump) const {
     dump += "Event Hub State:\n";