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);
    ......
  }
}
相关推荐
Qiuner3 天前
Spring Boot 机制二:配置属性绑定 Binder 源码解析(ConfigurationProperties 全链路)
java·spring boot·后端·spring·binder
无心水4 天前
【Python实战进阶】2、Jupyter Notebook终极指南:为什么说不会Jupyter就等于不会Python?
python·jupyter·信息可视化·binder·google colab·python实战进阶·python工程化实战进阶
nono牛9 天前
Android Binder 详解与实践指南
android·binder
nono牛10 天前
Android Binder C/C++ 层详解与实践
android·c语言·binder
峰哥的Android进阶之路21 天前
Android的binder机制理解
android·binder
我是好小孩25 天前
【Android】Binder 原理初探:理解 Android 进程通信机制
android·gitee·binder
yueqc11 个月前
Android 通信机制简析
android·binder·handle
锋风Fengfeng2 个月前
基于Binder的4种RPC调用
网络协议·rpc·binder
g_i_a_o_giao3 个月前
Android8 binder源码学习分析笔记(四)——ServiceManager启动
笔记·学习·binder
g_i_a_o_giao3 个月前
Android8 binder源码学习分析笔记(一)
android·java·笔记·学习·binder·安卓源码分析