Skip to content

Revert "Fix: [Audio] The audio device of usb not show."#526

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

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

Conversation

@GongHeng2017
Copy link
Contributor

@GongHeng2017 GongHeng2017 commented Aug 28, 2025

Reverts #524

Summary by Sourcery

Bug Fixes:

  • Remove driver.contains("snd-usb-audio") condition from USB audio device detection

@deepin-ci-robot
Copy link

deepin pr auto review

这段代码是一个条件判断,用于识别和处理声音设备相关的信息。我来分析一下这段代码的改进建议:

  1. 语法逻辑方面:
  • 原代码中移除了 || mapInfo["Driver"].contains("snd-usb-audio") 的判断条件,这可能是一个问题,因为这个条件对于识别某些USB音频设备是必要的。如果完全移除这个条件可能会导致某些USB音频设备无法被正确识别。
  1. 代码质量方面:
  • 条件判断比较复杂,包含了多个嵌套的字符串比较,建议提取为单独的函数或使用常量来提高可读性。
  • 字符串比较使用了硬编码的字符串,如"sound"、"network"、"WI-FI"等,建议定义为常量或枚举类型,便于维护。
  1. 代码性能方面:
  • 多次调用 mapInfo["Hardware Class"]mapInfo["Device"],可以考虑先存储到局部变量中,避免重复的哈希查找操作。
  1. 代码安全方面:
  • 直接使用字符串作为键访问 QMap 可能会导致键不存在时的隐式插入,建议使用 constFind 或先检查键是否存在。

改进建议如下:

// 建议在类中定义常量
static const QString SOUND_CLASS = "sound";
static const QString USB_AUDIO_DEVICE = "USB Audio";
static const QString SND_USB_AUDIO = "snd-usb-audio";
static const QString NETWORK_CLASS = "network";
static const QString WI_FI_DEVICE = "WI-FI";

void CmdTool::getMulHwinfoInfo(const QString &info)
{
    // ... 其他代码 ...

    for (const QString &item : list) {
        if (item.isEmpty()) {
            continue;
        }

        QMap<QString, QString> mapInfo;
        getMapInfoFromHwinfo(item, mapInfo);
        
        // 先获取值并存储,避免重复查找
        const QString hardwareClass = mapInfo.value("Hardware Class");
        const QString device = mapInfo.value("Device");
        const QString driver = mapInfo.value("Driver");
        
        bool isSoundDevice = (hardwareClass == SOUND_CLASS) || 
                            (device.contains(USB_AUDIO_DEVICE) && device.contains(SND_USB_AUDIO)) ||
                            (driver.contains(SND_USB_AUDIO));
                            
        if (isSoundDevice) {
            // mapInfo["Device"].contains("USB Audio") 是为了处理未识别的USB声卡 Bug-118773
            addMapInfo("hwinfo_sound", mapInfo);
        } else if (hardwareClass.contains(NETWORK_CLASS) || device.toUpper().contains(WI_FI_DEVICE)) {
            // ... 其他代码 ...
        }
    }
}

这样的改进可以提高代码的可读性、可维护性和性能,同时确保逻辑的完整性。特别是恢复了对驱动名称的检查,这对于正确识别USB音频设备很重要。

@sourcery-ai
Copy link

sourcery-ai bot commented Aug 28, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR reverts the USB audio driver-based detection fix by removing the driver check from the hardware info filtering in getMulHwinfoInfo.

Class diagram for CmdTool after reverting USB audio driver detection

classDiagram
    class CmdTool {
        +void getMulHwinfoInfo(const QString &info)
    }
    CmdTool : getMulHwinfoInfo() now only checks
    CmdTool : - mapInfo["Driver"].contains("snd-usb-audio") condition removed
    CmdTool : + mapInfo["Hardware Class"] == "sound" || (mapInfo["Device"].contains("USB Audio") && mapInfo["Device"].contains("snd-usb-audio"))
Loading

File-Level Changes

Change Details Files
Revert USB audio driver check in hardware info filtering condition
  • Removed the mapInfo["Driver"].contains("snd-usb-audio") clause from the if statement
  • Adjusted the conditional to only check 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

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: 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 28, 2025

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit e883cd1 into linuxdeepin:develop/eagle Aug 28, 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.

3 participants