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);
    ......
  }
}
相关推荐
帅次4 天前
Android 高级工程师专题深挖:WebView、Context 与初始化链
android·binder·webview·zygote·web app·dalvik
帅次6 天前
Android 高级工程师面试速记版
android·java·面试·kotlin·binder·zygote·android runtime
帅次11 天前
Android 高级工程师面试参考答案:Framework、生命周期、View 与 Binder
android·面试·binder
Grackers15 天前
Android Perfetto 系列 10:Binder 调度与锁竞争
android·binder
小书房20 天前
Android Binder机制
binder·aidl
消失的旧时光-19433 个月前
Binder 是如何贯穿 ART / Native / Kernel 的?
binder
灵感菇_3 个月前
全面解析Android Binder机制
android·binder
刘信的csdn4 个月前
RK3568 Android11 使用AIDL添加Hal层binder通讯
binder·hal·aidl
tmacfrank4 个月前
Binder 预备知识
linux·运维·binder
李坤林4 个月前
Android Binder 详解(6) Binder 客户端的创建
android·binder