feat: switch camera hotkey to daemon hardware privacy switch - #163
Conversation
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
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideThe 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 togglesequenceDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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>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); |
There was a problem hiding this comment.
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.
| osdInterface.call("ShowOSD", signal); | |
| QDBusMessage reply = osdInterface.call("ShowOSD", signal); | |
| if (reply.type() != QDBusMessage::ReplyMessage) { | |
| qWarning() << "ShowOSD failed:" << reply.errorMessage(); | |
| } |
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✓(23/25分)评价: 语法正确,逻辑清晰 代码语法正确,逻辑清晰。CameraController 继承 BaseController,通过 D-Bus 系统总线与 org.deepin.dde.Daemon1 交互,实现摄像头隐私开关的 toggle/on/off 操作。toggle() 方法先读取当前状态再翻转,逻辑正确。边界条件处理完善:无效接口、未知动作、无摄像头设备等情况均有处理。无内存泄漏(QDBusInterface 通过 Qt 父子对象机制管理生命周期),无空指针解引用风险。 潜在问题:
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 最佳实践。 潜在问题:
3. 代码性能 ✓(19/20分)评价: 性能良好,资源使用合理 性能良好,资源使用合理。D-Bus 接口在构造函数中创建一次并复用,避免重复连接。toggle() 方法仅发起2次 D-Bus 调用(GetCameraPrivacy + SetCameraPrivacy),对于快捷键工具而言性能开销合理。工具为短生命周期进程(执行后退出),性能不是关键瓶颈。无不必要的内存拷贝。 潜在问题:
4. 代码安全 🔒 ✓(30/30分)存在0个安全漏洞 安全合规。代码通过 D-Bus 系统总线与系统守护进程通信,使用 systemBus 进行硬件级控制(SetCameraPrivacy/GetCameraPrivacy),使用 sessionBus 进行 OSD 显示,权限划分合理。动作字符串("toggle"、"on"、"off")为预定义常量,不存在用户输入注入风险。execute() 方法对未知动作返回 false,防御性编程得当。无硬编码密钥、无敏感信息泄露、无命令注入、无 SQL 注入、无路径遍历、无缓冲区溢出风险。qDebug 仅输出隐私状态和应用结果,不包含敏感信息。快捷键配置 JSON 修改仅更新命令路径,安全无误。 漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个 安全漏洞详情: 📁 修改文件列表
💡 改进建议代码示例// 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 代码审查工具自动生成 |
Log: 摄像头热键改为仅通过系统接口硬件级开关摄像头,不关联相机应用
Influence:
feat: 摄像头热键改为仅通过系统接口硬件级开关摄像头
Log: 摄像头热键改为仅通过系统接口硬件级开关摄像头,不关联相机应用
Influence:
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:
Bug Fixes:
Enhancements: