Repository navigation
fix: report camera-not-enabled status and keep the face entry visible - #59
Conversation
Reviewer's GuideThe PR decouples the advertised face capability from the camera switch, introduces dedicated enrollment and verification status code 15 for unavailable cameras, and adds device-loss detection, watchdog fallback reporting, and null-safe cleanup so camera shutdowns fail promptly without crashing while preserving existing occupied-camera exception behavior. Sequence diagram for camera-unavailable enrollment handlingsequenceDiagram
participant Client
participant ErollThread
participant MediaDevices
participant Camera
participant Watchdog
Client->>ErollThread: Start(actionId, socket)
ErollThread->>MediaDevices: videoInputs()
alt no camera device before capture
MediaDevices-->>ErollThread: empty list
ErollThread-->>Client: processStatus(actionId, FaceEnrollCameraNotEnabled)
else camera available
ErollThread->>Camera: start()
ErollThread->>Watchdog: start()
alt device disappears during capture
Watchdog->>MediaDevices: videoInputs()
MediaDevices-->>Watchdog: empty list
Watchdog-->>Client: processStatus(actionId, FaceEnrollCameraNotEnabled)
Watchdog->>Watchdog: stop()
Client->>ErollThread: Stop()
ErollThread->>Camera: stop()
else capture error
Camera-->>ErollThread: captureError(...)
ErollThread->>MediaDevices: videoInputs()
alt no camera device
ErollThread-->>Client: processStatus(actionId, FaceEnrollCameraNotEnabled)
else camera still present
ErollThread-->>Client: processStatus(actionId, FaceEnrollException)
end
end
end
Sequence diagram for camera-unavailable verification handlingsequenceDiagram
participant Client
participant VerifyThread
participant MediaDevices
participant Camera
participant Watchdog
Client->>VerifyThread: Start(actionId, charas)
VerifyThread->>MediaDevices: videoInputs()
alt no camera device before capture
MediaDevices-->>VerifyThread: empty list
VerifyThread-->>Client: processStatus(actionId, FaceVerifyCameraNotEnabled)
else camera available
VerifyThread->>Camera: start()
VerifyThread->>Watchdog: start()
alt device disappears during capture
Watchdog->>MediaDevices: videoInputs()
MediaDevices-->>Watchdog: empty list
Watchdog-->>Client: processStatus(actionId, FaceVerifyCameraNotEnabled)
Watchdog->>Watchdog: stop()
Client->>VerifyThread: Stop()
VerifyThread->>Camera: stop()
else capture error
Camera-->>VerifyThread: captureError(...)
VerifyThread->>MediaDevices: videoInputs()
alt no camera device
VerifyThread-->>Client: processStatus(actionId, FaceVerifyCameraNotEnabled)
else camera still present
VerifyThread-->>Client: processStatus(actionId, FaceVerifyException)
end
end
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 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="workmodule.cpp" line_range="574" />
<code_context>
+ if (m_cameraWatchTimer) {
+ m_cameraWatchTimer->stop();
+ }
+ if (!m_imageCapture.isNull()) {
+ disconnect(m_imageCapture.data(), &QImageCapture::readyForCaptureChanged, this, &ErollThread::readyForCapture);
+ disconnect(m_imageCapture.data(), &QImageCapture::imageCaptured, this, &ErollThread::processCapturedImage);
</code_context>
<issue_to_address>
**Late verify error can crash service**
When camera removal or stopping leaves a queued `QImageCapture::errorOccurred` callback to run after `VerifyThread::Stop()` resets the camera, `VerifyThread::Stop()` disconnects only `imageCaptured`, then stops and resets `m_camera` while `errorOccurred` remains connected to `captureError()`. A delayed capture error therefore reaches `captureError()` with `m_camera` null, and its dereference crashes the service.
Disconnect `errorOccurred` (and other capture callbacks) before stopping the camera, and guard `captureError()` against a null camera.
Also at `workmodule.cpp:579`.
</issue_to_address>
### Comment 2
<location path="workmodule.cpp" line_range="166" />
<code_context>
qDebug() << "read camera fail:" << errorString;
- Q_EMIT processStatus(m_actionId, FaceEnrollException);
+ // 摄像头被开关关闭时设备会消失,按“未开启摄像头”上报;其余场景按录入异常处理
+ if (QMediaDevices::videoInputs().isEmpty()) {
+ Q_EMIT processStatus(m_actionId, FaceEnrollCameraNotEnabled);
+ } else {
</code_context>
<issue_to_address>
**Camera loss is misreported**
When the selected camera disappears while another input remains, or stays listed but unavailable, `checkCameraAvailable()` returns because the global input list is nonempty, while `captureError()` reports an exception; a silent backend leaves the operation stuck, and an error callback gives the caller the wrong status.
Check whether the camera selected for the operation is still available in both the watchdogs and `captureError()` handlers, and report camera-not-enabled when it is not.
Also at `workmodule.cpp:181-188`, `workmodule.cpp:429-433`, `workmodule.cpp:441-449`.
</issue_to_address>
### Comment 3
<location path="workmodule.cpp" line_range="55" />
<code_context>
- Q_EMIT processStatus(m_actionId, FaceEnrollException);
+ qDebug() << "open camera fail: no camera device";
+ // 摄像头开关关闭/未开启时设备不存在,上报专用状态码,由调用方提示“未开启摄像头”
+ Q_EMIT processStatus(m_actionId, FaceEnrollCameraNotEnabled);
return;
}
</code_context>
<issue_to_address>
**Unavailable cameras go undetected**
When every enumerated camera reports `isAvailable() == false`, the camera-selection loops leave `m_camera` non-null, so the no-camera branch is skipped; capture starts and the watchdog sees a nonempty input list, leaving the action waiting or reporting the wrong status.
Select only available cameras and report camera-not-enabled when none are available.
Also at `workmodule.cpp:181`, `workmodule.cpp:395-396`, `workmodule.cpp:441`.
</issue_to_address>2ad5597 to
c4bfd52
Compare
|
Thanks for the review. All three points are addressed in c4bfd52 (also rebased onto the latest master):
Re-verified on Inspur CP300F3 (UOS 25, arm64):
|
|
/retest |
|
/recheck |
|
/test github-pr-review-ci |
1. CharaType no longer follows the camera switch state: always report
FACECHARATYPE so the control center keeps showing the biometric
(face) entry after the camera FN key is toggled off; remove the
/dev video node watcher that zeroed CharaType.
2. Add FaceEnrollCameraNotEnabled / FaceVerifyCameraNotEnabled (15) to
report that the camera is not enabled. 13/14 stay reserved for the
vendor/sender disconnect codes used by deepin-authentication.
3. Report the new status when no camera device exists before capture,
and when the device disappears during capture (captureError).
4. Add a 1s runtime watchdog in the enroll/verify threads: after the
camera is switched off the Qt backend may neither raise an error nor
deliver frames, leaving the operation silent; the watchdog reports
the new status as a fallback.
5. Guard against null camera/imageCapture in ErollThread/VerifyThread
Stop() because the camera may never have been opened.
6. Fix VerifyThread::captureError reporting FaceEnrollException.
7. Listen to the camera privacy DConfig written by SetCameraPrivacy
(org.deepin.dde.daemon / org.deepin.dde.daemon.system /
cameraPrivacyEnabled) and abort the active enrollment/verification
with the new status as soon as the switch turns on, without waiting
for the watchdog.
8. Query GetCameraPrivacy (org.deepin.dde.Daemon1) at key points (no
camera device at start, captureError, watchdog) to confirm the real
hardware/driver state; this also covers the V4L2 privacy control
case where the device node remains and Qt still reports the camera
as available. Fall back to the local heuristic when the interface is
unavailable (older dde-daemon).
9. Report the camera-not-enabled status at most once per action so the
DConfig event, watchdog and device check cannot end the same
operation twice.
Log: fix face entry disappearing after camera FN key toggle
Influence:
1. Camera FN key off: the face entry stays visible in the control
center and adding a face prompts "Camera is not enabled".
2. Camera FN key on: enrollment and verification work as before.
3. Camera switched off during enrollment/verification: the new status
is reported immediately via the privacy switch event (watchdog as
fallback), and resources are released without crashing.
4. Camera occupied by another application: still reported as an
enrollment exception ("Camera occupied!").
fix: 摄像头未开启上报专用状态码并保持人脸入口始终展示
1. CharaType 不再跟随摄像头开关状态,恒上报 FACECHARATYPE,摄像头
FN 键关闭后控制中心仍展示生物认证(人脸)入口;移除 /dev 视频
节点监听(原先设备消失时会把 CharaType 置 0)。
2. 新增 FaceEnrollCameraNotEnabled/FaceVerifyCameraNotEnabled(15),
用于上报摄像头未开启;13/14 保留给 deepin-authentication 内部的
厂商断开/发起方断开状态码。
3. 采集前无摄像头设备、采集过程中设备消失(captureError)时上报
新状态码。
4. 录入/验证线程新增 1 秒运行期看门狗:摄像头被关闭后 Qt 后端可能
既不报错也不回调,导致流程静默卡住,由看门狗兜底上报新状态码。
5. ErollThread/VerifyThread 的 Stop() 增加空指针防护,摄像头未成功
打开时不再对空指针调用 stop()。
6. 修正 VerifyThread::captureError 误发 FaceEnrollException 的问题。
7. 监听 SetCameraPrivacy 写入的相机隐私开关 DConfig
(org.deepin.dde.daemon / org.deepin.dde.daemon.system /
cameraPrivacyEnabled),开关打开时立即以新状态码结束当前录入/
验证,无需等待看门狗。
8. 在关键点(启动无相机设备、captureError、看门狗)调用
GetCameraPrivacy(org.deepin.dde.Daemon1)校验真实硬件/驱动状态,
同时覆盖 V4L2 遮挡控制下设备节点仍在、Qt 仍认为可用的场景;
旧版本 dde-daemon 无此接口时回退本地判断。
9. 每个操作只上报一次“摄像头未开启”状态,DConfig 事件、看门狗与
设备检测不会重复结束同一操作。
Log: 修复摄像头FN键关闭后人脸入口不展示问题
Influence:
1. 摄像头 FN 键关闭:控制中心仍展示人脸入口,添加人脸时提示
“未开启摄像头”。
2. 摄像头 FN 键开启:录入、验证功能正常。
3. 录入/验证过程中关闭摄像头:通过开关事件立即上报新状态码
(看门狗兜底),资源正常释放,服务不崩溃。
4. 摄像头被其他应用占用:仍按录入异常提示“摄像头被占用!”。
PMS: BUG-377629
c4bfd52 to
ca35861
Compare
|
/retest |
1 similar comment
|
/retest |
|
/retest |
deepin pr auto reviewAI 代码审查报告
总体评价
评价结论: 代码审查通过(有改进建议) 评价原因: 未发现安全漏洞,代码整体实现符合修复目标。存在1处逻辑缺陷(VerifyThread缺少m_stopCapture防护守卫,构成竞态条件)需要修复,另有代码重复和性能优化建议。 漏洞统计
漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个 四维度评分维度1:语法逻辑 ✓✕ ✕ | 10 / 25 分评价词: 存在逻辑缺陷 问题列表:
// workmodule.h - VerifyThread 类中添加:
private:
std::atomic<bool> m_stopCapture{false};
// workmodule.cpp - VerifyThread::checkCameraAvailable 开头添加:
void VerifyThread::checkCameraAvailable()
{
if (m_stopCapture)
return;
// ... 原有逻辑
}
// workmodule.cpp - VerifyThread::Stop 中添加:
void VerifyThread::Stop()
{
m_stopCapture = true; // 添加此行
if (m_cameraWatchTimer) {
m_cameraWatchTimer->stop();
}
// ... 原有逻辑
}维度2:代码质量 ✓ | 21 / 25 分评价词: 代码结构清晰,注释完整 问题列表:
维度3:代码性能 ✓ | 18 / 20 分评价词: 性能良好,资源使用合理 问题列表:
维度4:代码安全 ✓ | 30 / 30 分评价词: 存在0个安全漏洞 无安全风险,代码安全合规。 新增的空指针防护(Stop() 中对 m_camera、m_imageCapture、m_cameraWatchTimer 的空检查)提升了代码的防御性编程质量。 代码目的匹配分析Commit 目的: 修复摄像头FN键关闭后人脸入口不展示问题,新增摄像头未开启专用状态码,添加运行期看门狗和空指针防护 匹配度分析:
修改文件清单
审查结论本次 PR 旨在修复摄像头 FN 键关闭后人脸入口消失的问题,整体实现质量较高,代码注释详尽,防御性编程有所增强。主要存在以下需要关注的问题:
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: fly602, Ivy233 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 |
… visible (linuxdeepin#59)" This reverts commit 17bd7f2. The change removed the /dev video-node watcher and always reported FACECHARATYPE, so the control center still showed the face entry on machines without a camera (BUG-379893). Revert it and restore the previous behavior. 1. Remove FaceEnrollCameraNotEnabled / FaceVerifyCameraNotEnabled (15) from the status enums, the corresponding status messages and the service interface documentation. 2. Remove the camera privacy DConfig watch, the 1-second runtime watchdog in the enroll/verify threads, the queryCameraPrivacy()/ GetCameraPrivacy checks and the camera-not-enabled reporting paths; restore the previous captureError handling and Stop() behavior in ErollThread/VerifyThread. 3. Restore the /dev video-node watcher in DriverManger::init(); CharaType again follows the camera device presence, so the face entry is hidden when the camera is switched off. Log: revert camera-not-enabled status reporting and restore the /dev watcher Influence: 1. Camera FN key off: the face entry is hidden again as before the change; enrollment/verification with the camera off restore the previous generic error handling. 2. Camera on: enrollment and verification work normally. 3. Machines without a camera: the face entry is hidden again (the restored /dev watcher sets EMPTYCHARATYPE). Revert "fix: 摄像头未开启上报专用状态码并保持人脸入口始终展示" 此提交回退 17bd7f2。 该提交移除了 /dev 视频节点监听并恒上报 FACECHARATYPE,导致无摄像头 机型控制中心仍展示人脸入口(BUG-379893)。现回退该改动,恢复原有 行为。 1. 从状态枚举、状态文案及服务接口文档中移除 FaceEnrollCameraNotEnabled / FaceVerifyCameraNotEnabled(15)。 2. 移除相机隐私 DConfig 监听、录入/验证线程的 1 秒看门狗、 queryCameraPrivacy()/GetCameraPrivacy 查询及“摄像头未开启”上报 路径;ErollThread/VerifyThread 的 captureError 处理与 Stop() 行为 恢复原有实现。 3. 恢复 DriverManger::init() 中的 /dev 视频节点监听,CharaType 重新 跟随摄像头设备状态,摄像头关闭时人脸入口恢复隐藏。 Log: 回退摄像头未开启状态码上报并恢复 /dev 视频节点监听 Influence: 1. 摄像头FN键关闭:人脸入口恢复隐藏(与改动前一致);摄像头未开启 时录入/验证恢复原有通用错误处理。 2. 摄像头正常:录入、验证流程正常工作。 3. 无摄像头机型:人脸入口恢复隐藏(恢复的 /dev 监听会置为 EMPTYCHARATYPE)。 PMS: BUG-379893
… visible (linuxdeepin#59)" This reverts commit 17bd7f2. The change removed the /dev video-node watcher and always reported FACECHARATYPE, so the control center still showed the face entry on machines without a camera (BUG-379893). Revert it and restore the previous behavior. 1. Remove FaceEnrollCameraNotEnabled / FaceVerifyCameraNotEnabled (15) from the status enums, the corresponding status messages and the service interface documentation. 2. Remove the camera privacy DConfig watch, the 1-second runtime watchdog in the enroll/verify threads, the queryCameraPrivacy()/ GetCameraPrivacy checks and the camera-not-enabled reporting paths; restore the previous captureError handling and Stop() behavior in ErollThread/VerifyThread. 3. Restore the /dev video-node watcher in DriverManger::init(); CharaType again follows the camera device presence, so the face entry is hidden when the camera is switched off. Log: revert camera-not-enabled status reporting and restore the /dev watcher Influence: 1. Camera FN key off: the face entry is hidden again as before the change; enrollment/verification with the camera off restore the previous generic error handling. 2. Camera on: enrollment and verification work normally. 3. Machines without a camera: the face entry is hidden again (the restored /dev watcher sets EMPTYCHARATYPE). Revert "fix: 摄像头未开启上报专用状态码并保持人脸入口始终展示" 此提交回退 17bd7f2。 该提交移除了 /dev 视频节点监听并恒上报 FACECHARATYPE,导致无摄像头 机型控制中心仍展示人脸入口(BUG-379893)。现回退该改动,恢复原有 行为。 1. 从状态枚举、状态文案及服务接口文档中移除 FaceEnrollCameraNotEnabled / FaceVerifyCameraNotEnabled(15)。 2. 移除相机隐私 DConfig 监听、录入/验证线程的 1 秒看门狗、 queryCameraPrivacy()/GetCameraPrivacy 查询及“摄像头未开启”上报 路径;ErollThread/VerifyThread 的 captureError 处理与 Stop() 行为 恢复原有实现。 3. 恢复 DriverManger::init() 中的 /dev 视频节点监听,CharaType 重新 跟随摄像头设备状态,摄像头关闭时人脸入口恢复隐藏。 Log: 回退摄像头未开启状态码上报并恢复 /dev 视频节点监听 Influence: 1. 摄像头FN键关闭:人脸入口恢复隐藏(与改动前一致);摄像头未开启 时录入/验证恢复原有通用错误处理。 2. 摄像头正常:录入、验证流程正常工作。 3. 无摄像头机型:人脸入口恢复隐藏(恢复的 /dev 监听会置为 EMPTYCHARATYPE)。 PMS: BUG-379893
… visible (#59)" (#63) This reverts commit 17bd7f2. The change removed the /dev video-node watcher and always reported FACECHARATYPE, so the control center still showed the face entry on machines without a camera (BUG-379893). Revert it and restore the previous behavior. 1. Remove FaceEnrollCameraNotEnabled / FaceVerifyCameraNotEnabled (15) from the status enums, the corresponding status messages and the service interface documentation. 2. Remove the camera privacy DConfig watch, the 1-second runtime watchdog in the enroll/verify threads, the queryCameraPrivacy()/ GetCameraPrivacy checks and the camera-not-enabled reporting paths; restore the previous captureError handling and Stop() behavior in ErollThread/VerifyThread. 3. Restore the /dev video-node watcher in DriverManger::init(); CharaType again follows the camera device presence, so the face entry is hidden when the camera is switched off. Log: revert camera-not-enabled status reporting and restore the /dev watcher Influence: 1. Camera FN key off: the face entry is hidden again as before the change; enrollment/verification with the camera off restore the previous generic error handling. 2. Camera on: enrollment and verification work normally. 3. Machines without a camera: the face entry is hidden again (the restored /dev watcher sets EMPTYCHARATYPE). Revert "fix: 摄像头未开启上报专用状态码并保持人脸入口始终展示" 此提交回退 17bd7f2。 该提交移除了 /dev 视频节点监听并恒上报 FACECHARATYPE,导致无摄像头 机型控制中心仍展示人脸入口(BUG-379893)。现回退该改动,恢复原有 行为。 1. 从状态枚举、状态文案及服务接口文档中移除 FaceEnrollCameraNotEnabled / FaceVerifyCameraNotEnabled(15)。 2. 移除相机隐私 DConfig 监听、录入/验证线程的 1 秒看门狗、 queryCameraPrivacy()/GetCameraPrivacy 查询及“摄像头未开启”上报 路径;ErollThread/VerifyThread 的 captureError 处理与 Stop() 行为 恢复原有实现。 3. 恢复 DriverManger::init() 中的 /dev 视频节点监听,CharaType 重新 跟随摄像头设备状态,摄像头关闭时人脸入口恢复隐藏。 Log: 回退摄像头未开启状态码上报并恢复 /dev 视频节点监听 Influence: 1. 摄像头FN键关闭:人脸入口恢复隐藏(与改动前一致);摄像头未开启 时录入/验证恢复原有通用错误处理。 2. 摄像头正常:录入、验证流程正常工作。 3. 无摄像头机型:人脸入口恢复隐藏(恢复的 /dev 监听会置为 EMPTYCHARATYPE)。 PMS: BUG-379893
Log: fix face entry disappearing after camera FN key toggle
Influence:
fix: 摄像头未开启上报专用状态码并保持人脸入口始终展示
Log: 修复摄像头FN键关闭后人脸入口不展示问题
Influence:
PMS: BUG-377629
Summary by Sourcery
Keep the face entry visible while reporting camera-disabled conditions through dedicated status codes and robustly terminating affected operations.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Chores: