IServiceConnection
bindService,我们会传递一个ServiceConnection对象,这个ServiceConnection对与IServiceConnection做一个映射,系统帮我们初始化完成Service后会将我们自己写的Binder Stub(Server端)通过IServiceConnection返回给Client端
1 | public interface IServiceConnection extends IInterface { |
这里我们关注Proxy,其中的mRemote为BinderProxy,这里我们不太需要关注mRemote,因为它已经有了跨进程能力,这里我们关注两个点
- writeStrongBinder
- transact
writeStrongBinder
1 | public class Parcel { |
首次Parcel创建的时候,会调用native c++ 中的
/Volumes/android/aosp/frameworks/base/core/jni/android_os_Parcel.cpp
1 | {"nativeCreate", "()J", (void*)android_os_Parcel_create}, |
/Volumes/android/aosp/frameworks/base/core/jni/android_util_Binder.cpp
1 | // 写入的时候肯定是BinderProxy,因为server进程拿到的是用户进程的Service Binder |
/Volumes/android/aosp/frameworks/native/libs/binder/Parcel.cpp
1 | Parcel::Parcel() |
transact
BinderProxy
1 | public native boolean transactNative(int code, Parcel data, Parcel reply, |
/Volumes/android/aosp/frameworks/base/core/jni/android_util_Binder.cpp
1 | {"transactNative", "(ILandroid/os/Parcel;Landroid/os/Parcel;I)Z", (void*)android_os_BinderProxy_transact}, |