首页 > 其他分享 >探究AudioPolicyManager.cpp中的成员变量mAvailableOutputDevices/InputDevices是根据什么来配置的,又有什么办法可以动态设置

探究AudioPolicyManager.cpp中的成员变量mAvailableOutputDevices/InputDevices是根据什么来配置的,又有什么办法可以动态设置

时间:2024-10-09 19:11:06浏览次数:8  
标签:2024 AudioPolicyManager 10 09 pid 3841 InputDevices mAvailableOutputDevices APM

2024-09-23 10:29:48.792   286-445   APM-AudioPolicyEngine   pid-286                              W  frameworks/av/services/audiopolicy/enginedefault/src/Engine.cpp:getDeviceForStrategyInt:278
2024-09-23 10:29:48.792   286-445   AudioFlinger            pid-286                              V  invalidateStream() stream 10

由此可以看到,好像是AudioFlinger拦截下来了

2024-09-23 11:03:05.640   301-472   AudioFlinger            [email protected]  D  #00 pc 00017911  /system/lib/libaudioflinger.so (android::AudioFlinger::invalidateStream(audio_stream_type_t)+32)
2024-09-23 11:03:05.640   301-472   AudioFlinger            [email protected]  D  #01 pc 0000e7f3  /system/lib/libaudiopolicyservice.so (android::AudioPolicyService::AudioPolicyClient::invalidateStream(audio_stream_type_t)+66)
2024-09-23 11:03:05.640   301-472   AudioFlinger            [email protected]  D  #02 pc 0002004d  /system/lib/libaudiopolicymanagerdefault.so (android::AudioPolicyManager::setPhoneState(audio_mode_t)+1424)
2024-09-23 11:03:05.640   301-472   AudioFlinger            [email protected]  D  #03 pc 0000c2d1  /system/lib/libaudiopolicyservice.so (android::AudioPolicyService::setPhoneState(audio_mode_t)+82)
2024-09-23 11:03:05.640   301-472   AudioFlinger            [email protected]  D  #04 pc 0003e7c7  /system/lib/libaudioclient.so (android::BnAudioPolicyService::onTransact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+598)
2024-09-23 11:03:05.640   301-472   AudioFlinger            [email protected]  D  #05 pc 0003613f  /system/lib/libbinder.so (android::BBinder::transact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+70)
2024-09-23 11:03:05.640   301-472   AudioFlinger            [email protected]  D  #06 pc 0003d99f  /system/lib/libbinder.so (android::IPCThreadState::executeCommand(int)+410)
2024-09-23 11:03:05.640   301-472   AudioFlinger            [email protected]  D  #07 pc 0003d72b  /system/lib/libbinder.so (android::IPCThreadState::getAndExecuteCommand()+106)
2024-09-23 11:03:05.640   301-472   AudioFlinger            [email protected]  D  #08 pc 0003dc53  /system/lib/libbinder.so (android::IPCThreadState::joinThreadPool(bool)+38)
2024-09-23 11:03:05.640   301-472   AudioFlinger            [email protected]  D  #09 pc 000546dd  /system/lib/libbinder.so (android::PoolThread::threadLoop()+12)
2024-09-23 11:03:05.640   301-472   AudioFlinger            [email protected]  D  #10 pc 0000c0c7  /system/lib/libutils.so (android::Thread::_threadLoop(void*)+166)
2024-09-23 11:03:05.640   301-472   AudioFlinger            [email protected]  D  #11 pc 000639f5  /system/lib/libc.so (__pthread_start(void*)+22)
2024-09-23 11:03:05.640   301-472   AudioFlinger            [email protected]  D  #12 pc 0001df75  /system/lib/libc.so (__start_thread+22)
2024-09-23 11:03:05.640   301-472   AudioFlinger            [email protected]  V  invalidateStream() stream 10

可以看到,拦截的地方是frameworks/av/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
AudioPolicyManager.cpp:582

搞错了,不是这里被拦截,因为Handset正常时也有这个

真正出问题的是

2024-09-23 10:29:49.628   286-286   AudioFlinger            pid-286                              E  createTrack() getOutputForAttr() return error -38 or invalid output handle
2024-09-23 10:29:49.628  1152-1523  IAudioFlinger           vdroid.server                        E  createTrack returned error -38
55:56.253   304-475   AudioFlinger            audioserver                          I  createTrack() getOutputForAttr result lStatus: -38, outputId: 0, streamType: 0

AudioSystem::getOutputForAttr()函数返回负

AudioPolicyManager.cpp:4725-4728

SortedVector<audio_io_handle_t> AudioPolicyManager::getOutputsForDevice中有这一段报错

在frameworks/av/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
里的

SortedVector<audio_io_handle_t> AudioPolicyManager::getOutputsForDevice(
                                                                audio_devices_t device,
                                                                const SwAudioOutputCollection& openOutputs)
{
    SortedVector<audio_io_handle_t> outputs;

    ALOGVV("getOutputsForDevice() device %04x", device);
    for (size_t i = 0; i < openOutputs.size(); i++) {
        ALOGVV("output %zu isDuplicated=%d device=%04x",
                i, openOutputs.valueAt(i)->isDuplicated(),
                openOutputs.valueAt(i)->supportedDevices());
        if ((device & openOutputs.valueAt(i)->supportedDevices()) == device) {
            ALOGVV("getOutputsForDevice() found output %d", openOutputs.keyAt(i));
            outputs.add(openOutputs.keyAt(i));
        }
    }
    return outputs;
}

循环里的if条件没过去一次,推断出openOutputs.valueAt(i)->supportedDevices()一直都是2208043E,LINE_OUT一直是20000

下一步,查看supportedDevices是怎么设定的

#include <utils/CallStack.h>
    CallStack stack;

    stack.update();

    stack.log(LOG_TAG); 
    LOCAL_SHARED_LIBRARIES := \
    libutils \
    libutilscallstack \

可以从这里看到当前是否在通话中。

AudioService.java:3218-3221:getMode()

    /** @see AudioManager#getMode() */
    public int getMode() {
        return mMode;
    }

查看Handset修改列表,学习仿照。

frameworks/av/services/audiopolicy/managerdefault/AudioPolicyManager.cpp中使用了
frameworks/av/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp来进行解析audio_policy_configuration.xml
现在要看是否被解析出来

frameworks/av/services/audiopolicy/enginedefault/src/Engine.cpp

audio_devices_t Engine::getDeviceForStrategy(routing_strategy strategy) const
{
    DeviceVector availableOutputDevices = mApmObserver->getAvailableOutputDevices();
    DeviceVector availableInputDevices = mApmObserver->getAvailableInputDevices();//在策略选择函数中,availableInputDevices是这么来的

    const SwAudioOutputCollection &outputs = mApmObserver->getOutputs();

    return getDeviceForStrategyInt(strategy, availableOutputDevices,
                                   availableInputDevices, outputs, (uint32_t)AUDIO_DEVICE_NONE);
}

该成员定义如下
AudioPolicyManagerObserver *mApmObserver;

改动入口仅有这一个

void Engine::setObserver(AudioPolicyManagerObserver *observer)
{
    ALOG_ASSERT(observer != NULL, "Invalid Audio Policy Manager observer");
    mApmObserver = observer;
}

在这里打印调用栈,看看情况

2024-09-26 10:26:09.675  3357-3357  APM-AudioPolicyEngine   pid-3357                             D  #00 pc 00007de9  /system/lib/libaudiopolicyenginedefault.so (android::audio_policy::Engine::setObserver(android::AudioPolicyManagerObserver*)+32)
2024-09-26 10:26:09.675  3357-3357  APM-AudioPolicyEngine   pid-3357                             D  #01 pc 00028e53  /system/lib/libaudiopolicymanagerdefault.so (android::AudioPolicyManager::initialize()+66)
2024-09-26 10:26:09.676  3357-3357  APM-AudioPolicyEngine   pid-3357                             D  #02 pc 00028cb1  /system/lib/libaudiopolicymanagerdefault.so (android::AudioPolicyManager::AudioPolicyManager(android::AudioPolicyClientInterface*)+16)
2024-09-26 10:26:09.676  3357-3357  APM-AudioPolicyEngine   pid-3357                             D  #03 pc 0000075f  /system/lib/libaudiopolicymanager.so (createAudioPolicyManager+14)
2024-09-26 10:26:09.676  3357-3357  APM-AudioPolicyEngine   pid-3357                             D  #04 pc 00006615  /system/lib/libaudiopolicyservice.so (android::AudioPolicyService::onFirstRef()+280)
2024-09-26 10:26:09.676  3357-3357  APM-AudioPolicyEngine   pid-3357                             D  #05 pc 000038b5  /system/bin/audioserver (android::BinderService<android::AudioPolicyService>::publish(bool, int)+72)
2024-09-26 10:26:09.676  3357-3357  APM-AudioPolicyEngine   pid-3357                             D  #06 pc 00003543  /system/bin/audioserver (main+494)
2024-09-26 10:26:09.676  3357-3357  APM-AudioPolicyEngine   pid-3357                             D  #07 pc 00088da5  /system/lib/libc.so (__libc_init+48)
2024-09-26 10:26:09.676  3357-3357  APM-AudioPolicyEngine   pid-3357                             D  #08 pc 00003313  /system/bin/audioserver (_start_main+46)
2024-09-26 10:26:09.676  3357-3357  APM-AudioPolicyEngine   pid-3357                             D  #09 pc 00000306  <anonymous:f73c5000>

看出是由AudioPolicyManager::initialize()这个在调用
mEngine->setObserver(this);

class AudioPolicyManager : public AudioPolicyInterface, public AudioPolicyManagerObserver
使用多态,是他自己

AudioPolicyManager其中重写了虚函数
        virtual const DeviceVector &getAvailableOutputDevices() const
        {
            return mAvailableOutputDevices;
        }

mAvailableOutputDevices类型是DeviceVector

DeviceVector类型的代码看来改变内部变量mDeviceTypes的函数是 void refreshTypes();
在add内调用。

可以看到

APM_AudioPolicyManager  pid-3026                             V  output 0 isDuplicated=0 device=220a043e 这里是有看到20000(audio_out_line)的,但要搞清楚为什么没进mAvailableOutputDevices

mAvailableOutputDevices仅仅是getDeviceForStrategy() - availableOutputDevices: 22000002
确定修改的入口是这里了,该函数是私有函数,是被共有函数add调用。
打印调用栈看看情况

2024-09-30 15:18:33.786  2698-2698  APM::Devices            pid-2698                             D  #00 pc 0002f8dd  /system/lib/libaudiopolicymanagerdefault.so (android::DeviceVector::refreshTypes()+80)
2024-09-30 15:18:33.786  2698-2698  APM::Devices            pid-2698                             D  #01 pc 0002f9cf  /system/lib/libaudiopolicymanagerdefault.so (android::DeviceVector::add(android::sp<android::DeviceDescriptor> const&)+58)
2024-09-30 15:18:33.786  2698-2698  APM::Devices            pid-2698                             D  #02 pc 0002fc1b  /system/lib/libaudiopolicymanagerdefault.so (android::DeviceVector::getDevicesFromType(unsigned int) const+122)
2024-09-30 15:18:33.786  2698-2698  APM::Devices            pid-2698                             D  #03 pc 0000867f  /system/lib/libaudiopolicyenginedefault.so (android::audio_policy::Engine::getDeviceForStrategyInt(android::routing_strategy, android::DeviceVector, android::DeviceVector, android::SwAudioOutputCollection const&, unsigned int) const+1074)
2024-09-30 15:18:33.786  2698-2698  APM::Devices            pid-2698                             D  #04 pc 000081d9  /system/lib/libaudiopolicyenginedefault.so (android::audio_policy::Engine::getDeviceForStrategy(android::routing_strategy) const+144)
2024-09-30 15:18:33.786  2698-2698  APM::Devices            pid-2698                             D  #05 pc 0002b3a3  /system/lib/libaudiopolicymanagerdefault.so (android::AudioPolicyManager::checkDeviceMuteStrategies(android::sp<android::AudioOutputDescriptor> const&, unsigned int, unsigned int)+110)
2024-09-30 15:18:33.786  2698-2698  APM::Devices            pid-2698                             D  #06 pc 0002b719  /system/lib/libaudiopolicymanagerdefault.so (android::AudioPolicyManager::setOutputDevice(android::sp<android::AudioOutputDescriptor> const&, unsigned int, bool, int, int*, char const*, bool)+380)
2024-09-30 15:18:33.786  2698-2698  APM::Devices            pid-2698                             D  #07 pc 000206f5  /system/lib/libaudiopolicymanagerdefault.so (android::AudioPolicyManager::setForceUse(audio_policy_force_use_t, audio_policy_forced_cfg_t)+448)
2024-09-30 15:18:33.786  2698-2698  APM::Devices            pid-2698                             D  #08 pc 0000c349  /system/lib/libaudiopolicyservice.so (android::AudioPolicyService::setForceUse(audio_policy_force_use_t, audio_policy_forced_cfg_t)+66)
2024-09-30 15:18:33.786  2698-2698  APM::Devices            pid-2698                             D  #09 pc 0003f97f  /system/lib/libaudioclient.so (android::BnAudioPolicyService::onTransact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+4310)
2024-09-30 15:18:33.786  2698-2698  APM::Devices            pid-2698                             D  #10 pc 0003613f  /system/lib/libbinder.so (android::BBinder::transact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+70)
2024-09-30 15:18:33.786  2698-2698  APM::Devices            pid-2698                             D  #11 pc 0003d99f  /system/lib/libbinder.so (android::IPCThreadState::executeCommand(int)+410)
2024-09-30 15:18:33.786  2698-2698  APM::Devices            pid-2698                             D  #12 pc 0003d72b  /system/lib/libbinder.so (android::IPCThreadState::getAndExecuteCommand()+106)
2024-09-30 15:18:33.786  2698-2698  APM::Devices            pid-2698                             D  #13 pc 0003dc53  /system/lib/libbinder.so (android::IPCThreadState::joinThreadPool(bool)+38)
2024-09-30 15:18:33.786  2698-2698  APM::Devices            pid-2698                             D  #14 pc 0000358d  /system/bin/audioserver (main+568)
2024-09-30 15:18:33.786  2698-2698  APM::Devices            pid-2698                             D  #15 pc 00088da5  /system/lib/libc.so (__libc_init+48)
2024-09-30 15:18:33.786  2698-2698  APM::Devices            pid-2698                             D  #16 pc 00003313  /system/bin/audioserver (_start_main+46)
2024-09-30 15:18:33.786  2698-2698  APM::Devices            pid-2698                             D  #17 pc 00000306  <anonymous:f4ca1000>
2024-09-30 15:18:33.787  2698-2698  APM::Devices            pid-2698                             V  DeviceVector::getDevicesFromType() for type 20000000 found 0xf2042140
2024-09-30 15:18:33.787  2698-2698  APM::Devices            pid-2698                             V  DeviceVector::refreshTypes() mDeviceTypes 22000002

我要看的是 DeviceVector availableInputDevices = mApmObserver->getAvailableInputDevices();在

#04 pc 000081d9  /system/lib/libaudiopolicyenginedefault.so (android::audio_policy::Engine::getDeviceForStrategy(android::routing_strategy) const+144)

中,调用了availableInputDevices=getAvailableInputDevices(),传入了getDeviceForStrategyInt。所以后面不用看了,找到一个refreshTypes的调用栈,且不进过getDeviceForStrategy

因为在setObserver之前所有的对DeviceVector的修改都在这里(通过调用栈得知)
解析和设置的逻辑都在这里,但有点杂乱

status_t ModuleTraits::deserialize(xmlDocPtr doc, const xmlNode *root, PtrElement &module,  
                                   PtrSerializingCtx ctx)  

在frameworks/av/services/audiopolicy/managerdefault/AudioPolicyManager.cpp中,
使用mAvailableOutputDevices.add只有setDeviceConnectionStateInt函数,但通过添加打印,发现,初始化阶段并没有去调用这个函数
所以使用mAvailableOutputDevices值的设定并不是在这里做的。

由于通过日志打印了解到mAvailableOutputDevices是通过默认构造的,所以排除拷贝构造。
有几种可能,其他cpp文件调用add,通过拷贝赋值。
重载了其拷贝构造和拷贝赋值函数,在内部进行正常逻辑操作,并额外添加日志输出。
通过日志打印可知,并没有通过拷贝赋值,而是通过add,通过最后mAvailableOutputDevices的地址,定位到在往mAvailableOutputDevices里add设备时的调用栈如下

2024-10-08 21:39:21.529  3196-3196  APM::Serializer         pid-3196                             W  deserialize: Set routes for module
2024-10-08 21:39:21.529  3196-3196  APM::Serializer         pid-3196                             W  deserialize: Iterating over child nodes
2024-10-08 21:39:21.529  3196-3196  APM::Serializer         pid-3196                             W  deserialize: ModuleTraits attachedDevices found
2024-10-08 21:39:21.529  3196-3196  APM::Serializer         pid-3196                             W  deserialize: ModuleTraits item=Speaker
2024-10-08 21:39:21.529  3196-3196  APM::Devices            pid-3196                             V  DeviceVector::refreshTypes() mDeviceTypes 00000002
2024-10-08 21:39:21.529  3196-3196  APM::Devices            pid-3196                             V  DeviceVector::refreshTypes() p: 0xe9b3d05c
2024-10-08 21:39:21.530  3196-3196  APM_AudioPolicyManager  pid-3196                             I  this=0xe9b3d05c, mDeviceTypes=0x2
2024-10-08 21:39:21.530  3196-3196  APM::Serializer         pid-3196                             W  deserialize: ModuleTraits item=Handset Speaker
2024-10-08 21:39:21.530  3196-3196  APM::Devices            pid-3196                             V  DeviceVector::refreshTypes() mDeviceTypes 20000002
2024-10-08 21:39:21.530  3196-3196  APM::Devices            pid-3196                             V  DeviceVector::refreshTypes() p: 0xe9b3d05c
2024-10-08 21:39:21.530  3196-3196  APM_AudioPolicyManager  pid-3196                             I  this=0xe9b3d05c, mDeviceTypes=0x20000002
2024-10-08 21:39:21.566  3196-3196  APM_AudioPolicyManager  pid-3196                             D  #00 pc 0002d20f  /system/lib/libaudiopolicymanagerdefault.so (android::DeviceVector::a(void*, unsigned int)+58)
2024-10-08 21:39:21.566  3196-3196  APM_AudioPolicyManager  pid-3196                             D  #01 pc 0002f93f  /system/lib/libaudiopolicymanagerdefault.so (android::DeviceVector::refreshTypes()+134)
2024-10-08 21:39:21.566  3196-3196  APM_AudioPolicyManager  pid-3196                             D  #02 pc 0002fa27  /system/lib/libaudiopolicymanagerdefault.so (android::DeviceVector::add(android::sp<android::DeviceDescriptor> const&)+58)
2024-10-08 21:39:21.566  3196-3196  APM_AudioPolicyManager  pid-3196                             D  #03 pc 0003b8e1  /system/lib/libaudiopolicymanagerdefault.so (android::ModuleTraits::deserialize(_xmlDoc*, _xmlNode const*, android::sp<android::HwModule>&, android::AudioPolicyConfig*)+1724)
2024-10-08 21:39:21.566  3196-3196  APM_AudioPolicyManager  pid-3196                             D  #04 pc 0003c91b  /system/lib/libaudiopolicymanagerdefault.so (android::PolicySerializer::deserialize(char const*, android::AudioPolicyConfig&)+534)
2024-10-08 21:39:21.566  3196-3196  APM_AudioPolicyManager  pid-3196                             D  #05 pc 00028f89  /system/lib/libaudiopolicymanagerdefault.so (android::AudioPolicyManager::loadConfig()+176)
2024-10-08 21:39:21.566  3196-3196  APM_AudioPolicyManager  pid-3196                             D  #06 pc 00028ecb  /system/lib/libaudiopolicymanagerdefault.so (android::AudioPolicyManager::AudioPolicyManager(android::AudioPolicyClientInterface*)+10)
2024-10-08 21:39:21.566  3196-3196  APM_AudioPolicyManager  pid-3196                             D  #07 pc 0000075f  /system/lib/libaudiopolicymanager.so (createAudioPolicyManager+14)
2024-10-08 21:39:21.566  3196-3196  APM_AudioPolicyManager  pid-3196                             D  #08 pc 00006615  /system/lib/libaudiopolicyservice.so (android::AudioPolicyService::onFirstRef()+280)
2024-10-08 21:39:21.566  3196-3196  APM_AudioPolicyManager  pid-3196                             D  #09 pc 000038b5  /system/bin/audioserver (android::BinderService<android::AudioPolicyService>::publish(bool, int)+72)
2024-10-08 21:39:21.566  3196-3196  APM_AudioPolicyManager  pid-3196                             D  #10 pc 00003543  /system/bin/audioserver (main+494)
2024-10-08 21:39:21.566  3196-3196  APM_AudioPolicyManager  pid-3196                             D  #11 pc 00088da5  /system/lib/libc.so (__libc_init+48)
2024-10-08 21:39:21.566  3196-3196  APM_AudioPolicyManager  pid-3196                             D  #12 pc 00003313  /system/bin/audioserver (_start_main+46)
2024-10-08 21:39:21.566  3196-3196  APM_AudioPolicyManager  pid-3196                             D  #13 pc 00000306  <anonymous:ec7a8000>

尝试关闭编译器优化,看到更清晰的调用栈,编译完成,待烧录

deserialize: Set routes for module
2024-10-09 10:36:28.129  3841-3841  APM::Serializer         pid-3841                             W  deserialize: Iterating over child nodes
2024-10-09 10:36:28.129  3841-3841  APM::Serializer         pid-3841                             W  deserialize: ModuleTraits attachedDevices found
2024-10-09 10:36:28.129  3841-3841  APM::Serializer         pid-3841                             W  deserialize: ModuleTraits item=Speaker
2024-10-09 10:36:28.129  3841-3841  APM::Devices            pid-3841                             V  DeviceVector::refreshTypes() mDeviceTypes 00000002
2024-10-09 10:36:28.130  3841-3841  APM::Devices            pid-3841                             V  DeviceVector::refreshTypes() p: 0xe583d05c
2024-10-09 10:36:28.130  3841-3841  APM_AudioPolicyManager  pid-3841                             I  this=0xe583d05c, mDeviceTypes=0x2
2024-10-09 10:36:28.130  3841-3841  APM::Serializer         pid-3841                             W  deserialize: ModuleTraits item=Handset Speaker
2024-10-09 10:36:28.130  3841-3841  APM::Devices            pid-3841                             V  DeviceVector::refreshTypes() mDeviceTypes 20000002
2024-10-09 10:36:28.130  3841-3841  APM::Devices            pid-3841                             V  DeviceVector::refreshTypes() p: 0xe583d05c
2024-10-09 10:36:28.130  3841-3841  APM_AudioPolicyManager  pid-3841                             I  this=0xe583d05c, mDeviceTypes=0x20000002
2024-10-09 10:36:28.166  3841-3841  APM_AudioPolicyManager  pid-3841                             D  #00 pc 0002d20f  /system/lib/libaudiopolicymanagerdefault.so (android::DeviceVector::a(void*, unsigned int)+58)
2024-10-09 10:36:28.166  3841-3841  APM_AudioPolicyManager  pid-3841                             D  #01 pc 0002f93f  /system/lib/libaudiopolicymanagerdefault.so (android::DeviceVector::refreshTypes()+134)
2024-10-09 10:36:28.166  3841-3841  APM_AudioPolicyManager  pid-3841                             D  #02 pc 0002fa27  /system/lib/libaudiopolicymanagerdefault.so (android::DeviceVector::add(android::sp<android::DeviceDescriptor> const&)+58)
2024-10-09 10:36:28.166  3841-3841  APM_AudioPolicyManager  pid-3841                             D  #03 pc 0003b8e1  /system/lib/libaudiopolicymanagerdefault.so (android::ModuleTraits::deserialize(_xmlDoc*, _xmlNode const*, android::sp<android::HwModule>&, android::AudioPolicyConfig*)+1724)
2024-10-09 10:36:28.166  3841-3841  APM_AudioPolicyManager  pid-3841                             D  #04 pc 0003c91b  /system/lib/libaudiopolicymanagerdefault.so (android::PolicySerializer::deserialize(char const*, android::AudioPolicyConfig&)+534)
2024-10-09 10:36:28.166  3841-3841  APM_AudioPolicyManager  pid-3841                             D  #05 pc 00028f89  /system/lib/libaudiopolicymanagerdefault.so (android::AudioPolicyManager::loadConfig()+176)
2024-10-09 10:36:28.166  3841-3841  APM_AudioPolicyManager  pid-3841                             D  #06 pc 00028ecb  /system/lib/libaudiopolicymanagerdefault.so (android::AudioPolicyManager::AudioPolicyManager(android::AudioPolicyClientInterface*)+10)
2024-10-09 10:36:28.166  3841-3841  APM_AudioPolicyManager  pid-3841                             D  #07 pc 0000075f  /system/lib/libaudiopolicymanager.so (createAudioPolicyManager+14)
2024-10-09 10:36:28.166  3841-3841  APM_AudioPolicyManager  pid-3841                             D  #08 pc 00006615  /system/lib/libaudiopolicyservice.so (android::AudioPolicyService::onFirstRef()+280)
2024-10-09 10:36:28.166  3841-3841  APM_AudioPolicyManager  pid-3841                             D  #09 pc 000038b5  /system/bin/audioserver (android::BinderService<android::AudioPolicyService>::publish(bool, int)+72)
2024-10-09 10:36:28.166  3841-3841  APM_AudioPolicyManager  pid-3841                             D  #10 pc 00003543  /system/bin/audioserver (main+494)
2024-10-09 10:36:28.166  3841-3841  APM_AudioPolicyManager  pid-3841                             D  #11 pc 00088da5  /system/lib/libc.so (__libc_init+48)
2024-10-09 10:36:28.166  3841-3841  APM_AudioPolicyManager  pid-3841                             D  #12 pc 00003313  /system/bin/audioserver (_start_main+46)
2024-10-09 10:36:28.166  3841-3841  APM_AudioPolicyManager  pid-3841                             D  #13 pc 00000306  <anonymous:e84db000>
2024-10-09 10:36:28.167  3841-3841  APM::Serializer         pid-3841                             W  deserialize: ModuleTraits item=Built-In Mic
2024-10-09 10:36:28.167  3841-3841  APM::Devices            pid-3841                             V  DeviceVector::refreshTypes() mDeviceTypes 80000004
2024-10-09 10:36:28.167  3841-3841  APM::Devices            pid-3841                             V  DeviceVector::refreshTypes() p: 0xe583d074
2024-10-09 10:36:28.167  3841-3841  APM_AudioPolicyManager  pid-3841                             I  this=0xe583d074, mDeviceTypes=0x80000004
2024-10-09 10:36:28.167  3841-3841  APM::Serializer         pid-3841                             W  deserialize: ModuleTraits item=Handset Mic
2024-10-09 10:36:28.167  3841-3841  APM::Devices            pid-3841                             V  DeviceVector::refreshTypes() mDeviceTypes 80200004
2024-10-09 10:36:28.167  3841-3841  APM::Devices            pid-3841                             V  DeviceVector::refreshTypes() p: 0xe583d074
2024-10-09 10:36:28.167  3841-3841  APM_AudioPolicyManager  pid-3841                             I  this=0xe583d074, mDeviceTypes=0x80200004
2024-10-09 10:36:28.167  3841-3841  APM::Serializer         pid-3841                             W  deserialize: ModuleTraits item=Fake Headset
2024-10-09 10:36:28.167  3841-3841  APM::Devices            pid-3841                             V  DeviceVector::refreshTypes() mDeviceTypes 22000002
2024-10-09 10:36:28.167  3841-3841  APM::Devices            pid-3841                             V  DeviceVector::refreshTypes() p: 0xe583d05c
2024-10-09 10:36:28.167  3841-3841  APM_AudioPolicyManager  pid-3841                             I  this=0xe583d05c, mDeviceTypes=0x22000002
2024-10-09 10:36:28.167  3841-3841  APM::Serializer         pid-3841                             W  deserialize: ModuleTraits item=Fake Headset Mic
2024-10-09 10:36:28.167  3841-3841  APM::Devices            pid-3841                             V  DeviceVector::refreshTypes() mDeviceTypes 81200004
2024-10-09 10:36:28.167  3841-3841  APM::Devices            pid-3841                             V  DeviceVector::refreshTypes() p: 0xe583d074
2024-10-09 10:36:28.167  3841-3841  APM_AudioPolicyManager  pid-3841                             I  this=0xe583d074, mDeviceTypes=0x81200004
2024-10-09 10:36:28.167  3841-3841  APM::Serializer         pid-3841                             W  deserialize: ModuleTraits defaultOutputDevice=Speaker
2024-10-09 10:36:28.167  3841-3841  APM::Serializer         pid-3841                             W  deserialize: default is 00000002
2024-10-09 10:36:28.167  3841-3841  APM::Serializer         pid-3841                             W  deserialize: Deserialization complete

可以看到,解析的地方是status_t ModuleTraits::deserialize中,末尾那个大的while,需要搞清楚他在解析什么文件,去看一下什么情况

经过简易阅读此处源码,应该是audio/audio_policy_configuration.xml里的attachedDevices标签,才会被解析为可用
简易修改尝试一下

成功定位到AudioPolicyServer在初始化时,决定哪些设备可用是通过audio_policy_configuration.xml里的attachedDevices标签来决定的。

标签:2024,AudioPolicyManager,10,09,pid,3841,InputDevices,mAvailableOutputDevices,APM
From: https://www.cnblogs.com/chenshao107/p/18454791

相关文章