注册服务

addService ---------> ServiceManager.java

public static void addService(String name, IBinder service) {
        try {
            getIServiceManager().addService(name, service, false);
        } catch (RemoteException e) {
            Log.e(TAG, "error in addService", e);
        }
}
private static IServiceManager getIServiceManager() {
        if (sServiceManager != null) {
            return sServiceManager;
        }
        sServiceManager = ServiceManagerNative.asInterface(BinderInternal.getContextObject());
        return sServiceManager;
}

接下来分析getIServiceManager方法的返回值问题,请注意BinderInternal.getContextObject()的native方法已经做了与jni的映射。

BinderInternal.getContextObject()返回的BinderProxy对象,原因请见android_util_Binder.cpp

ServiceManagerNative.asInterface(BinderInternal.getContextObject())最终返回的ServiceManagerProxy对象,详情

所以注册服务最终调用的是ServiceManagerProxy.addService

results matching ""

    No results matching ""