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

Commit 81a590ca authored by Yanye Li's avatar Yanye Li
Browse files

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
parent 1c375bb6
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -214,3 +214,10 @@ flag {
  description: "Enable telemetry for rotary input"
  bug: "370353565"
}

flag {
  name: "set_input_device_kernel_wake"
  namespace: "input"
  description: "Set input device's power/wakeup sysfs node"
  bug: "372812925"
}
+10 −0
Original line number Diff line number Diff line
@@ -426,6 +426,16 @@ public:

    /* Notifies that mouse cursor faded due to typing. */
    virtual void notifyMouseCursorFadedOnTyping() = 0;

    /* Set whether the given input device can wake up the kernel from sleep
     * when it generates input events. By default, usually only internal (built-in)
     * input devices can wake the kernel from sleep. For an external input device
     * that supports remote wakeup to be able to wake the kernel, this must be called
     * after each time the device is connected/added.
     *
     * Returns true if setting power wakeup was successful.
     */
    virtual bool setKernelWakeEnabled(int32_t deviceId, bool enabled) = 0;
};

// --- TouchAffineTransformation ---
+29 −0
Original line number Diff line number Diff line
@@ -2848,6 +2848,35 @@ void EventHub::requestReopenDevices() {
    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";

+8 −0
Original line number Diff line number Diff line
@@ -745,6 +745,14 @@ void InputDevice::setKeyboardType(KeyboardType keyboardType) {
    }
}

bool InputDevice::setKernelWakeEnabled(bool enabled) {
    bool success = false;
    for_each_subdevice([&enabled, &success](InputDeviceContext& context) {
        success |= context.setKernelWakeEnabled(enabled);
    });
    return success;
}

InputDeviceContext::InputDeviceContext(InputDevice& device, int32_t eventHubId)
      : mDevice(device),
        mContext(device.getContext()),
+10 −0
Original line number Diff line number Diff line
@@ -901,6 +901,16 @@ void InputReader::notifyMouseCursorFadedOnTyping() {
    mPreventingTouchpadTaps = true;
}

bool InputReader::setKernelWakeEnabled(int32_t deviceId, bool enabled) {
    std::scoped_lock _l(mLock);

    InputDevice* device = findInputDeviceLocked(deviceId);
    if (device) {
        return device->setKernelWakeEnabled(enabled);
    }
    return false;
}

void InputReader::dump(std::string& dump) {
    std::scoped_lock _l(mLock);

Loading