Skip to content

fix: fix missing wake option for PS/2 keyboard in device manager - #726

Open
tianming-1996 wants to merge 2 commits into
linuxdeepin:develop/eaglefrom
tianming-1996:develop/eagle
Open

fix: fix missing wake option for PS/2 keyboard in device manager#726
tianming-1996 wants to merge 2 commits into
linuxdeepin:develop/eaglefrom
tianming-1996:develop/eagle

Conversation

@tianming-1996

@tianming-1996 tianming-1996 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

根因分析

结论:强根因

DeviceInput::wakeupPath() (DeviceInput.cpp:508) 中 PS/2 设备判断条件与同文件的 isWakeupMachine() (:484) 不一致。wakeupPath() 仅判断 m_Name.contains("PS/2"),而 isWakeupMachine() 正确使用了 m_Name.contains("PS/2") || m_Interface.contains("PS/2")

L420 内置 PS/2 键盘名称为 "AT Translated Set 2 keyboard"(不含 "PS/2" 字符串),导致 wakeupPath() 返回错误的 sysfs 路径 /sys/.../power/wakeup(该路径在 PS/2 设备上不存在),使 canWakeupMachine()QFile::open() 失败返回 false,右键菜单中"允许唤起电脑"选项因此被禁用。

关键证据:

  • DeviceInput.cpp:508wakeupPath() 仅判断 m_Name
  • DeviceInput.cpp:484isWakeupMachine() 判断 m_Name || m_Interface
  • DBusWakeupInterface.cpp:50 注释明确:PS/2 设备只能通过 ACPI 接口控制,无 sysfs wakeup 节点

修复方案

wakeupPath() 的 PS/2 判断中增加 m_Interface.contains("PS/2"),与 isWakeupMachine() 逻辑对齐:

// 修改前
if (m_Name.contains("PS/2")) {

// 修改后
if (m_Name.contains("PS/2") || m_Interface.contains("PS/2")) {

改动安全评估

低风险。仅扩展 PS/2 判断条件,函数签名不变。所有调用者(canWakeupMachine()isWakeupMachine()PageMultiInfo::getTableListInfo())均受益或不受影响,无历史回归风险。

Summary by Sourcery

Fix PS/2 keyboard wakeup detection so the device-manager wake option is available for supported keyboards.

Bug Fixes:

  • Restore the device-manager wake option for PS/2 keyboards whose device name does not include “PS/2” by selecting the correct ACPI wakeup path from the interface identifier.

Chores:

  • Update the copyright year range for DeviceInput.cpp.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @tianming-1996, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: tianming-1996

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai

sourcery-ai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Aligns PS/2 keyboard wakeup path detection with existing wake-capability logic by considering both device name and interface, ensuring PS/2 devices without 'PS/2' in their name still use the ACPI wakeup path.

Sequence diagram for PS2 wakeupPath selection in DeviceInput

sequenceDiagram
    participant DeviceManager
    participant DeviceInput
    participant QFile

    DeviceManager->>DeviceInput: canWakeupMachine()
    DeviceInput->>DeviceInput: wakeupPath()
    alt [m_Name.contains(PS2) or m_Interface.contains(PS2)]
        DeviceInput-->>DeviceInput: return /proc/acpi/wakeup
    else [no PS2 in name and interface]
        DeviceInput-->>DeviceInput: return /sys/.../power/wakeup
    end
    DeviceInput->>QFile: open(wakeupPath)
    QFile-->>DeviceInput: open result
    DeviceInput-->>DeviceManager: canWakeupMachine() result
Loading

File-Level Changes

Change Details Files
Align PS/2 detection in wakeupPath() with isWakeupMachine() so PS/2 keyboards using only the interface string are correctly mapped to the ACPI wakeup path.
  • Extend PS/2 detection condition in wakeupPath() to check both m_Name and m_Interface for 'PS/2'.
  • Keep return value for detected PS/2 devices as /proc/acpi/wakeup, falling back to /sys/.../power/wakeup for others without changing the function signature or call sites.
deepin-devicemanager/src/DeviceManager/DeviceInput.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

1. 修复 wakeupPath() 中 PS/2 设备判断条件不一致问题;
2. 增加对 m_Interface 字段的 PS/2 判断, 使其与 isWakeupMachine() 逻辑一致;
3. PS/2 键盘设备名称不含 "PS/2" 字符串时也能正确返回 /proc/acpi/wakeup 路径;
4. 更新 SPDX 版权年份为 2022-2026;

=====================================

1. fixed inconsistent PS/2 device detection in wakeupPath();
2. added m_Interface check to align with isWakeupMachine() logic;
3. PS/2 keyboard devices without "PS/2" in name now correctly return /proc/acpi/wakeup path;
4. updated SPDX copyright year to 2022-2026;

Log: 修复设备管理器中 PS/2 键盘右键菜单缺少 "允许唤起电脑" 选项的问题, 原因是 wakeupPath() 判断条件与 isWakeupMachine() 不一致

Bug: https://pms.uniontech.com/bug-view-294489.html
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码精准修复了PS/2设备唤醒路径判断遗漏的问题,逻辑清晰且无副作用。
四个审查维度均无缺陷,符合优秀代码标准。

■ 【详细分析】

  • 1.语法逻辑完全正确✓

在 DeviceInput.cpp 的 wakeupPath() 函数中,通过逻辑或操作符连接 m_Name 和 m_Interface 的字符串包含判断,符合C++短路求值原则,准确覆盖了名称中不含但接口中包含PS/2的设备场景。
建议:保持现有的简洁逻辑即可。

  • 2.代码质量良好✓

修改直接针对BUG关键信息中指出的遗漏点,没有引入不必要的复杂度或冗余代码,变量命名清晰,符合项目既有规范。
建议:无需额外修改。

  • 3.代码性能无性能问题✓

新增的 m_Interface.contains("PS/2") 调用仅为一次针对极短字符串的线性查找,时间复杂度与空间复杂度消耗均趋近于零,对系统无感知影响。
建议:无需额外修改。

  • 4.代码安全存在0个安全漏洞✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码修改仅涉及内部成员变量的只读字符串匹配操作,未引入任何外部输入、命令拼接、路径遍历或内存越界等风险点,安全性极高。
建议:继续保持安全的编码习惯。

■ 【改进建议代码示例】

#include <QString>

class DeviceInput {
private:
    QString m_Name;
    QString m_Interface;
    QString m_SysPath;

public:
    QString wakeupPath();
};

QString DeviceInput::wakeupPath()
{
    int index = m_SysPath.lastIndexOf(":");
    if (index == -1) {
        return "";
    }

    if (m_Name.contains("PS/2") || m_Interface.contains("PS/2")) {
        return "/proc/acpi/wakeup";
    } else {
        return QString("/sys") + m_SysPath.left(index) + QString("/power/wakeup");
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants