Framework systemServer作用

1.systemServer执行顺序

在这里插入图片描述
init进程–》zygote进程–》Android虚拟机—》systemserver

system作用是干嘛

2.执行流程

public final class SystemServer {
    
    
    ...
    public static void main(String[] args) {
    
    
        //先初始化SystemServer对象,再调用对象的run()方法, 【见小节1.2】
        new SystemServer().run();
    }
}

1.创建loop 主线程对象
2.加载其他server的so库
3.创建context
4.启动引导服务 :ActivityManagerService, PowerManagerService, LightsService, DisplayManagerService, PackageManagerService, UserManagerService, sensor服务
5.启动核心服务:BatteryService,UsageStatsService,WebViewUpdateService
6.启动其他服务:
7.开启looper循环,不断接收应用的消息

private void run() {
    
    
 
    // 主线程looper就在当前线程运行
    Looper.prepareMainLooper();

    //加载android_servers.so库,该库包含的源码在frameworks/base/services/目录下
    System.loadLibrary("android_servers");

    //检测上次关机过程是否失败,该方法可能不会返回[见小节1.2.1]
    performPendingShutdown();

    //初始化系统上下文 【见小节1.3】
    createSystemContext();

    //创建系统服务管理
    mSystemServiceManager = new SystemServiceManager(mSystemContext);
    //将mSystemServiceManager添加到本地服务的成员sLocalServiceObjects
    LocalServices.addService(SystemServiceManager.class, mSystemServiceManager);


    //启动各种系统服务
    try {
    
    
        startBootstrapServices(); // 启动引导服务【见小节1.4】
        startCoreServices();      // 启动核心服务【见小节1.5】
        startOtherServices();     // 启动其他服务【见小节1.6】
    } catch (Throwable ex) {
    
    
        Slog.e("System", "************ Failure starting system services", ex);
        throw ex;
    }
 
    //一直循环执行
    Looper.loop();
    throw new RuntimeException("Main thread loop unexpectedly exited");
}

3.总结

systemserver主要用来加载其他framework层各种服务对象的,方便APP进程启动后使用。

猜你喜欢

转载自blog.csdn.net/chentaishan/article/details/118695792
今日推荐