Skip to content

Fix: [Audio] The audio device of usb not show.#524

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:develop/eaglefrom
GongHeng2017:202508271643-eagle-fixUsbAudio
Aug 27, 2025
Merged

Fix: [Audio] The audio device of usb not show.#524
deepin-bot[bot] merged 1 commit intolinuxdeepin:develop/eaglefrom
GongHeng2017:202508271643-eagle-fixUsbAudio

Conversation

@GongHeng2017
Copy link
Contributor

@GongHeng2017 GongHeng2017 commented Aug 27, 2025

-- Add logic code to append usb audio.

Log: fix issue
Bug: https://pms.uniontech.com/bug-view-331293.html

Summary by Sourcery

Bug Fixes:

  • Add check for snd-usb-audio in the Driver field to ensure USB sound cards are recognized and displayed.

@sourcery-ai
Copy link

sourcery-ai bot commented Aug 27, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Enriches the USB audio detection in getMulHwinfoInfo by adding a driver-based check, ensuring previously unrecognized USB sound cards are captured.

File-Level Changes

Change Details Files
Extended USB audio detection logic
  • Added an OR condition checking if mapInfo["Driver"] contains "snd-usb-audio"
  • Retained existing checks on "Hardware Class" and "Device" fields
deepin-devicemanager/src/GenerateDevice/CmdTool.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. 代码质量方面:
  • 当前代码中的条件判断逻辑较为复杂,建议提取为单独的函数以提高可读性
  • 字符串比较使用了魔法字符串("sound", "USB Audio", "snd-usb-audio"),建议定义为常量
  • 条件判断中的逻辑可以进一步优化,避免重复的字符串contains调用
  1. 代码性能方面:
  • 多次调用mapInfo["Device"].contains()和mapInfo["Driver"].contains()可能影响性能,建议先缓存结果
  • 可以考虑使用字符串哈希值代替直接字符串比较,提高比较效率
  1. 代码安全方面:
  • 直接使用mapInfo["Hardware Class"]这样的键访问可能存在键不存在导致的问题,应该先检查键是否存在
  • 建议添加对字符串内容的合法性检查,防止潜在的注入攻击

改进建议代码:

namespace {
    const QString HARDWARE_CLASS_SOUND = "sound";
    const QString DEVICE_USB_AUDIO = "USB Audio";
    const QString DRIVER_SND_USB_AUDIO = "snd-usb-audio";
    const QString HARDWARE_CLASS_NETWORK = "network";
    const QString DEVICE_WIFI = "WI-FI";
}

// 提取判断逻辑为单独函数
bool isSoundDevice(const QMap<QString, QString>& mapInfo) {
    if (!mapInfo.contains("Hardware Class") || !mapInfo.contains("Device") || !mapInfo.contains("Driver")) {
        return false;
    }
    
    const QString& hardwareClass = mapInfo["Hardware Class"];
    const QString& device = mapInfo["Device"];
    const QString& driver = mapInfo["Driver"];
    
    return hardwareClass == HARDWARE_CLASS_SOUND
        || (device.contains(DEVICE_USB_AUDIO) && device.contains(DRIVER_SND_USB_AUDIO))
        || driver.contains(DRIVER_SND_USB_AUDIO);
}

bool isNetworkDevice(const QMap<QString, QString>& mapInfo) {
    if (!mapInfo.contains("Hardware Class") || !mapInfo.contains("Device")) {
        return false;
    }
    
    const QString& hardwareClass = mapInfo["Hardware Class"];
    const QString& device = mapInfo["Device"];
    
    return hardwareClass.contains(HARDWARE_CLASS_NETWORK) 
        || device.toUpper().contains(DEVICE_WIFI);
}

void CmdTool::getMulHwinfoInfo(const QString &info) {
    // ... 其他代码 ...
    
    for (const QString &item : list) {
        if (item.isEmpty()) {
            continue;
        }
        
        QMap<QString, QString> mapInfo;
        getMapInfoFromHwinfo(item, mapInfo);
        
        if (isSoundDevice(mapInfo)) {
            addMapInfo("hwinfo_sound", mapInfo);
        } else if (isNetworkDevice(mapInfo)) {
            // ... 其他代码 ...
        }
    }
}

主要改进点:

  1. 将魔法字符串提取为命名空间常量
  2. 将复杂的条件判断逻辑拆分为独立的函数
  3. 增加了键存在性检查,提高安全性
  4. 缓存了字符串引用,避免重复查找
  5. 提高了代码的可读性和可维护性

这些改进使得代码更加健壮、安全,同时也提高了可读性和可维护性。

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 and they look great!


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.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos, GongHeng2017, max-lvs

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

@GongHeng2017
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Aug 27, 2025

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit 76729e9 into linuxdeepin:develop/eagle Aug 27, 2025
15 of 17 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.

4 participants