Android ServiceManager

一、ServiceManager介绍

ServiceManager是Binder的守护进程,在Android上如果service manager挂掉,所有采用Binder通信的进程服务都会挂掉。

ServiceManager本身也是一个Binder服务,handle固定为0。提供注册服务,查询服务的功能。应用程序相要通过Binder向一个service发送数据,必须先通过Service Manager获取该service的handle然后才能通过binder驱动与service通信。

Service Manager既然也是一个service,那按照流程,Service Manager的逻辑流程就应该如下:

1.打开binder驱动

2.向binder驱动注册一个service,这个service就是servicemanager

3.进入一个loop循环,轮询binder驱动,查看是否有其他的进行要与service manager通信(注册service 查询service等)

ServiceManager于android binder来说是非常重要的一部分。ServiceManager在java层与native层都有各自的逻辑,整体的流程图:

二、ServiceManager相关类、接口、文件

IServiceManager

Basic interface for finding and publishing system services.

IServiceManager文件路径:

frameworks/native/libs/binder/aidl/android/os/IServiceManager.aidl

IServiceManager定义:

interface IServiceManager {}

IServiceManager方法:

IBinder getService(@utf8InCpp String name):Retrieve an existing service called @a name from the service manager.
IBinder checkService(@utf8InCpp String name):Retrieve an existing service called @a name from the service manager. 
void addService(@utf8InCpp String name, IBinder service, boolean allowIsolated, int dumpPriority):Place a new @a service called @a name into the service manager.
String[] listServices(int dumpPriority):Return a list of all currently running services.
void registerForNotifications(@utf8InCpp String name, IServiceCallback callback):Request a callback when a service is registered.
void unregisterForNotifications(@utf8InCpp String name, IServiceCallback callback):Unregisters all requests for notifications for a specific callback.
boolean isDeclared(@utf8InCpp String name):Returns whether a given interface is declared on the device, even if it 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值