Skip to content

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

Open
tianming-1996 wants to merge 1 commit 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 1 commit 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

Bug Fixes:

  • Fix missing wake-up option for certain PS/2 keyboards by also checking the device interface string when resolving the ACPI wakeup path.

@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

★ 总体评分:100分

■ 【总体评价】

代码精准修复了PS/2设备唤醒路径判断逻辑遗漏的问题,实现简洁且无副作用
逻辑完全正确且无任何安全风险,符合满分标准

■ 【详细分析】

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

在DeviceInput.cpp的wakeupPath()函数第508行,将原本单一的m_Name.contains判断扩展为包含m_Interface.contains的逻辑或判断,准确覆盖了设备名称不含"PS/2"但接口类型为PS/2的边界情况,语法和逻辑均无瑕疵
建议:保持现有逻辑即可

  • 2.代码质量(良好)✓

代码改动极简,仅增加必要的条件判断,未引入冗余代码或破坏原有结构,同时顺带更新了SPDX版权年份,符合日常维护规范
建议:保持现有代码风格

  • 3.代码性能(高效)✓

QString::contains方法在短字符串上的时间复杂度可忽略不计,增加一次m_Interface的字符串匹配对系统性能无任何可感知影响
建议:无需优化

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码仅对内部成员变量进行字符串匹配并返回硬编码或基于sysfs的安全路径,未引入任何外部输入处理,无安全风险

  • 建议:无需额外安全加固

■ 【改进建议代码示例】

@@ -503,8 +503,10 @@ QString DeviceInput::wakeupPath()
         return "";
     }
 
-    if (m_Name.contains("PS/2")) {
+    // 增加对 m_Interface 的判空保护与 PS/2 检测
+    if (m_Name.contains("PS/2") || (!m_Interface.isEmpty() && 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