Binder(四)以AMS为例学习binder的请求过程

1.Service的大管家SystemServer

ServiceManager服务启动后,通过BINDER_SET_CONTEXT_MGR命令将自己设置为ContextManager,这样后面启动的服务就可以通过ServiceManager来管理,每当Client需要使用Server的功能时,首先通过ServiceManager获取这个Server服务,然后再调用Server的相关功能。

系统启动时,SystemServer.java中的run()方法会启动系统的一些服务,会依次调用下面三个方法**:**

cpp 复制代码
private void run() {    
            // Start services.
            t.traceBegin("StartServices");
            startBootstrapServices(t);
            startOtherServices(t);
            //......
}

2.ActivityManagerService 创建和启动,注册到SM中

java 复制代码
  private void startBootstrapServices(@NonNull TimingsTraceAndSlog t) {

    ...
     // Activity manager runs the show.
        ActivityTaskManagerService atm = mSystemServiceManager.startService(
        ActivityTaskManagerService.Lifecycle.class).getService();
        mActivityManagerService = ActivityManagerService.Lifecycle.startService(
                                  mSystemServiceManager, atm);
        mActivityManagerService.setSystemServiceManager(mSystemServiceManager);
    
    ...
        mActivityManagerService.setSystemProcess();

}
java 复制代码
public class ActivityManagerService extends IActivityManager.Stub{
  ......
  public void setSystemProcess() {
    ......
    ServiceManager.addService(Context.ACTIVITY_SERVICE, this, /* allowIsolated= */ true, DUMP_FLAG_PRIORITY_CRITICAL | DUMP_FLAG_PRIORITY_NORMAL | DUMP_FLAG_PROTO);
    ......
  }
}
相关推荐
每次的天空9 天前
Android学习总结之Binder篇
android·学习·binder
Bonnie_cat2 个月前
Android Framwork 之深入理解 IPC Binder机制
android·binder
Mekeater3 个月前
手写一个Java Android Binder服务及源码分析
android·java·binder·proxy·stub·mremote·bbinder
Mekeater3 个月前
手写一个C++ Android Binder服务及源码分析
android·c++·binder·remote·iservicemanager·bpbinder·bprefbase
aaajj4 个月前
【Android】直接使用binder的transact来代替aidl接口
android·binder
明天就是Friday5 个月前
Android Binder 进程间通信
android·binder
冬瓜神君5 个月前
Android14 AOSP 允许system分区和vendor分区应用进行AIDL通信
android·binder
小狗爱世界5 个月前
深入解析Binder源码
android·binder
深圳函数6 个月前
Binder架构
binder
Winston Wood6 个月前
Android Binder技术概览
android·binder·进程通信