Android framework召回(3)binder使用和IBinder BpRefbase IInterface INTERFACE 之间的关系

status_t AudioSystem::setStreamVolumeIndex(audio_stream_type_t stream, int index, audio_devices_t device){
    const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();//
    if (aps == 0) return PERMISSION_DENIED;
    return aps->setStreamVolumeIndex(stream, index, device); //(1)
}
virtual status_t setStreamVolumeIndex(audio_stream_type_t stream, int index, audio_devices_t device){
    Parcel data, reply;
    data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
    data.writeInt32(static_cast <uint32_t>(stream));
    data.writeInt32(index);
    data.writeInt32(static_cast <uint32_t>(device));
    remote()->transact(SET_STREAM_VOLUME, data, &reply);//(2)
    return static_cast <status_t> (reply.readInt32());

}

我在追查音量设置问题是,从(1)追到(2)。就不知道怎么追查了,
grep -r setStreamVolumeIndex . 搜到AudioPolicyService。里面也有setStreamVolumeIndex这个函数,貌似会调用到这里。
打印log发现果然会走到这里,但是代码怎么走到这里的呢?这就须要我们了解binder原理。

例如以下图:是IBinder BpRefbase IInterface INTERFACE 之间关系图。


有了此图,尽管看不出binder是怎么实现的,可是我们就能大致binder是怎么利用的。

用setStreamVolumeIndex分析数据的流向。

例如以下图:


有一个关键点,就 是AudioPolicyService,是怎么传递到aps里面的mRemote里面的,它是通过重写interface_cast交货。

版权声明:本文博主原创文章。博客,未经同意不得转载。

原文地址:https://www.cnblogs.com/gcczhongduan/p/4813766.html