Skip to content

Revert "fix: report camera-not-enabled status and keep the face entry visible" - #62

Draft
Ivy233 wants to merge 1 commit into
masterfrom
revert-59-fix-face-camera-not-enabled
Draft

Ivy233 wants to merge 1 commit into
masterfrom
revert-59-fix-face-camera-not-enabled

Conversation

@Ivy233

@Ivy233 Ivy233 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Reverts #59

Summary by Sourcery

Revert dedicated camera privacy and camera-not-enabled reporting behavior in favor of the previous face authentication flow.

Enhancements:

  • Restore the previous camera detection and face capability behavior without dedicated camera-not-enabled status reporting.
  • Remove camera privacy switch integration and runtime availability monitoring from enrollment and verification flows.
  • Restore filesystem-based detection of video devices to update face capability availability.

Documentation:

  • Remove camera-not-enabled status values from the biometric authentication interface documentation.

Chores:

  • Revert the dedicated camera-not-enabled enrollment and verification status codes and related handling.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 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

@github-actions

Copy link
Copy Markdown

CLA Assistant Lite bot:

如果你是以企业贡献者的身份进行提交,请联系我们签署企业贡献者许可协议
If you submit as corporate contributor, please contact us to sign our Corporate Contributor License Agreement

感谢您的提交,我们非常感谢。 像许多开源项目一样,在接受您的贡献之前,我们要求您签署我们的个人贡献者许可协议。 您只需发布与以下格式相同的评论即可签署个人贡献者许可协议。
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Individual Contributor License Agreement before we can accept your contribution. You can sign the Individual Contributor License Agreement by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA.

You can retrigger this bot by commenting recheck in this Pull Request

@sourcery-ai

sourcery-ai Bot commented Oct 16, 2026

Copy link
Copy Markdown

Reviewer's Guide

This PR reverts the previous camera privacy and camera-not-enabled behavior: status enums, documentation, privacy monitoring, DBus queries, watchdog detection, and deduplication are removed; camera failures again report generic exceptions, while face capability is determined by watching /dev/ for video devices.

Flow diagram for camera capability detection and failure reporting

flowchart TD
    Init["DriverManger::init"] --> Watch["QFileSystemWatcher watches /dev/"]
    Watch --> Change["onDirectoryChanged"]
    Change --> Video{Video device found}
    Video -->|Yes| Face["setCharaType(FACECHARATYPE)"]
    Video -->|No| Empty["setCharaType(EMPTYCHARATYPE)"]
    Start["ErollThread::run or VerifyThread::run"] --> Camera["QMediaDevices::videoInputs"]
    Camera --> Available{Camera available}
    Available -->|Yes| Capture["Start capture"]
    Available -->|No| Exception["processStatus(..., FaceEnrollException)"]
    Capture --> Error["captureError"]
    Error --> Exception
Loading

File-Level Changes

Change Details Files
Revert the dedicated camera-not-enabled status and privacy-state handling, restoring generic exception reporting for camera failures.
  • Remove camera-not-enabled enum values and API documentation entries.
  • Remove DConfig privacy monitoring, DBus privacy queries, camera availability watchdogs, and duplicate-status suppression.
  • Report camera initialization and capture failures as exception statuses instead.
definehead.h
doc/uos-biometric-authentication-service-interface.md
drivermanger.cpp
drivermanger.h
workmodule.cpp
workmodule.h
Restore camera presence-based face capability detection using filesystem monitoring of /dev/.
  • Add a QFileSystemWatcher for /dev/ and update face capability when directory contents change.
  • Set the capability to face-enabled when a video device is found, otherwise clear it.
drivermanger.cpp
drivermanger.h
Revert defensive camera-stop and capture cleanup changes introduced by the previous fix.
  • Remove null-safe camera and capture cleanup paths during stop.
  • Return to stopping the camera directly and disconnecting fewer capture signals.
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 reviewed your changes and they look great!


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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

AI 代码审查报告

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


总体评价

总分: 65/100 (不及格)
风险等级: Medium
总体评价: 代码审查不通过

本次 PR 是对 PR #59 的 Revert 操作,撤销了"摄像头未开启状态报告和人脸入口可见性保持"功能,恢复到原始实现。Revert 操作本身目的明确,但恢复后的代码重新引入了原始版本中存在的空指针解引用缺陷:当摄像头设备不可用时,run() 方法提前返回导致 m_camera 为空,而 Stop() 方法中未做空指针防护直接调用 m_camera->stop() 将导致程序崩溃。建议在 Revert 时同步修复这些已知缺陷。

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


四维度评分

维度1: 语法逻辑 (0/25) ✕

评价词: 存在逻辑缺陷

问题列表:

  1. 严重错误 - 空指针解引用: ErollThread::Stop() (workmodule.cpp:76)

    • 当 ErollThread::run() 因无摄像头设备(m_camera.isNull() 为 true)提前返回时,m_camera 和 m_imageCapture 均为空。随后调用 enrollStop() → Stop() 时,第 76 行 m_camera->stop() 将导致空指针解引用崩溃。
    • 触发场景:摄像头在 init 后被移除,QMediaDevices::videoInputs() 返回空列表,run() 提前返回,用户调用 enrollStop()
    • 修复建议:在调用 m_camera->stop() 前增加 if (!m_camera.isNull()) 空指针防护
    void ErollThread::Stop()
    {
        qDebug() << "ErollThread::Stop thread:" << QThread::currentThreadId();
        if (!m_imageCapture.isNull()) {
            disconnect(m_imageCapture.data(), &QImageCapture::readyForCaptureChanged, this, &ErollThread::readyForCapture);
            disconnect(m_imageCapture.data(), &QImageCapture::imageCaptured, this, &ErollThread::processCapturedImage);
            disconnect(m_imageCapture.data(), QOverload<int, QImageCapture::Error, const QString &>::of(&QImageCapture::errorOccurred),
                    this, &ErollThread::captureError);
        }
        m_stopCapture = true;
        if (!m_camera.isNull()) {
            m_camera->stop();
        }
        m_camera.reset();
        // ...
    }
  2. 严重错误 - 空指针解引用: VerifyThread::Stop() (workmodule.cpp:510)

    • 同上,VerifyThread::run() 在无摄像头设备时提前返回,m_camera 为空。Stop() 中第 510 行 m_camera->stop() 将导致空指针解引用崩溃。
    • 触发场景:与 ErollThread 相同,摄像头不可用时调用 verifyStop()
    • 修复建议:增加 if (!m_camera.isNull()) 和 if (!m_imageCapture.isNull()) 空指针防护
    void VerifyThread::Stop()
    {
        qDebug() << "VerifyThread::Stop thread:" << QThread::currentThreadId();
        disconnect(m_imageCapture.data(), &QImageCapture::imageCaptured, this, &VerifyThread::processCapturedImage);
        if (!m_camera.isNull()) {
            m_camera->stop();
        }
        for (int i = 0; i < m_charaDatas.size(); i++) {
            if (m_charaDatas[i] != nullptr) {
                free(m_charaDatas[i]);
            }
        }
        m_camera.reset();
        m_charaDatas.clear();
    }
  3. 轻微问题 - 枚举值使用不当: VerifyThread::run() (workmodule.cpp:352) 和 VerifyThread::captureError() (workmodule.cpp:384)

    • VerifyThread 中使用了 FaceEnrollException(EnrollStatus 枚举值)代替 FaceVerifyException(VerifyStatus 枚举值)。虽然两者在枚举中的整数值均为 12,功能上不影响,但语义上不正确,影响代码可读性和可维护性。
    • 修复建议:将 VerifyThread::run() 和 VerifyThread::captureError() 中的 FaceEnrollException 改为 FaceVerifyException

维度2: 代码质量 (21/25) ✓

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

问题列表:

  1. 版权年份回归 (definehead.h:1, drivermanger.h:1)

    • SPDX 版权声明从 2022 - 2026 回退为 2022,丢失了当前年份范围。即使是 Revert 操作,版权年份应保持当前年份。
    • 扣分: -2
  2. 错误路径处理不完善 (workmodule.cpp:68-85, 504-518)

    • ErollThread::Stop() 和 VerifyThread::Stop() 未对 m_camera 和 m_imageCapture 做空指针检查就直接访问,错误路径处理不完善。(与语法逻辑维度的问题重叠,此处从代码质量角度扣分)
    • 扣分: -2

优点:

  • onDirectoryChanged() 方法有清晰的注释说明逻辑
  • init() 中有"暂不支持热插拔"的说明注释
  • 代码结构清晰,无重复代码
  • 无残留调试代码

维度3: 代码性能 (20/20) ✓

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

分析:

  • Revert 操作移除了 PR fix: report camera-not-enabled status and keep the face entry visible #59 中引入的 1 秒间隔轮询定时器(QTimer),恢复了事件驱动的 QFileSystemWatcher 机制,降低了 CPU 开销
  • 移除了 DConfig 和 DBus 轮询查询,减少了系统总线通信开销
  • onDirectoryChanged() 仅在 /dev/ 目录变化时触发,事件驱动方式性能良好
  • 无不必要的内存拷贝或资源泄漏

维度4: 代码安全 (30/30) ✓

存在0个安全漏洞

分析:

  • 本次变更未引入任何安全漏洞
  • 无硬编码密钥、命令注入、SQL注入、路径遍历等安全风险
  • 无敏感信息泄露
  • 无不安全的密码算法使用
  • 漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个

修改文件清单

文件 修改类型 说明
definehead.h 修改 移除 FaceEnrollCameraNotEnabled/FaceVerifyCameraNotEnabled 枚举值
doc/uos-biometric-authentication-service-interface.md 修改 移除摄像头未开启状态相关文档
drivermanger.cpp 修改 移除 DConfig 隐私开关监听,恢复 QFileSystemWatcher 设备检测
drivermanger.h 修改 移除 initCameraPrivacyWatch 声明和 cameraNotEnabledReported 字段
workmodule.cpp 修改 移除看门狗定时器、queryCameraPrivacy、isCameraUnavailable 等
workmodule.h 修改 移除 QTimer、QCameraDevice 等相关声明

改进建议

建议修复代码示例

修复 ErollThread::Stop() 空指针崩溃:

void ErollThread::Stop()
{
    qDebug() << "ErollThread::Stop thread:" << QThread::currentThreadId();
    
    // 增加空指针防护,避免摄像头未打开成功时崩溃
    if (!m_imageCapture.isNull()) {
        disconnect(m_imageCapture.data(), &QImageCapture::readyForCaptureChanged, this, &ErollThread::readyForCapture);
        disconnect(m_imageCapture.data(), &QImageCapture::imageCaptured, this, &ErollThread::processCapturedImage);
        disconnect(m_imageCapture.data(), QOverload<int, QImageCapture::Error, const QString &>::of(&QImageCapture::errorOccurred),
                this, &ErollThread::captureError);
    }
    m_stopCapture = true;
    if (!m_camera.isNull()) {
        m_camera->stop();
    }
    m_camera.reset();
    while (!m_checkDone) {
        qDebug() << "wait check done thread:" << QThread::currentThreadId();
        QThread::msleep(100);
        continue;
    }
    qDebug() << "check done";
    close(m_fileSocket);
}

修复 VerifyThread::Stop() 空指针崩溃:

void VerifyThread::Stop()
{
    qDebug() << "VerifyThread::Stop thread:" << QThread::currentThreadId();

    // 当关闭相机后, 会取消图片的抓取, 此时不需要去处理抓取的图片
    if (!m_imageCapture.isNull()) {
        disconnect(m_imageCapture.data(), &QImageCapture::imageCaptured, this, &VerifyThread::processCapturedImage);
    }
    if (!m_camera.isNull()) {
        m_camera->stop();
    }
    for (int i = 0; i < m_charaDatas.size(); i++) {
        if (m_charaDatas[i] != nullptr) {
            free(m_charaDatas[i]);
        }
    }
    m_camera.reset();
    m_charaDatas.clear();
}

修复 VerifyThread 枚举值使用:

// VerifyThread::run() 中
// 修改前: Q_EMIT processStatus(m_actionId, FaceEnrollException);
// 修改后:
Q_EMIT processStatus(m_actionId, FaceVerifyException);

// VerifyThread::captureError() 中
// 修改前: Q_EMIT processStatus(m_actionId, FaceEnrollException);
// 修改后:
Q_EMIT processStatus(m_actionId, FaceVerifyException);

审查结论

本次 Revert PR 的目的是撤销 PR #59 中添加的摄像头隐私开关检测功能,恢复到原始实现。Revert 操作本身目的明确,代码变更与目的一致。但恢复后的代码重新引入了原始版本中存在的两个严重空指针解引用缺陷(ErollThread::Stop() 和 VerifyThread::Stop()),当摄像头设备不可用时会导致程序崩溃。建议在 Revert 的同时修复这些已知缺陷,添加空指针防护。


本报告由 AI 代码审查系统自动生成

@Ivy233

Ivy233 commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

邮箱不对、SPDX也不对,已经交给https://github.com/linuxdeepin/deepin-face/pull/63跟进。
这个PR转draft闲置,以后不再使用github的回退功能。

@Ivy233
Ivy233 marked this pull request as draft October 16, 2026 09:31
@deepin-bot

deepin-bot Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 2.0.18
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #64

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