在分析Jelly Bean Audio Subsystem的时候,发现HAL层的库audio_policy.xxx.so与其依赖的静态库libaudiopolicy_legacy.a都有audio_policy_hal.cpp这个源文件而且两者都定义了一个HMI。当调用者引用HMI的时候,调用的究竟是哪个呢?
首先看audio_policy.xxx.so的Android.mk文件,在定义编译audio_policy.xxx.so的段落里面有这么一句:
LOCAL_STATIC_LIBRARIES := \
libaudiohw_legacy \
libmedia_helper \
libaudiopolicy_legacy
说明libaudiopolicy_legacy是以静态库的形式为audio_policy.xxx.so所用,而在通用的audio_policy库(也可以说是谷歌提供给厂商参考用的policy库)audio_policy.default.so的库里面是这么用的:
LOCAL_WHOLE_STATIC_LIBRARIES := \
libaudiopolicy_legacy
而audio_policy.default.so的源码里面就没有audio_policy_hal.cpp这个源文件,所以玄机应该就在LOCAL_WHOLE_STATIC_LIBRARIES和LOCAL_STATIC_LIBRARIES这两个宏的差异上面。先看下谷歌在build/core/build-system.html里面是怎么说的:
LOCAL_STATIC_LIBRARIES
These are the static libraries that you want to include in your module. Mostly, we use shared libraries, but there are a couple of places, like executables in sbin and host executables where we use static libraries instead.
LOCAL_WHOLE_STATIC_LIBRARIES
These are the static libraries that you want to include in your module without allowing the linker to remove dead code from them. This is mostly useful if you want to add a static library to a shared library and have the static library's content exposed from the shar