fix(audio): fix BluetoothAudioMode empty after bluez5 support#1136
Conversation
1. Add bluez5 device API recognition in getCardName to support PipeWire/BlueZ5 bluetooth audio devices 2. Fix refreshBluetoothOpts using friendly card name instead of pulse raw name for isBluezAudio check, causing BluetoothAudioMode to remain empty after bluetooth profile switch Log: fix BluetoothAudioMode empty caused by bluez5 card name change fix(audio): 修复 bluez5 支持后 BluetoothAudioMode 为空的问题 1. getCardName 中增加 bluez5 设备 API 的识别,支持 PipeWire/BlueZ5 蓝牙音频设备 2. 修复 refreshBluetoothOpts 中 isBluezAudio 使用友好名称而非 pulse 原始名称判断, 导致蓝牙 profile 切换后 BluetoothAudioMode 属性未被赋值 Log: 修复 bluez5 声卡名称变更导致 BluetoothAudioMode 为空 PMS: BUG-364299
Reviewer's guide (collapsed on small PRs)Reviewer's GuideUpdates Bluetooth audio handling to correctly recognize BlueZ5-based devices and ensure BluetoothAudioMode is populated by using the core PulseAudio card name for BlueZ detection and supporting the bluez5 device.api in card naming. Flow diagram for updated Bluetooth audio card handlingflowchart TD
PA_Card[pulse.Card] --> GetName[getCardName]
GetName --> CheckAPI{device.api<br/>bluez/bluez5?}
CheckAPI -->|yes and device.description not empty| UseDesc[Set name = device.description]
CheckAPI -->|no| CheckAlsa{alsa.card_name<br/>not empty?}
CheckAlsa -->|yes| UseAlsa[Set name = alsa.card_name]
CheckAlsa -->|no| UseRaw[Set name = raw card name]
subgraph BluetoothOpts[refreshBluetoothOpts]
CardWrapper[card] --> CoreName[card.core.Name]
CoreName --> IsBluez[isBluezAudio]
IsBluez -->|false| Exit[Return without<br/>BluetoothAudioMode]
IsBluez -->|true| SetMode[Set BluetoothAudioMode]
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review你好!我是CodeGeeX。我已仔细审查了你提供的Git Diff代码。这次修改主要涉及音频卡名称获取逻辑的优化以及蓝牙设备判断逻辑的调整。 以下是我对这次代码变更的详细审查意见,分为语法逻辑、代码质量、代码性能和代码安全四个方面: 1. 语法与逻辑
2. 代码质量
代码质量改进示例: // 在 card.go 顶部或相关的常量定义区域添加
const (
ApiBluez = "bluez"
ApiBluez5 = "bluez5"
)
// 修改 getCardName 函数中的判断逻辑
func getCardName(card *pulse.Card) (name string) {
propAlsaCardName := card.PropList["alsa.card_name"]
propDeviceApi := card.PropList["device.api"]
propDeviceDesc := card.PropList["device.description"]
// 使用常量替换魔法字符串,提高可读性
if (propDeviceApi == ApiBluez5 || propDeviceApi == ApiBluez) && propDeviceDesc != "" {
name = propDeviceDesc
} else if propAlsaCardName != "" {
name = propAlsaCardName
}
// ... 其他逻辑
}3. 代码性能
4. 代码安全
安全改进建议: 针对 // audio1/audio.go
func (a *Audio) refreshBluetoothOpts() {
// ... 前置逻辑
// 防御性编程:确保 card 和 card.core 都不为空
if card == nil || card.core == nil {
return
}
if !isBluezAudio(card.core.Name) {
return
}
// ... 后续逻辑
}总结这次 Diff 的修改方向是正确的,修复了 BlueZ5 协议设备名称获取不准确的问题,并统一了名称获取的入口。主要的改进点在于增加防御性编程以防空指针崩溃,以及消除魔法字符串提升代码可维护性。建议采纳上述安全和质量方面的改进意见后合入主分支。 |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider extracting the BlueZ/BlueZ5 device.api check into a small helper (e.g.,
isBluezApi(propDeviceApi string)) so that future BlueZ variants or related APIs can be handled in a single place and reused if needed. - When switching
refreshBluetoothOptsto usecard.core.Name, ensurecard.coreis always non-nil in all code paths or add a defensive nil check to avoid potential panics if a card is partially initialized.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider extracting the BlueZ/BlueZ5 device.api check into a small helper (e.g., `isBluezApi(propDeviceApi string)`) so that future BlueZ variants or related APIs can be handled in a single place and reused if needed.
- When switching `refreshBluetoothOpts` to use `card.core.Name`, ensure `card.core` is always non-nil in all code paths or add a defensive nil check to avoid potential panics if a card is partially initialized.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: fly602, mhduiy The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Log: fix BluetoothAudioMode empty caused by bluez5 card name change
fix(audio): 修复 bluez5 支持后 BluetoothAudioMode 为空的问题
Log: 修复 bluez5 声卡名称变更导致 BluetoothAudioMode 为空
PMS: BUG-364299
Summary by Sourcery
Fix Bluetooth audio mode handling for BlueZ5/PipeWire devices by correctly identifying BlueZ5 cards and using the raw card name for BlueZ detection.
Bug Fixes: