http://blog.csdn.net/lsdmx2016/article/details/8772583

Android4.1 中出现了一个新的类,BinderService,所有的Native Service 都会继承这个类。
class BinderService
{
public:
    static status_t publish(bool allowIsolated = false) {
        sp<IServiceManager> sm(defaultServiceManager());
        return sm->addService(String16(SERVICE::getServiceName()), new SERVICE(), allowIsolated);
    }

static void publishAndJoinThreadPool(bool allowIsolated = false) {
        sp<IServiceManager> sm(defaultServiceManager());
        sm->addService(String16(SERVICE::getServiceName()), new SERVICE(), allowIsolated);
        ProcessState::self()->startThreadPool();
        IPCThreadState::self()->joinThreadPool();
    }

static void instantiate() { publish(); }

static status_t shutdown() {
        return NO_ERROR;
    }
};
从代码中可以得知,这个类的publish(),就是将Native Service 注册到ServiceManager,同时 BinderService 作为 NativeService 的友元类。这是因为BinderService 需要访问 Native Service 的getServiceName方法。

05-17 07:33