Skip to content

feat: switch camera hotkey to daemon hardware privacy switch - #163

Open
fly602 wants to merge 1 commit into
linuxdeepin:masterfrom
fly602:master
Open

feat: switch camera hotkey to daemon hardware privacy switch#163
fly602 wants to merge 1 commit into
linuxdeepin:masterfrom
fly602:master

Conversation

@fly602

@fly602 fly602 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor
  1. Add CameraController to dde-shortcut-tool exposing camera toggle/on/off. It reads the real device state through org.deepin.dde.Daemon1.GetCameraPrivacy and switches it through SetCameraPrivacy, so the camera is disabled at the hardware level.
  2. The hotkey only drives the hardware switch and shows the matching OSD; it never launches or closes the camera application. When the daemon reports no switchable camera, the hotkey stays silent.
  3. Point the webcam shortcut config at dde-shortcut-tool camera toggle so the hotkey no longer needs the camera-switch helper script.

Log: 摄像头热键改为仅通过系统接口硬件级开关摄像头,不关联相机应用

Influence:

  1. Press the camera hotkey on a machine with a USB camera and confirm the camera toggles off/on with the OSD shown, and the built-in mic on the same device keeps working.
  2. Press the camera hotkey on a machine without a switchable camera and confirm nothing happens (no application is launched).
  3. Build dde-shortcut-tool and confirm camera toggle/on/off commands work without errors.

feat: 摄像头热键改为仅通过系统接口硬件级开关摄像头

  1. 在 dde-shortcut-tool 中新增 CameraController,提供 camera toggle/on/off,经 org.deepin.dde.Daemon1.GetCameraPrivacy 读取状态、 SetCameraPrivacy 开关,硬件级禁用摄像头。
  2. 热键仅驱动硬件开关并显示 OSD,不启停相机应用;守护进程无可切换 摄像头时热键静默不动作。
  3. 将 webcam 快捷键配置指向 dde-shortcut-tool camera toggle,热键不再 依赖 camera-switch 辅助脚本。

Log: 摄像头热键改为仅通过系统接口硬件级开关摄像头,不关联相机应用

Influence:

  1. 有 USB 摄像头的机型按热键,确认开关且有 OSD,同设备内置麦克风 不受影响。
  2. 无可切换摄像头的机型按热键,确认无动作(不启动相机应用)。
  3. 构建 dde-shortcut-tool,确认 camera toggle/on/off 命令无报错。

PMS: BUG-375443

Summary by Sourcery

Switch the webcam hotkey to control camera privacy through the system hardware interface instead of the camera application.

New Features:

  • Add camera toggle, enable, and disable commands to dde-shortcut-tool.

Bug Fixes:

  • Prevent the camera hotkey from launching or closing the camera application when no switchable camera is available.

Enhancements:

  • Route the webcam hotkey through the system daemon's hardware privacy switch and display the corresponding camera OSD.

1. Add CameraController to dde-shortcut-tool exposing camera
   toggle/on/off. It reads the real device state through
   org.deepin.dde.Daemon1.GetCameraPrivacy and switches it through
   SetCameraPrivacy, so the camera is disabled at the hardware level.
2. The hotkey only drives the hardware switch and shows the matching OSD;
   it never launches or closes the camera application. When the daemon
   reports no switchable camera, the hotkey stays silent.
3. Point the webcam shortcut config at dde-shortcut-tool camera toggle
   so the hotkey no longer needs the camera-switch helper script.

Log: 摄像头热键改为仅通过系统接口硬件级开关摄像头,不关联相机应用

Influence:
1. Press the camera hotkey on a machine with a USB camera and confirm
   the camera toggles off/on with the OSD shown, and the built-in mic
   on the same device keeps working.
2. Press the camera hotkey on a machine without a switchable camera and
   confirm nothing happens (no application is launched).
3. Build dde-shortcut-tool and confirm camera toggle/on/off commands
   work without errors.

feat: 摄像头热键改为仅通过系统接口硬件级开关摄像头

1. 在 dde-shortcut-tool 中新增 CameraController,提供 camera
   toggle/on/off,经 org.deepin.dde.Daemon1.GetCameraPrivacy 读取状态、
   SetCameraPrivacy 开关,硬件级禁用摄像头。
2. 热键仅驱动硬件开关并显示 OSD,不启停相机应用;守护进程无可切换
   摄像头时热键静默不动作。
3. 将 webcam 快捷键配置指向 dde-shortcut-tool camera toggle,热键不再
   依赖 camera-switch 辅助脚本。

Log: 摄像头热键改为仅通过系统接口硬件级开关摄像头,不关联相机应用

Influence:
1. 有 USB 摄像头的机型按热键,确认开关且有 OSD,同设备内置麦克风
   不受影响。
2. 无可切换摄像头的机型按热键,确认无动作(不启动相机应用)。
3. 构建 dde-shortcut-tool,确认 camera toggle/on/off 命令无报错。

PMS: BUG-375443
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: fly602

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 4, 2026

Copy link
Copy Markdown

Reviewer's Guide

The webcam hotkey is migrated from application/helper-script control to dde-shortcut-tool camera actions, which use org.deepin.dde.Daemon1 to query and apply hardware-level camera privacy, show corresponding OSD feedback, and remain silent when no switchable camera is available.

Sequence diagram for hardware camera hotkey toggle

sequenceDiagram
    actor User
    participant Shortcut as dde-shortcut-tool
    participant Daemon as org.deepin.dde.Daemon1
    participant OSD as org.deepin.dde.Osd1

    User->>Shortcut: camera toggle
    Shortcut->>Daemon: GetCameraPrivacy()
    Daemon-->>Shortcut: privacy, deviceKnown
    alt switchable camera available
        Shortcut->>Daemon: SetCameraPrivacy(!privacy)
        Daemon-->>Shortcut: applied
        alt hardware switch applied
            Shortcut->>OSD: ShowOSD(CameraOn or CameraOff)
            OSD-->>User: Matching camera OSD
        else no switch applied
        end
    else no switchable camera
    end
Loading

File-Level Changes

Change Details Files
Adds a camera controller that delegates privacy state and hardware switching to dde-system-daemon over system D-Bus.
  • Creates camera toggle, on, and off actions.
  • Reads GetCameraPrivacy and handles unavailable or non-switchable cameras without fallback behavior.
  • Calls SetCameraPrivacy and reports success only when the daemon applies the hardware switch.
src/plugin-qt/shortcut/tools/dde-shortcut-tool/cameracontroller.cpp
src/plugin-qt/shortcut/tools/dde-shortcut-tool/cameracontroller.h
Integrates camera actions into the shortcut tool and its build.
  • Adds the controller sources to the executable.
  • Registers the camera command with the command parser.
src/plugin-qt/shortcut/tools/dde-shortcut-tool/CMakeLists.txt
src/plugin-qt/shortcut/tools/dde-shortcut-tool/main.cpp
Changes the webcam shortcut to invoke the shortcut tool's hardware camera toggle instead of the legacy helper behavior.
  • Points the webcam keybinding at the camera toggle command.
  • Preserves matching camera-on/camera-off OSD feedback and avoids launching the camera application.
src/plugin-qt/shortcut/configs/org.deepin.dde.keybinding.shortcut.webcam/org.deepin.shortcut.json

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

@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.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/plugin-qt/shortcut/tools/dde-shortcut-tool/cameracontroller.cpp" line_range="188" />
<code_context>
+        QDBusConnection::sessionBus()
+    );
+
+    if (osdInterface.isValid()) {
+        osdInterface.call("ShowOSD", signal);
+    } else {
+        qWarning() << "Failed to connect to OSD interface";
</code_context>
<issue_to_address>
**issue (bug_risk):** `ShowOSD` is called without checking the returned D-Bus message, so a camera switch can succeed while the OSD call fails and `execute` still reports success. The hotkey therefore does not guarantee the matching OSD described by the feature.

**Triggers:** When the OSD service is registered but rejects or fails the `ShowOSD` method call.

**Suggested fix:** Capture the returned `QDBusMessage` and log or propagate its error when the call is not a valid reply.

```suggestion
        QDBusMessage reply = osdInterface.call("ShowOSD", signal);
        if (reply.type() != QDBusMessage::ReplyMessage) {
            qWarning() << "ShowOSD failed:" << reply.errorMessage();
        }
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

);

if (osdInterface.isValid()) {
osdInterface.call("ShowOSD", signal);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): ShowOSD is called without checking the returned D-Bus message, so a camera switch can succeed while the OSD call fails and execute still reports success. The hotkey therefore does not guarantee the matching OSD described by the feature.

Triggers: When the OSD service is registered but rejects or fails the ShowOSD method call.

Suggested fix: Capture the returned QDBusMessage and log or propagate its error when the call is not a valid reply.

Suggested change
osdInterface.call("ShowOSD", signal);
QDBusMessage reply = osdInterface.call("ShowOSD", signal);
if (reply.type() != QDBusMessage::ReplyMessage) {
qWarning() << "ShowOSD failed:" << reply.errorMessage();
}

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
PR 标题 feat: switch camera hotkey to daemon hardware privacy switch
PR 作者 fly602
审查模式 全量分析
评分详情 未发现安全漏洞,代码结构清晰,逻辑正确,性能良好。新增 CameraController 通过 D-Bus 系统总线和 org.deepin.dde.Daemon1 交互,实现硬件级摄像头隐私开关,符合需求描述的目的。代码遵循现有控制器模式(如 AudioController),注释完整,错误处理得当。

🔍 详细分析

1. 语法逻辑 ✓(23/25分)

评价: 语法正确,逻辑清晰

代码语法正确,逻辑清晰。CameraController 继承 BaseController,通过 D-Bus 系统总线与 org.deepin.dde.Daemon1 交互,实现摄像头隐私开关的 toggle/on/off 操作。toggle() 方法先读取当前状态再翻转,逻辑正确。边界条件处理完善:无效接口、未知动作、无摄像头设备等情况均有处理。无内存泄漏(QDBusInterface 通过 Qt 父子对象机制管理生命周期),无空指针解引用风险。

潜在问题:

  1. cameracontroller.cpp 第53行:析构函数 ~CameraController() 函数体为空,建议在头文件中使用 ~CameraController() override = default; 替代,减少不必要的函数体定义
  2. cameracontroller.cpp 第41行:commandActions() 和 commandActionHelp() 每次调用都返回新的 QStringList/QMap 对象,虽然与现有 AudioController 模式一致,但可考虑缓存为静态成员变量

2. 代码质量 ✓(23/25分)

评价: 代码结构清晰,注释完整

代码结构清晰,注释完整。SPDX 许可证头文件在 .cpp 和 .h 文件中均存在。头文件中包含完整的类级文档注释,说明设计意图("Toggles camera privacy through the system daemon")。关键逻辑处有行内注释说明设计决策(如"No camera device to switch: the hotkey only drives hardware")。代码遵循现有控制器模式(AudioController),方法命名清晰。错误处理使用 qWarning 输出诊断信息,符合 Qt 最佳实践。

潜在问题:

  1. cameracontroller.h 第26行:未添加 Q_DISABLE_COPY(CameraController) 宏,虽然 QObject 已禁用拷贝构造,但显式声明是更好的实践
  2. cameracontroller.cpp 第53行:空的析构函数实现增加了不必要的代码量,建议使用 = default

3. 代码性能 ✓(19/20分)

评价: 性能良好,资源使用合理

性能良好,资源使用合理。D-Bus 接口在构造函数中创建一次并复用,避免重复连接。toggle() 方法仅发起2次 D-Bus 调用(GetCameraPrivacy + SetCameraPrivacy),对于快捷键工具而言性能开销合理。工具为短生命周期进程(执行后退出),性能不是关键瓶颈。无不必要的内存拷贝。

潜在问题:

  1. cameracontroller.cpp 第165行:showOSD() 方法每次调用都创建新的 QDBusInterface 对象,虽然不在循环中调用(仅在 toggle/on/off 时触发一次),但可考虑缓存为成员变量以减少对象创建开销

4. 代码安全 🔒 ✓(30/30分)

存在0个安全漏洞

安全合规。代码通过 D-Bus 系统总线与系统守护进程通信,使用 systemBus 进行硬件级控制(SetCameraPrivacy/GetCameraPrivacy),使用 sessionBus 进行 OSD 显示,权限划分合理。动作字符串("toggle"、"on"、"off")为预定义常量,不存在用户输入注入风险。execute() 方法对未知动作返回 false,防御性编程得当。无硬编码密钥、无敏感信息泄露、无命令注入、无 SQL 注入、无路径遍历、无缓冲区溢出风险。qDebug 仅输出隐私状态和应用结果,不包含敏感信息。快捷键配置 JSON 修改仅更新命令路径,安全无误。

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个

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


📁 修改文件列表

文件 类型 说明
org.deepin.shortcut.json 修改 快捷键配置从 camera-switch 脚本改为 dde-shortcut-tool camera toggle
CMakeLists.txt 修改 添加 cameracontroller.cpp/h 到构建系统
cameracontroller.cpp 新增 CameraController 实现,通过 D-Bus 控制摄像头隐私开关
cameracontroller.h 新增 CameraController 头文件,继承 BaseController
main.cpp 修改 注册 CameraController 到命令解析器

💡 改进建议代码示例

// cameracontroller.h - 建议改进
class CameraController : public BaseController
{
    Q_OBJECT
    Q_DISABLE_COPY(CameraController)  // 显式禁用拷贝

public:
    explicit CameraController(QObject *parent = nullptr);
    ~CameraController() override = default;  // 使用 default 替代空实现
    // ...
};
// cameracontroller.cpp - showOSD 优化建议
// 可将 OSD 接口缓存为成员变量
// 在构造函数中初始化:
//   m_osdInterface = new QDBusInterface(
//       "org.deepin.dde.Osd1",
//       "/org/deepin/dde/shell/osd",
//       "org.deepin.dde.shell.osd",
//       QDBusConnection::sessionBus(), this);
// showOSD() 中直接使用 m_osdInterface->call("ShowOSD", signal);

本报告由 AI 代码审查工具自动生成
审查时间: 2026-09-04 17:58:00
构建地址: https://jenkinswh.uniontech.com/job/SmartOS/job/Gerrit-AI-agent-response/878/
报告地址: http://zl.uniontech.com/ibrebuild/reports/SmartOS/Gerrit-AI-agent-response/878/ai-check-report.html

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