Android: expose the device's own type (`AudioDeviceInfo.getType()`) in `DeviceDescription`

未关闭
#1,423 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
48/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
android, rust

调研方向

Start by reading the Android AAudio host code that builds DeviceDescription and the existing java_interface::AudioDeviceType definition; the issue names both but gives no file paths. Check how DeviceDescription and DeviceDescriptionBuilder are exposed through cpal::platform, then compare the implementation with the proposal. Done means Android callers can retrieve the original device type and existing behavior on other platforms remains unchanged.

由索引模型根据 Issue 内容生成。

描述

extension host - aaudio platform - android

Android: expose the device's own type (AudioDeviceInfo.getType()) in DeviceDescription

cpal 0.18.2, AAudio host.

The problem

On Android, DeviceDescription::device_type() and interface_type() are
derived from AudioDeviceInfo.getType(), but several of Android's types map
to the same pair, so an app can't tell them apart:

  • TYPE_BUILTIN_SPEAKER and TYPE_BUILTIN_SPEAKER_SAFE (the speaker's route
    for alarms and notifications): both "Speaker", built in. Both are listed,
    both named "Speaker" on a Pixel.
  • TYPE_BLUETOOTH_SCO (a headset's link for calls) and TYPE_BLE_HEADSET:
    both "Headset", Bluetooth.
  • TYPE_TELEPHONY falls into Unknown with many others, so devices meant
    for calls (which an app playing music wants to mark or leave out) can't
    all be recognised: the earpiece can, the call link (SCO) and telephony
    can't.

The device id doesn't help either: Android gives a Bluetooth device a new id
each time it connects (we saw 28087, then 28061 for the same headphones), so
an app that remembers the user's chosen output needs something stable to
recognise it by. Android's type, the name and the visible part of the address
do that, but the type is lost in the mapping.

Proposal

An Android-only getter beside the existing ones, giving the type as Android
reports it, and the type exported from cpal::platform:

#[cfg(target_os = "android")]
impl DeviceDescription {
    /// Android's own type of the device (`AudioDeviceInfo.getType()`), which
    /// `device_type()` and `interface_type()` merge.
    pub fn android_type(&self) -> Option<cpal::platform::AndroidDeviceType>;
}

AndroidDeviceType is the existing java_interface::AudioDeviceType, made
public (plus PartialEq, Eq, Hash), and DeviceDescriptionBuilder gets
an android_type(..) method that the AAudio host calls with
info.device_type. Nothing changes on other platforms or for existing
callers.

The attached patch (against 0.18.2, about 120 lines) does this; we use it
in our app through [patch.crates-io]. Happy to open a pull request against
master if the shape is acceptable (a field on DeviceDescription, or would
you rather have a platform extension trait?).

主要语言
Rust
星标
4k
派生
554
平均合并
1 天 3 小时
30 天内合并 PR
1

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

RustAudio/cpal 的其他 Issue

查看 RustAudio/cpal 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。