Skip to content

fix: show I2C touchpad in device manager mouse list - #764

Open
pengfeixx wants to merge 1 commit into
linuxdeepin:develop/eaglefrom
pengfeixx:agent/pms-bug-bot/263f2dd9d981
Open

pengfeixx wants to merge 1 commit into
linuxdeepin:develop/eaglefrom
pengfeixx:agent/pms-bug-bot/263f2dd9d981

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Root Cause Analysis

I2C touchpads (e.g., elan-clickpad on Huawei L410) only register /dev/input/eventX without /dev/input/mouseX. The device manager relies on hwinfo which classifies devices as "mouse" only when handlers contain the string "mouse". Since I2C touchpads lack "mouse" in their handlers, they never enter the hwinfo_mouse list, and getMouseInfoFromHwinfo() never processes them — making the touchpad invisible in the device manager.

Key evidence:

  • CmdTool.cpp:706 filters by Hardware Class == "mouse", which I2C touchpads never match
  • CmdTool.cpp:828-852 (loadCatInputDeviceInfo) reads the device from /proc/bus/input/devices but only stores it in m_InputDeviceInfo without injecting into the mouse list

Fix Approach

Added touchpad detection in loadCatInputDeviceInfo(): when a device's handlers do not contain "mouse", the new method addTouchpadToMouseList() uses udevadm to check ID_INPUT_TOUCHPAD=1. If confirmed as a touchpad, it constructs an hwinfo_mouse-compatible map and injects it via addMouseKeyboardInfoMapInfo("hwinfo_mouse", ...), making the device visible to getMouseInfoFromHwinfo().

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • Only appends new logic at the end of loadCatInputDeviceInfo(); no existing code paths or function signatures are modified
  • PS/2 touchpads are unaffected: their handlers contain "mouse", so the new branch is skipped and hwinfo's existing classification is used

Business Impact Scope

  • Mouse/Touchpad display: I2C touchpads (e.g., Huawei L410 elan-clickpad) will now appear in the device manager's mouse/touchpad section — this is the intended fix
  • PS/2 touchpads: No impact; already classified by hwinfo, skipped by the new logic
  • Other input devices: No impact; the udevadm ID_INPUT_TOUCHPAD=1 check only triggers for touchpads

Verification Suggestion

Test on affected I2C touchpad hardware (e.g., Huawei L410) to confirm the touchpad appears in device manager. Verify PS/2 touchpad devices still display correctly without duplication. Confirm other mouse devices are unaffected.


根因分析

I2C 接口触摸板(如华为 L410 的 elan-clickpad)仅注册 /dev/input/eventX,不注册 /dev/input/mouseX。设备管理器依赖 hwinfo 进行设备分类,而 hwinfo 仅在 handlers 包含 "mouse" 字符串时将设备归类为 mouse。I2C 触摸板 handlers 中无 "mouse",因此无法进入 hwinfo_mouse 列表,getMouseInfoFromHwinfo() 永远遍历不到该设备,导致触摸板在设备管理器中不可见。

关键证据:

  • CmdTool.cpp:706Hardware Class == "mouse" 筛选,I2C 触摸板不匹配
  • CmdTool.cpp:828-852loadCatInputDeviceInfo)从 /proc/bus/input/devices 读取到该设备,但仅存入 m_InputDeviceInfo,未接入鼠标列表

修复方案

loadCatInputDeviceInfo() 中新增触摸板检测逻辑:当设备 handlers 不含 "mouse" 时,通过新增方法 addTouchpadToMouseList() 调用 udevadm 检测 ID_INPUT_TOUCHPAD=1。确认为触摸板后,构造 hwinfo_mouse 兼容格式的 map,通过 addMouseKeyboardInfoMapInfo("hwinfo_mouse", ...) 注入鼠标列表,使 getMouseInfoFromHwinfo() 能处理该设备。

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • 仅在 loadCatInputDeviceInfo() 末尾新增独立分支,不修改已有代码路径和函数签名
  • PS/2 触摸板不受影响:其 handlers 含 "mouse",新逻辑跳过,使用 hwinfo 已有分类

业务影响范围

  • 鼠标/触摸板显示:I2C 接口触摸板(如华为 L410 elan-clickpad)将在设备管理器鼠标/触摸板区域可见——本次修复目标
  • PS/2 触摸板:不受影响,已被 hwinfo 分类,新逻辑通过 handlers 含 "mouse" 判断跳过
  • 其他输入设备:不受影响,udevadm ID_INPUT_TOUCHPAD=1 检测仅对触摸板触发

验证建议

在受影响的 I2C 触摸板硬件(如华为 L410)上测试触摸板在设备管理器中的可见性。验证 PS/2 触摸板仍正常显示且不出现重复。确认其他鼠标设备不受影响。

PMS: BUG-209019

Summary by Sourcery

Bug Fixes:

  • Make I2C touchpads visible in the device manager's mouse/touchpad list by identifying them through udev properties and incorporating them into mouse-device processing.

1. Root cause: I2C touchpads (e.g. elan-clickpad) only register
   /dev/input/eventX without /dev/input/mouseX, hwinfo classifies
   devices as mouse only when handlers contain "mouse", so I2C
   touchpads never enter hwinfo_mouse list and are invisible
2. Fix: add touchpad detection in loadCatInputDeviceInfo() using
   udevadm to check ID_INPUT_TOUCHPAD=1, inject detected touchpads
   into hwinfo_mouse via addMouseKeyboardInfoMapInfo
3. Impact: only affects devices without "mouse" in handlers, PS/2
   touchpads are unaffected as they are already classified by hwinfo

Log: I2C touchpad now visible in device manager mouse/touchpad area

Influence:
1. Test I2C touchpad visibility in device manager on affected hardware
2. Verify PS/2 touchpad still displays correctly without duplication
3. Verify other mouse devices are unaffected

fix: I2C触摸板在设备管理器鼠标列表中可见

1. 根因:I2C触摸板(如elan-clickpad)仅注册/dev/input/eventX而不注册
   /dev/input/mouseX,hwinfo仅在handlers含"mouse"时分类为mouse,
   导致I2C触摸板无法进入hwinfo_mouse列表,设备管理器中不可见
2. 方案:在loadCatInputDeviceInfo()中通过udevadm检测ID_INPUT_TOUCHPAD=1,
   将识别到的触摸板通过addMouseKeyboardInfoMapInfo注入hwinfo_mouse列表
3. 影响:仅影响handlers中不含mouse的设备,PS/2触摸板已被hwinfo分类,
   不受影响

Log: I2C触摸板在设备管理器鼠标/触摸板区域可见

Influence:
1. 在受影响硬件上测试I2C触摸板在设备管理器中的可见性
2. 验证PS/2触摸板仍正常显示且不出现重复
3. 验证其他鼠标设备不受影响

PMS: BUG-209019

@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

Adds a udev-based fallback for I2C touchpads that appear only as event devices, synthesizes hwinfo-compatible mouse metadata, and injects the result into the existing mouse discovery pipeline without changing the normal hwinfo path.

Sequence diagram for I2C touchpad discovery

sequenceDiagram
    participant CmdTool
    participant ProcInput as /proc/bus/input/devices
    participant Udevadm
    participant MouseList as hwinfo_mouse
    participant DeviceManager

    CmdTool->>ProcInput: loadCatInputDeviceInfo()
    ProcInput-->>CmdTool: mapInfo with Handlers and event node
    alt handlers contain mouse
        CmdTool->>MouseList: use existing hwinfo classification
    else handlers lack mouse
        CmdTool->>CmdTool: addTouchpadToMouseList(mapInfo)
        CmdTool->>Udevadm: isTouchpadDevice(eventNode)
        Udevadm-->>CmdTool: ID_INPUT_TOUCHPAD=1
        CmdTool->>MouseList: addMouseKeyboardInfoMapInfo(hwinfo_mouse, mouseMapInfo)
    end
    DeviceManager->>MouseList: getMouseInfoFromHwinfo()
    MouseList-->>DeviceManager: touchpad metadata
Loading

File-Level Changes

Change Details Files
Detect I2C touchpads that hwinfo omits from its mouse classification and add them to the mouse processing list.
  • Adds a fallback branch for input devices whose handlers lack “mouse”.
  • Uses udev properties to require ID_INPUT_TOUCHPAD=1 before treating the device as a touchpad.
  • Extracts the event node from handlers and performs a bounded udevadm property query.
deepin-devicemanager/src/GenerateDevice/CmdTool.cpp
deepin-devicemanager/src/GenerateDevice/CmdTool.h
Adapt detected touchpad metadata to the existing hwinfo mouse-device pipeline.
  • Constructs a compatible mouse map with device name, touchpad model, sysfs path, device files, and mouse hardware class.
  • Injects the synthesized record into hwinfo_mouse for downstream processing.
  • Sets Hotplug to PS/2 so existing authorization checks are bypassed while bus detection can identify the actual I2C interface.
deepin-devicemanager/src/GenerateDevice/CmdTool.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 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 88 分,大于 70 分通过阈值。本次变更修复了 I2C 触摸板在设备管理器中不可见的问题,代码逻辑正确,无安全漏洞,但存在代码质量方面的改进空间。

🔍 详细分析

1. 语法逻辑 ✅

评价: 良好 ✅ 通过

潜在问题:

  1. CmdTool.cpp:872 - isTouchpadDevice() 中 waitForFinished(5000) 返回值未检查,QProcess 超时后未显式 kill

建议: 检查 waitForFinished() 返回值,超时时显式调用 process.kill() 清理进程;使用 QRegularExpression 替代 QRegExp


2. 代码质量 ❌

评价: 良好 ❌ 不通过

潜在问题:

  1. CmdTool.cpp:884 - addTouchpadToMouseList() 使用已废弃的 QRegExp,与同文件现有代码使用的 QRegularExpression 不一致
  2. CmdTool.cpp:912 - addTouchpadToMouseList() 设置 Hotplug="PS/2" 绕过 authorized 文件检查,虽已注释说明但仍为 workaround

建议: 将 QRegExp 替换为 QRegularExpression 保持代码风格一致性;考虑在 getMouseInfoFromHwinfo() 中直接处理 I2C 设备的 authorized 检查逻辑,避免通过 Hotplug 字段绕过


3. 代码性能 ✅

评价: 良好 ✅ 通过

潜在问题:

  1. CmdTool.cpp:867 - isTouchpadDevice() 对每个非 mouse 设备调用 udevadm 阻塞等待,无缓存机制

建议: 考虑缓存 udevadm 查询结果,或使用非阻塞方式调用 QProcess;对于明确非触摸板的设备类型(如键盘)可提前跳过


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

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

建议: 本次新增代码无安全风险。QProcess 使用参数列表模式调用 udevadm,eventNode 经正则验证仅含 event+数字,无命令注入风险


💡 改进建议代码示例

// 改进1: 使用 QRegularExpression 替代 QRegExp
void CmdTool::addTouchpadToMouseList(const QMap<QString, QString> &mapInfo)
{
    // 从Handlers中提取event设备节点
    QRegularExpression re(".*(event[0-9]{1,2}).*");
    QRegularExpressionMatch match = re.match(mapInfo["Handlers"]);
    if (!match.hasMatch())
        return;

    QString eventNode = match.captured(1);

    // 通过udevadm检测是否为触摸板
    if (!isTouchpadDevice(eventNode))
        return;
    // ... 后续逻辑不变
}

// 改进2: isTouchpadDevice 增加 waitForFinished 返回值检查和进程清理
bool CmdTool::isTouchpadDevice(const QString &eventNode)
{
    if (eventNode.isEmpty())
        return false;

    QProcess process;
    process.start("udevadm", QStringList() << "info" << "--query=property" << "--name=/dev/input/" + eventNode);

    bool finished = process.waitForFinished(5000);
    if (!finished) {
        process.kill();
        process.waitForFinished(1000);
        return false;
    }

    QString output = process.readAllStandardOutput();
    return output.contains("ID_INPUT_TOUCHPAD=1");
}

本报告由 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