Skip to content

fix: align wakeupPath PS/2 check with isWakeupMachine - #761

Open
pengfeixx wants to merge 1 commit into
linuxdeepin:develop/eaglefrom
pengfeixx:fix/wakeup-path-ps2-check-294489
Open

pengfeixx wants to merge 1 commit into
linuxdeepin:develop/eaglefrom
pengfeixx:fix/wakeup-path-ps2-check-294489

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Root Cause Analysis

DeviceInput::wakeupPath() (DeviceInput.cpp:508) used only m_Name.contains("PS/2") to select the PS/2 wakeup path, while the sibling function isWakeupMachine() (line 488) already used m_Name.contains("PS/2") || m_Interface.contains("PS/2"). PS/2 keyboards typically have names like "AT Translated Set 2 keyboard" which do not contain "PS/2", so wakeupPath() returned the wrong sysfs path (/sys/.../power/wakeup) instead of /proc/acpi/wakeup. The non-existent sysfs file caused canWakeupMachine() to return false, greying out the "allow wake computer" context menu item.

Key evidence: isWakeupMachine() at line 488 already has the correct dual-condition check, confirming the intended behavior; PS/2 mice normally contain "PS/2" in their names (e.g., "PS/2 Generic Mouse"), which is why mice worked but keyboards did not—matching the bug report.

Fix

Added m_Interface.contains("PS/2") to the condition in wakeupPath(), aligning it with isWakeupMachine() at line 488. One-line change, only affects PS/2 device path selection; USB/Bluetooth paths are unchanged.

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • The target line was introduced by fengli (2023-11-09) for "fix: 待机后不能通过PS2鼠标唤醒" — this change does not revert that fix, it extends the PS/2 detection to cover keyboards whose names lack "PS/2"
  • Affected callers (canWakeupMachine(), isWakeupMachine(), PageMultiInfo.cpp) all benefit from the corrected path — no behavior change for USB/Bluetooth devices

Business Impact Scope

Affected module: keyboard/mouse "allow wake computer" (允许唤起电脑) context menu in Device Manager. The fix corrects PS/2 keyboard path selection so the menu item is no longer greyed out. PS/2 mouse, USB, and Bluetooth devices are unaffected.

Verification Suggestion

Verify PS/2 keyboard right-click menu shows an enabled "allow wake computer" option. Regression-test PS/2 mouse and USB/Bluetooth keyboard/mouse wakeup functionality to confirm no impact.


根因分析

DeviceInput::wakeupPath()(DeviceInput.cpp:508)仅使用 m_Name.contains("PS/2") 选择 PS/2 唤醒路径,而同文件 isWakeupMachine()(第488行)已使用 m_Name.contains("PS/2") || m_Interface.contains("PS/2") 双条件判断。PS/2 键盘名称通常为 "AT Translated Set 2 keyboard",不含 "PS/2",导致 wakeupPath() 返回错误的 sysfs 路径(/sys/.../power/wakeup)而非 /proc/acpi/wakeup。该 sysfs 文件不存在使 canWakeupMachine() 返回 false,"允许唤起电脑"右键菜单项被置灰。

关键证据:isWakeupMachine()(第488行)已有正确的双条件判断,证实预期行为;PS/2 鼠标名称通常含 "PS/2"(如 "PS/2 Generic Mouse"),故鼠标正常而键盘异常——与 bug 现象吻合。

修复方案

wakeupPath() 条件中增加 m_Interface.contains("PS/2"),与第488行 isWakeupMachine() 对齐。一行改动,仅影响 PS/2 设备路径选择,USB/蓝牙路径不变。

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • 目标行由 fengli(2023-11-09)为"待机后不能通过PS2鼠标唤醒"引入——本次修改不撤销该修复,而是扩展 PS/2 检测以覆盖名称不含"PS/2"的键盘
  • 受影响调用者(canWakeupMachine()isWakeupMachine()PageMultiInfo.cpp)均从修正后的路径受益——USB/蓝牙设备行为无变化

业务影响范围

受影响模块:设备管理器中键盘/鼠标"允许唤起电脑"右键菜单。修复修正了 PS/2 键盘路径选择,使菜单项不再置灰。PS/2 鼠标、USB 和蓝牙设备不受影响。

验证建议

验证 PS/2 键盘右键菜单"允许唤起电脑"选项可见且可操作。回归测试 PS/2 鼠标及 USB/蓝牙键盘/鼠标唤起功能,确认无影响。

PMS: BUG-294489

Summary by Sourcery

Bug Fixes:

  • Correct PS/2 device wakeup path detection so PS/2 keyboards can use the ACPI wakeup configuration and have an enabled wake-computer option.

1. Root cause: DeviceInput::wakeupPath() only checked
   m_Name.contains("PS/2") to select the PS/2 wakeup path, while
   isWakeupMachine() already used m_Name || m_Interface check
2. PS/2 keyboards named "AT Translated Set 2 keyboard" do not contain
   "PS/2" in name, so wakeupPath() returned wrong sysfs path instead
   of /proc/acpi/wakeup, causing canWakeupMachine() to return false
3. Fix: add m_Interface.contains("PS/2") to the condition in
   wakeupPath(), aligning with isWakeupMachine() at line 488

Log: Fix PS/2 keyboard "allow wake computer" menu item greyed out

Influence:
1. Test PS/2 keyboard right-click menu shows "allow wake computer"
2. Test PS/2 mouse wakeup function remains normal
3. Test USB and Bluetooth keyboard/mouse wakeup unaffected

fix: 对齐wakeupPath与isWakeupMachine的PS/2判断条件

1. 根因:DeviceInput::wakeupPath()仅检查m_Name.contains("PS/2")
   来选择PS/2唤醒路径,而isWakeupMachine()已使用m_Name||
   m_Interface双条件判断
2. PS/2键盘名称通常为"AT Translated Set 2 keyboard",不含"PS/2",
   导致wakeupPath()返回错误的sysfs路径而非/proc/acpi/wakeup,
   canWakeupMachine()返回false,菜单项被置灰
3. 方案:在wakeupPath()条件中增加m_Interface.contains("PS/2"),
   与第488行isWakeupMachine()保持一致

Log: 修复PS/2键盘"允许唤起电脑"菜单项置灰问题

Influence:
1. 测试PS/2键盘右键菜单"允许唤起电脑"选项可正常使用
2. 测试PS/2鼠标唤起功能不受影响
3. 测试USB和蓝牙键盘/鼠标唤起功能不受影响

PMS: BUG-294489

@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 @pengfeixx, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 5 days and 10 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: pengfeixx

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 Sep 16, 2026

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

Reviewer's Guide

Fixes PS/2 keyboard wakeup support by extending wakeup-path selection to inspect both the device name and interface, preventing the wakeup menu from being incorrectly disabled while preserving USB and Bluetooth behavior.

Flow diagram for PS/2 wakeup path selection

flowchart TD
    A["DeviceInput::wakeupPath()"] --> B{PS/2 in name or interface?}
    B -->|Yes| C["/proc/acpi/wakeup"]
    B -->|No| D["/sys.../power/wakeup"]
    C --> E["canWakeupMachine()"]
    D --> E
    E --> F["Wakeup context menu"]
Loading

File-Level Changes

Change Details Files
Align PS/2 wakeup-path detection with the existing device classification logic.
  • Treat devices whose interface contains "PS/2" as PS/2 devices when selecting the wakeup path.
  • Continue using /proc/acpi/wakeup for PS/2 devices and the sysfs power-wakeup path for other devices.
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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 100 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 100 分,大于 70 分通过阈值,代码质量符合要求。本次提交为 PS/2 键盘唤醒路径检测的 Bug 修复,变更仅一行,逻辑清晰且与同文件 isWakeupMachine() 函数的判断逻辑对齐,无安全漏洞。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 语法正确,逻辑清晰。修改在 DeviceInput.cpp 第508行 wakeupPath() 函数中,将单条件 m_Name.contains("PS/2") 扩展为双条件 m_Name.contains("PS/2") || m_Interface.contains("PS/2"),与同文件第488行 isWakeupMachine() 函数的判断逻辑完全一致。QString::contains() 方法和 || 运算符使用正确,无语法错误。


2. 代码质量 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 代码结构清晰,注释完整。本次修改为最小化的一行变更,精确修复了 PS/2 键盘唤醒路径检测问题。修改后消除了 wakeupPath() 与 isWakeupMachine() 两个函数间的逻辑不一致问题,提升了代码一致性。无重复代码,无残留调试代码。


3. 代码性能 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 性能良好,资源使用合理。新增的 m_Interface.contains("PS/2") 调用为 QString 短字符串匹配操作,开销极小。wakeupPath() 函数在设备枚举时调用,非高频热路径,对整体性能无影响。


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: 安全合规。本次修改仅涉及内部设备成员变量 m_Name 和 m_Interface 的字符串匹配判断,不涉及用户输入、文件操作、网络通信或权限控制,无命令注入、路径遍历、缓冲区溢出等安全风险。返回的路径为硬编码的 /proc/acpi/wakeup 和基于 m_SysPath 构建的 sysfs 路径,不存在路径拼接安全问题。


💡 改进建议代码示例

// 当前修复已正确对齐 wakeupPath() 与 isWakeupMachine() 的 PS/2 检测逻辑
// 无需额外修改,代码示例如下:
QString DeviceInput::wakeupPath()
{
    // ...
    // 修复后:同时检查 m_Name 和 m_Interface,与 isWakeupMachine() 一致
    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");
    }
}

本报告由 AI 代码审查工具自动生成

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