除了使用HIDL来区分蓝牙的公共stack和vendor lib,Oreo对蓝牙A2DP的支持也更加全面。除了A2DP profile强制支持的SBC,Oreo新增了对AAC、APTX、LDAC的编码定义。具体是否支持,还得看实现。这里简单说明Oreo是如何做到支持多种编码,并选择合适的编码方式的。
Java world的声明
codec的支持是A2DP profile的声明的。在Bluetooth.apk中,编码的支持包含在A2dpStateMachine当中。它在自己的构造函数中对编码的支持进行了初始化:
private A2dpStateMachine(A2dpService svc, Context context) {
//......
mCodecConfigPriorities = assignCodecConfigPriorities();
initNative(mCodecConfigPriorities);
//......
}
assignCodecConfigPriorities的作用是,首先加载各个codec的priority,再将每个支持的codec参数初始化。codec的priority保存在配置文件values/config.xml中。就目前的设置来看,它支持五种编码:
<!-- Configuring priorities of A2DP source codecs. Larger value means
higher priority. Value -1 means the codec is disabled.
Value 0 is reserved and should not be used here. Enabled codecs
should have priorities in the interval [1, 999999], and each priority
value should be unique. -->
<integer name="a2dp_source_codec_priority_sbc">1001</integer>
<integer name="