Skip to content

Conversation

@add-uos
Copy link
Contributor

@add-uos add-uos commented Nov 28, 2025

pick develop/eagle to master

Summary by Sourcery

Adjust monitor, Bluetooth, storage, and device image handling for specific hardware configurations and vendors.

New Features:

  • Support displaying monitor refresh rate separately and customize resolution/overview formatting for specific specialComType values.
  • Recognize an additional Bluetooth adapter model (SCM2625 BT 5.2 network adapter) when parsing hwinfo.
  • Ensure certain device images are always shown by default via a forced display flag.

Enhancements:

  • Refine monitor overview and base info display to hide the monitor name and adjust resolution string formatting for specific OEM configurations.
  • Change UFS disk description handling to rely on dynamically read interface version instead of a hardcoded interface value.

fix the w515 device of monitor display

pick from: linuxdeepin@d6a9c9f

Log: fix the w515 device of monitor display

Task: https://pms.uniontech.com/task-view-368603.html
fix the w525 device of monitor display

pick form: linuxdeepin@02ee8d0

Log: fix the w525 device of monitor display

Task: https://pms.uniontech.com/task-view-368603.html
fix the UFS display

Log: fix the UFS display

Bug: https://pms.uniontech.com/bug-view-276131.html
Change-Id: I41512e4466ff5b0dc4196b4c444ad5488c44a2b2
fix the camera info show incorrect

Log: fix the camera info show incorrect

Bug: https://pms.uniontech.com/bug-view-290539.html
Change-Id: Ibea8fb2ff9150674c7257fdc6ab9ca1159d77ff2
fix the bluetooth of false identification

pick from: linuxdeepin@366a729

Log: fix the bluetooth of false identification

Task: https://pms.uniontech.com/task-view-360593.html
Change-Id: I56de4352eed27414aba935daa97cd72ef76dd309
fix the device of monitor display

pick from: linuxdeepin@02f7a69

Log: fix the device of monitor display

Bug: https://pms.uniontech.com/bug-view-296425.html
https: //pms.uniontech.com/bug-view-296689.html
Change-Id: Ief79bbd158fef4f7a2b9332ec87e82246cd55a87
@sourcery-ai
Copy link

sourcery-ai bot commented Nov 28, 2025

Reviewer's Guide

Adds monitor refresh-rate handling and special OEM-type behaviors, extends Bluetooth device detection, adjusts UFS disk metadata generation, and ensures device images are forcibly displayable.

Class diagram for updated device model classes

classDiagram

class DeviceMonitor {
    QString m_Name
    QString m_ScreenSize
    QString m_CurrentResolution
    QString m_RefreshRate
    QString getOverviewInfo()
    void loadBaseDeviceInfo()
    void loadOtherDeviceInfo()
    bool setMainInfoFromXrandr(QString info, QString rate)
}

class DeviceGenerator {
    void getBlueToothInfoFromHwinfo()
}

class HWGenerator {
    void generatorDiskDevice()
}

class DeviceImage {
    bool m_CanEnable
    bool m_CanUninstall
    bool m_forcedDisplay
    DeviceImage()
}
Loading

Flow diagram for monitor resolution and refresh-rate handling

flowchart TD
    A[setMainInfoFromXrandr called with info, rate] --> B[Parse current rate with regular expression]
    B --> C{Rate match found and boardVendorType not empty?}
    C -- No --> H[Set m_CurrentResolution without rate]
    C -- Yes --> D{Common.specialComType == 1?}
    D -- Yes --> E[Round rate integer part and append .00 plus suffix]
    D -- No --> F[Round rate integer part and append suffix]
    E --> G[Set curRate]
    F --> G[Set curRate]
    G --> I{Common.specialComType is 1 or 6?}
    I -- Yes --> J[Set m_RefreshRate from curRate]
    I -- No --> K[Do not change m_RefreshRate]
    J --> L
    K --> L
    L{Common.specialComType is 5 or 6?} -- Yes --> M[Set m_CurrentResolution to screen size only]
    L -- No --> N[Set m_CurrentResolution to screen size and curRate with space before @]
    H --> O[Return from function]
    M --> O[Return from function]
    N --> O[Return from function]
Loading

File-Level Changes

Change Details Files
Add per-OEM handling for monitor overview text and resolution/refresh-rate parsing and formatting.
  • Initialize a new m_RefreshRate member in DeviceMonitor to track monitor refresh rate independently of resolution.
  • Change getOverviewInfo to omit monitor name from the overview string when specialComType is 6 while preserving existing behavior otherwise.
  • Skip adding the Name base device info for monitors when specialComType is 6.
  • When specialComType is 4, parse the refresh rate out of m_CurrentResolution after the '@' separator and store it in m_RefreshRate.
  • In setMainInfoFromXrandr, for specialComType 1 format the rounded refresh rate with an explicit .00 decimal suffix, store the resulting rate in m_RefreshRate for specialComType 1 and 6, and change m_CurrentResolution formatting to " @" while omitting the rate entirely for specialComType 5 and 6.
deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp
Broaden Bluetooth adapter detection from hwinfo to include an additional known device ID.
  • Treat devices with "SCM2625 BT 5.2 network adapter" in the Device field as Bluetooth when parsing hwinfo, alongside existing matching criteria like model, hardware class, driver, and BCM20702A0 ID.
deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp
Adjust disk device metadata so UFS interface version is derived dynamically instead of hard-coded.
  • Remove the hard-coded Interface field value "UFS 3.1" for UFS devices so that the interface version can be read from the underlying system instead of being fixed.
  • Retain the Description as "Universal Flash Storage" per HW requirements.
deepin-devicemanager/src/GenerateDevice/HWGenerator.cpp
Ensure device images are forcibly displayable by default.
  • Initialize the DeviceImage m_forcedDisplay flag to true in the constructor, so newly created device images are marked as forced-displayable by default.
deepin-devicemanager/src/DeviceManager/DeviceImage.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

@deepin-ci-robot
Copy link

deepin pr auto review

我来对这段代码进行审查:

  1. DeviceImage.cpp:
  • 新增了 m_forcedDisplay 成员变量初始化为 true
  • 建议:需要添加对应的成员变量声明和注释说明其用途
  1. DeviceMonitor.cpp:
  • 新增了 m_RefreshRate 成员变量初始化
  • getOverviewInfo() 函数中添加了特殊类型判断逻辑
  • loadBaseDeviceInfo() 中添加了条件判断
  • loadOtherDeviceInfo() 中添加了刷新率解析逻辑
  • setMainInfoFromXrandr() 中修改了分辨率格式和刷新率处理

问题与建议:

  1. 代码中多处使用 Common::specialComType 进行条件判断,建议:

    • 将这些特殊类型的值定义为枚举常量,提高代码可读性
    • 考虑使用策略模式或工厂模式来处理不同类型的特殊逻辑
  2. 刷新率处理逻辑:

    if (m_CurrentResolution.contains("@")) {
        QStringList refreshList = m_CurrentResolution.split('@', QT_SKIP_EMPTY_PARTS);
        if (refreshList.size() == 2) {
            m_RefreshRate = refreshList.at(1).trimmed();
        }
    }

    建议添加错误处理,当解析失败时设置默认值

  3. 分辨率格式化:

    m_CurrentResolution = QString("%1 @%2").arg(QT_REGEXP_CAPTURE(reScreenSize, 1, info)).arg(curRate);

    建议将格式化字符串定义为常量,便于统一修改

  4. DeviceGenerator.cpp:

  • 添加了对新的蓝牙设备的支持
  • 建议:将设备ID列表定义为常量数组,便于维护
  1. HWGenerator.cpp:
  • 移除了硬编码的 "UFS 3.1" 接口信息
  • 建议:从设备信息中动态获取接口版本,而不是硬编码

总体建议:

  1. 增加错误处理和日志记录
  2. 将魔法数字和字符串提取为常量
  3. 考虑使用配置文件来管理特殊类型的处理逻辑
  4. 添加单元测试来验证新功能
  5. 考虑代码重构,减少条件判断的嵌套层级
  6. 添加更详细的注释说明特殊处理的原因

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • In DeviceMonitor::getOverviewInfo, ov is assigned twice with effectively the same pattern; consider computing it once with a single conditional expression to avoid redundant formatting and make the intent clearer.
  • The parsing of m_CurrentResolution to extract m_RefreshRate in loadOtherDeviceInfo adds a second place where resolution strings are interpreted (in addition to setMainInfoFromXrandr); consider centralizing this parsing logic to a helper to keep the format assumptions consistent.
  • The Bluetooth device detection condition now hardcodes a full device name string ("SCM2625 BT 5.2 network adapter"); if this is expected to vary slightly across systems, consider using a case-insensitive contains check or a more general pattern to make the match more robust.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `DeviceMonitor::getOverviewInfo`, `ov` is assigned twice with effectively the same pattern; consider computing it once with a single conditional expression to avoid redundant formatting and make the intent clearer.
- The parsing of `m_CurrentResolution` to extract `m_RefreshRate` in `loadOtherDeviceInfo` adds a second place where resolution strings are interpreted (in addition to `setMainInfoFromXrandr`); consider centralizing this parsing logic to a helper to keep the format assumptions consistent.
- The Bluetooth device detection condition now hardcodes a full device name string (`"SCM2625 BT 5.2 network adapter"`); if this is expected to vary slightly across systems, consider using a case-insensitive `contains` check or a more general pattern to make the match more robust.

## Individual Comments

### Comment 1
<location> `deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp:450-451` </location>
<code_context>
+                    curRate = QString::number(ceil(curRate.left(pos).toDouble())) + curRate.right(curRate.size() - pos);
+                }
+            }
+            if (Common::specialComType == 1 || Common::specialComType == 6) {
+                m_RefreshRate = QString("%1").arg(curRate);
             }
-            if (Common::specialComType == 5) {
</code_context>

<issue_to_address>
**issue (bug_risk):** m_RefreshRate may retain stale values when no rate is detected

`m_RefreshRate` is only updated when `reRate.indexIn(rate)` matches and the `specialComType` condition holds. When no rate is found (or the condition fails), it retains the previous value, which may be wrong for the current monitor. Please clear or reset `m_RefreshRate` when no valid rate is detected so consumers can distinguish “no rate” from a stale value.
</issue_to_address>

### Comment 2
<location> `deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp:342` </location>
<code_context>
     QString ov;

     ov = QString("%1(%2)").arg(m_Name).arg(m_ScreenSize);
+    if (Common::specialComType == 6) {
+        ov = QString("(%1)").arg(m_ScreenSize);
</code_context>

<issue_to_address>
**issue (complexity):** Consider refactoring the new monitor-handling logic to remove redundant assignments, replace magic specialComType numbers with named enums, and centralize resolution/refresh-rate formatting into small helpers.

You can keep all the new behavior but significantly reduce complexity and duplication with a few small refactors.

### 1. Simplify `getOverviewInfo`

The current logic reassigns `ov` unnecessarily and repeats the same format string:

```cpp
QString ov;

ov = QString("%1(%2)").arg(m_Name).arg(m_ScreenSize);
if (Common::specialComType == 6) {
    ov = QString("(%1)").arg(m_ScreenSize);
} else {
    ov = QString("%1(%2)").arg(m_Name).arg(m_ScreenSize);
}
```

You can remove the redundant assignment and use a conditional expression (or a tiny helper) instead:

```cpp
const QString DeviceMonitor::getOverviewInfo()
{
    qCDebug(appLog) << "Getting monitor overview information";

    const QString ov = (Common::specialComType == 6)
        ? QString("(%1)").arg(m_ScreenSize)
        : QString("%1(%2)").arg(m_Name).arg(m_ScreenSize);

    qCDebug(appLog) << "Monitor overview:" << ov;
    return ov;
}
```

### 2. Replace magic `specialComType` numbers with named values

You already have several magic numbers (1, 4, 5, 6). You can centralize their meaning without changing behavior by introducing an enum (or `enum class`) and using it where you branch:

```cpp
namespace Common {
    enum SpecialComType {
        Normal              = 0,
        RateWithDecimals    = 1, // was 1
        ParseResolutionRate = 4, // was 4
        NoRateInResolution  = 5, // was 5
        NameLessOverview    = 6  // was 6
    };
}
```

Then update conditions locally for clarity:

```cpp
if (Common::specialComType == Common::NameLessOverview) { ... }
if (Common::specialComType == Common::ParseResolutionRate) { ... }
// etc.
```

This keeps all branching exactly as-is but makes the intent much clearer and reduces cognitive load.

### 3. Localize resolution/refresh-rate formatting

Right now, resolution and refresh rate formatting is scattered:

- `setMainInfoFromXrandr`:
  - `specialComType == 1`: tweak `curRate` string with a `".00"` inserted.
  - `specialComType == 1 || 6`: set `m_RefreshRate`.
  - `specialComType == 5 || 6`: set `m_CurrentResolution` without `@`.
  - Else: `"Size @Rate"` format with a space.
- `loadOtherDeviceInfo`:
  - `specialComType == 4`: parse `m_CurrentResolution` to extract refresh rate.

You can centralize this into compact helpers that preserve behavior but remove duplication and condition scattering.

#### 3.1 Extract a `formatCurRate` helper

This removes the duplicated `curRate` expression with/without `".00"`:

```cpp
static QString formatCurRate(const QString &rawRate, int specialComType)
{
    QRegularExpression rateStart("[a-zA-Z]");
    QRegularExpressionMatch rateMatch = rateStart.match(rawRate);
    int pos = rateMatch.capturedStart();

    if (pos <= 0 || rawRate.size() <= pos || Common::boardVendorType().isEmpty())
        return rawRate;

    const QString base = QString::number(ceil(rawRate.left(pos).toDouble()));
    const QString suffix = rawRate.right(rawRate.size() - pos);

    if (specialComType == Common::RateWithDecimals) { // was 1
        return base + ".00" + suffix;
    }
    return base + suffix;
}
```

Use it in `setMainInfoFromXrandr`:

```cpp
QString curRate = formatCurRate(rate, Common::specialComType);

if (Common::specialComType == Common::RateWithDecimals ||
    Common::specialComType == Common::NameLessOverview) {
    m_RefreshRate = curRate;
}

if (Common::specialComType == Common::NoRateInResolution ||
    Common::specialComType == Common::NameLessOverview) {
    m_CurrentResolution = QT_REGEXP_CAPTURE(reScreenSize, 1, info);
} else {
    m_CurrentResolution = QString("%1 @%2")
        .arg(QT_REGEXP_CAPTURE(reScreenSize, 1, info))
        .arg(curRate);
}
```

Behavior is unchanged; logic is easier to follow and the `curRate` formatting is in one place.

#### 3.2 Extract refresh-rate parsing from `m_CurrentResolution`

The parsing for `specialComType == 4` can also be centralized to avoid repeating rules elsewhere:

```cpp
static QString extractRefreshRateFromResolution(const QString &resolution)
{
    if (!resolution.contains('@'))
        return {};

    const QStringList parts = resolution.split('@', QT_SKIP_EMPTY_PARTS);
    if (parts.size() != 2)
        return {};

    return parts.at(1).trimmed();
}
```

Then `loadOtherDeviceInfo` becomes:

```cpp
if (m_CurrentResolution != "@Hz") {
    addOtherDeviceInfo("Current Resolution", m_CurrentResolution);
    addOtherDeviceInfo("Display Ratio", m_AspectRatio);

    if (Common::specialComType == Common::ParseResolutionRate) {
        m_RefreshRate = extractRefreshRateFromResolution(m_CurrentResolution);
    }
}
```

This centralizes the `@` parsing logic; if other `specialComType` values later need similar parsing, it’s now reusable.

---

All of the above keeps your feature behavior intact, but:

- eliminates redundant assignments and duplicate string formatting,
- replaces magic numbers with named constants,
- and localizes resolution/refresh-rate formatting and parsing into small, focused helpers.
</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.

Comment on lines +450 to +451
m_RefreshRate = QString("%1").arg(curRate);
}
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): m_RefreshRate may retain stale values when no rate is detected

m_RefreshRate is only updated when reRate.indexIn(rate) matches and the specialComType condition holds. When no rate is found (or the condition fails), it retains the previous value, which may be wrong for the current monitor. Please clear or reset m_RefreshRate when no valid rate is detected so consumers can distinguish “no rate” from a stale value.

QString ov;

ov = QString("%1(%2)").arg(m_Name).arg(m_ScreenSize);
if (Common::specialComType == 6) {
Copy link

Choose a reason for hiding this comment

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

issue (complexity): Consider refactoring the new monitor-handling logic to remove redundant assignments, replace magic specialComType numbers with named enums, and centralize resolution/refresh-rate formatting into small helpers.

You can keep all the new behavior but significantly reduce complexity and duplication with a few small refactors.

1. Simplify getOverviewInfo

The current logic reassigns ov unnecessarily and repeats the same format string:

QString ov;

ov = QString("%1(%2)").arg(m_Name).arg(m_ScreenSize);
if (Common::specialComType == 6) {
    ov = QString("(%1)").arg(m_ScreenSize);
} else {
    ov = QString("%1(%2)").arg(m_Name).arg(m_ScreenSize);
}

You can remove the redundant assignment and use a conditional expression (or a tiny helper) instead:

const QString DeviceMonitor::getOverviewInfo()
{
    qCDebug(appLog) << "Getting monitor overview information";

    const QString ov = (Common::specialComType == 6)
        ? QString("(%1)").arg(m_ScreenSize)
        : QString("%1(%2)").arg(m_Name).arg(m_ScreenSize);

    qCDebug(appLog) << "Monitor overview:" << ov;
    return ov;
}

2. Replace magic specialComType numbers with named values

You already have several magic numbers (1, 4, 5, 6). You can centralize their meaning without changing behavior by introducing an enum (or enum class) and using it where you branch:

namespace Common {
    enum SpecialComType {
        Normal              = 0,
        RateWithDecimals    = 1, // was 1
        ParseResolutionRate = 4, // was 4
        NoRateInResolution  = 5, // was 5
        NameLessOverview    = 6  // was 6
    };
}

Then update conditions locally for clarity:

if (Common::specialComType == Common::NameLessOverview) { ... }
if (Common::specialComType == Common::ParseResolutionRate) { ... }
// etc.

This keeps all branching exactly as-is but makes the intent much clearer and reduces cognitive load.

3. Localize resolution/refresh-rate formatting

Right now, resolution and refresh rate formatting is scattered:

  • setMainInfoFromXrandr:
    • specialComType == 1: tweak curRate string with a ".00" inserted.
    • specialComType == 1 || 6: set m_RefreshRate.
    • specialComType == 5 || 6: set m_CurrentResolution without @.
    • Else: "Size @Rate" format with a space.
  • loadOtherDeviceInfo:
    • specialComType == 4: parse m_CurrentResolution to extract refresh rate.

You can centralize this into compact helpers that preserve behavior but remove duplication and condition scattering.

3.1 Extract a formatCurRate helper

This removes the duplicated curRate expression with/without ".00":

static QString formatCurRate(const QString &rawRate, int specialComType)
{
    QRegularExpression rateStart("[a-zA-Z]");
    QRegularExpressionMatch rateMatch = rateStart.match(rawRate);
    int pos = rateMatch.capturedStart();

    if (pos <= 0 || rawRate.size() <= pos || Common::boardVendorType().isEmpty())
        return rawRate;

    const QString base = QString::number(ceil(rawRate.left(pos).toDouble()));
    const QString suffix = rawRate.right(rawRate.size() - pos);

    if (specialComType == Common::RateWithDecimals) { // was 1
        return base + ".00" + suffix;
    }
    return base + suffix;
}

Use it in setMainInfoFromXrandr:

QString curRate = formatCurRate(rate, Common::specialComType);

if (Common::specialComType == Common::RateWithDecimals ||
    Common::specialComType == Common::NameLessOverview) {
    m_RefreshRate = curRate;
}

if (Common::specialComType == Common::NoRateInResolution ||
    Common::specialComType == Common::NameLessOverview) {
    m_CurrentResolution = QT_REGEXP_CAPTURE(reScreenSize, 1, info);
} else {
    m_CurrentResolution = QString("%1 @%2")
        .arg(QT_REGEXP_CAPTURE(reScreenSize, 1, info))
        .arg(curRate);
}

Behavior is unchanged; logic is easier to follow and the curRate formatting is in one place.

3.2 Extract refresh-rate parsing from m_CurrentResolution

The parsing for specialComType == 4 can also be centralized to avoid repeating rules elsewhere:

static QString extractRefreshRateFromResolution(const QString &resolution)
{
    if (!resolution.contains('@'))
        return {};

    const QStringList parts = resolution.split('@', QT_SKIP_EMPTY_PARTS);
    if (parts.size() != 2)
        return {};

    return parts.at(1).trimmed();
}

Then loadOtherDeviceInfo becomes:

if (m_CurrentResolution != "@Hz") {
    addOtherDeviceInfo("Current Resolution", m_CurrentResolution);
    addOtherDeviceInfo("Display Ratio", m_AspectRatio);

    if (Common::specialComType == Common::ParseResolutionRate) {
        m_RefreshRate = extractRefreshRateFromResolution(m_CurrentResolution);
    }
}

This centralizes the @ parsing logic; if other specialComType values later need similar parsing, it’s now reusable.


All of the above keeps your feature behavior intact, but:

  • eliminates redundant assignments and duplicate string formatting,
  • replaces magic numbers with named constants,
  • and localizes resolution/refresh-rate formatting and parsing into small, focused helpers.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos, lzwind

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

@add-uos
Copy link
Contributor Author

add-uos commented Nov 28, 2025

/merge

@deepin-bot deepin-bot bot merged commit 205d1d9 into linuxdeepin:master Nov 28, 2025
18 checks passed
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.

3 participants