Skip to content

fix: report camera-not-enabled status and keep the face entry visible - #59

Merged
Ivy233 merged 1 commit into
linuxdeepin:masterfrom
Ivy233:fix-face-camera-not-enabled
Oct 12, 2026
Merged

Ivy233 merged 1 commit into
linuxdeepin:masterfrom
Ivy233:fix-face-camera-not-enabled

Conversation

@Ivy233

@Ivy233 Ivy233 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor
  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.

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 promptly 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 的问题。

Log: 修复摄像头FN键关闭后人脸入口不展示问题

Influence:

  1. 摄像头 FN 键关闭:控制中心仍展示人脸入口,添加人脸时提示 “未开启摄像头”。
  2. 摄像头 FN 键开启:录入、验证功能正常。
  3. 录入/验证过程中关闭摄像头:及时上报新状态码,资源正常释放, 服务不崩溃。
  4. 摄像头被其他应用占用:仍按录入异常提示“摄像头被占用!”。

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:

  • Add dedicated enrollment and verification status codes for reporting that the camera is not enabled.
  • Keep the face biometric entry available regardless of the camera privacy-switch state.

Bug Fixes:

  • Report camera-disabled conditions before or during capture and prevent face operations from stalling or crashing when the camera becomes unavailable.
  • Correct verification capture errors to report verification exceptions.

Enhancements:

  • Add privacy-switch monitoring and runtime camera availability watchdogs to terminate active operations promptly.
  • Preserve existing enrollment-exception reporting for cases such as camera occupation while adding null-safety during operation shutdown.

Documentation:

  • Document the new camera-not-enabled enrollment and verification status codes.

Chores:

  • Remove the /dev video-node watcher used to hide face capability when the camera was disabled.

@sourcery-ai

sourcery-ai Bot commented Oct 9, 2026

Copy link
Copy Markdown

Reviewer's Guide

The 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 handling

sequenceDiagram
    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
Loading

Sequence diagram for camera-unavailable verification handling

sequenceDiagram
    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
Loading

File-Level Changes

Change Details Files
Keep face capability advertised independently of camera availability by removing device-node-driven capability changes.
  • Always initialize the character type as FACECHARATYPE.
  • Remove the /dev filesystem watcher and its directory-change handler.
  • Retain the face entry so camera availability is reported during the requested operation.
drivermanger.cpp
drivermanger.h
Define and expose dedicated status code 15 values for camera-not-enabled conditions.
  • Add separate enrollment and verification camera-not-enabled enum values while preserving codes 13/14 for internal disconnect states.
  • Document the new status values and map them to user-facing status messages.
definehead.h
doc/uos-biometric-authentication-service-interface.md
drivermanger.cpp
Detect camera absence before and during enrollment or verification and report the dedicated status.
  • Report camera-not-enabled when no camera can be opened.
  • Classify capture errors based on whether video inputs have disappeared.
  • Add one-second watchdog timers to cover backend failures that produce neither errors nor frames.
  • Stop watchdogs and guard camera/image-capture cleanup when resources were never initialized.
workmodule.cpp
workmodule.h
Correct verification capture failures to emit verification-specific exceptions.
  • Use FaceVerifyException for non-camera verification capture errors instead of FaceEnrollException.
workmodule.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

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

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread workmodule.cpp Resolved
Comment thread workmodule.cpp Resolved
Comment thread workmodule.cpp Resolved
@BLumia BLumia closed this Oct 9, 2026
@BLumia BLumia reopened this Oct 9, 2026
@Ivy233
Ivy233 force-pushed the fix-face-camera-not-enabled branch from 2ad5597 to c4bfd52 Compare October 9, 2026 07:21
@Ivy233

Ivy233 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. All three points are addressed in c4bfd52 (also rebased onto the latest master):

  1. Late verify error can crash service (High) — VerifyThread::Stop() now disconnects all capture callbacks (readyForCaptureChanged, imageCaptured, errorOccurred) before stopping and releasing the camera, and captureError() in both threads returns early when the camera is null.

  2. Camera loss is misreported (Medium) — Each thread now remembers the QCameraDevice selected for the operation; the watchdog and captureError() check whether that specific device is still enumerated and available instead of looking at the global device list, so losing the selected camera while other inputs remain is reported as camera-not-enabled.

  3. Unavailable cameras go undetected (Medium) — The camera selection loops now track whether an available camera was found and report camera-not-enabled instead of starting capture when none of the enumerated cameras is available.

Re-verified on Inspur CP300F3 (UOS 25, arm64):

  • camera off: enrollment and verification report status 15 (camera-not-enabled);
  • camera switched off during enrollment: status 15 is reported promptly and the service does not crash;
  • camera occupied by another process: still reported as an enrollment exception ("Camera occupied"), no behavior change.

@Ivy233

Ivy233 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@Ivy233

Ivy233 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

/recheck

@hudeng-go

Copy link
Copy Markdown
Contributor

/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
@Ivy233
Ivy233 force-pushed the fix-face-camera-not-enabled branch from c4bfd52 to ca35861 Compare October 9, 2026 10:17
@Ivy233

Ivy233 commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

/retest

1 similar comment
@Ivy233

Ivy233 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@Ivy233
Ivy233 requested review from fly602 and robertkill October 12, 2026 02:40
@Ivy233

Ivy233 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

AI 代码审查报告

项目: linuxdeepin/deepin-face
PR: #59 - fix: report camera-not-enabled status and keep the face entry visible
作者: Ivy233
分支: fix-face-camera-not-enabled → master
Commit: ca35861
分析模式: 全量分析
审查时间: 2026-10-12


总体评价

总分 等级 风险等级
79 / 100 及格 None

评价结论: 代码审查通过(有改进建议)

评价原因: 未发现安全漏洞,代码整体实现符合修复目标。存在1处逻辑缺陷(VerifyThread缺少m_stopCapture防护守卫,构成竞态条件)需要修复,另有代码重复和性能优化建议。


漏洞统计

指标 数量
当前漏洞总数 0
新增漏洞 0
修复漏洞 0
持平漏洞 0

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


四维度评分

维度1:语法逻辑 ✓✕ ✕ | 10 / 25 分

评价词: 存在逻辑缺陷

问题列表:

  1. [严重错误 -15分] workmodule.cpp VerifyThread::checkCameraAvailable (第538行)
    • VerifyThread::checkCameraAvailable 缺少 m_stopCapture 防护守卫
    • ErollThread::checkCameraAvailable(第237行)在函数开头有 if (m_stopCapture) return; 防护,但 VerifyThread::checkCameraAvailable(第538行)没有此防护
    • 同时 VerifyThread 类根本没有声明 m_stopCapture 成员变量(workmodule.h 确认,仅 ErollThread 在第59行声明了 std::atomic<bool> m_stopCapture)
    • 当 Stop() 通过 BlockingQueuedConnection 调用后,定时器已停止但事件队列中可能仍有待处理的 timeout 事件,该事件触发后 checkCameraAvailable 会在会话已拆除的情况下继续执行 DBus 查询和信号发射,构成竞态条件
    • 修复建议: 为 VerifyThread 添加 std::atomic<bool> m_stopCapture{false} 成员变量,在 Stop() 中设置为 true,并在 checkCameraAvailable() 开头添加 if (m_stopCapture) return; 防护守卫,与 ErollThread 保持一致
// 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 分

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

问题列表:

  1. [一般问题 -2分] workmodule.cpp ErollThread 和 VerifyThread 之间存在大量代码重复

    • isCameraUnavailable()、checkCameraAvailable()、captureError() 逻辑以及 run() 中摄像头打开逻辑几乎完全相同
    • 虽然此重复模式在原有代码中已存在,但本次新增代码进一步加深了重复
    • 建议: 考虑提取公共逻辑到基类或辅助函数中
  2. [轻微问题 -2分] workmodule.cpp queryCameraPrivacy (第24行)

    • known 参数命名具有误导性
    • 该参数实际存储的是 DBus 返回的第二个布尔值(表示隐私开关是否已启用),而非简单的查询是否成功标志
    • 调用方使用 if (privacyOn && privacyKnown) 读取为"隐私已开启且我们知道",但 privacyKnown 实际持有的是 DBus 返回值
    • 建议: 重命名为 privacyEnabled 或更清晰的名称

维度3:代码性能 ✓ | 18 / 20 分

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

问题列表:

  1. [一般优化 -2分] workmodule.cpp queryCameraPrivacy / checkCameraAvailable (第34行)
    • queryCameraPrivacy() 执行阻塞式 DBus 调用,超时为 1000ms
    • 该函数被看门狗定时器每秒调用一次(ErollThread::checkCameraAvailable 和 VerifyThread::checkCameraAvailable)
    • 如果 DBus 服务响应缓慢或不可用,工作线程可能在每个定时器周期内被阻塞接近 1000ms,影响录入/验证流水线的响应性
    • 建议: 考虑将看门狗定时器间隔增大至 2-3 秒,或将 DBus 超时减少至 500ms,或使用异步 DBus 调用

维度4:代码安全 ✓ | 30 / 30 分

评价词: 存在0个安全漏洞

无安全风险,代码安全合规。

新增的空指针防护(Stop() 中对 m_camera、m_imageCapture、m_cameraWatchTimer 的空检查)提升了代码的防御性编程质量。


代码目的匹配分析

Commit 目的: 修复摄像头FN键关闭后人脸入口不展示问题,新增摄像头未开启专用状态码,添加运行期看门狗和空指针防护

匹配度分析:

修改项 是否符合目的 说明
CharaType 恒上报 FACECHARATYPE ✅ 符合"人脸入口始终展示"目标
新增 FaceEnrollCameraNotEnabled/FaceVerifyCameraNotEnabled(15) ✅ 符合"新增专用状态码"目标
移除 /dev 视频节点监听 ✅ 符合"解耦人脸能力与摄像头状态"目标
新增 DConfig 相机隐私开关监听 ✅ 符合"第一时间结束操作"目标
新增 1 秒运行期看门狗 ✅ 符合"防止流程静默卡住"目标
Stop() 空指针防护 ✅ 符合"防止空指针崩溃"目标
修正 VerifyThread::captureError 误发 FaceEnrollException ✅ 符合"修正错误上报"目标

修改文件清单

文件 修改内容
definehead.h 新增 FaceEnrollCameraNotEnabled/FaceVerifyCameraNotEnabled 枚举值,显式指定枚举编号
doc/uos-biometric-authentication-service-interface.md 文档更新,同步新增状态码说明
drivermanger.cpp 移除 /dev 文件监听,新增 DConfig 相机隐私开关监听,新增状态去重逻辑,新增状态消息
drivermanger.h 移除 QFileSystemWatcher,新增 cameraNotEnabledReported 字段,新增 initCameraPrivacyWatch 声明
workmodule.cpp 新增 queryCameraPrivacy 函数,新增看门狗定时器,新增空指针防护,新增 isCameraUnavailable 方法,修正 captureError 状态码
workmodule.h 新增 QCameraDevice 成员,新增 QTimer 看门狗成员,新增方法声明

审查结论

本次 PR 旨在修复摄像头 FN 键关闭后人脸入口消失的问题,整体实现质量较高,代码注释详尽,防御性编程有所增强。主要存在以下需要关注的问题:

  1. 需修复: VerifyThread::checkCameraAvailable 缺少 m_stopCapture 防护守卫,与 ErollThread 不一致,存在竞态条件风险
  2. 建议改进: ErollThread 和 VerifyThread 代码重复较多,建议提取公共逻辑
  3. 建议优化: 看门狗中的阻塞 DBus 调用可能影响工作线程响应性

@deepin-ci-robot

Copy link
Copy Markdown

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

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

@Ivy233
Ivy233 merged commit 17bd7f2 into linuxdeepin:master Oct 12, 2026
6 checks passed
@Ivy233
Ivy233 deleted the fix-face-camera-not-enabled branch October 12, 2026 08:11
Ivy233 added a commit to Ivy233/deepin-face that referenced this pull request Oct 16, 2026
… 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
Ivy233 added a commit to Ivy233/deepin-face that referenced this pull request Oct 16, 2026
… 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
Ivy233 added a commit that referenced this pull request Oct 16, 2026
… 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
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.

5 participants