🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
AMS由SystemServer的ServerThread线程创建,提取它的调用轨迹,代码如下: **SystemServer.java::ServerThread的run函数** ~~~ //①调用main函数,得到一个Context对象 context =ActivityManagerService.main(factoryTest); //②setSystemProcess:这样SystemServer进程可加到AMS中,并被它管理 ActivityManagerService.setSystemProcess(); //③installSystemProviders:将SettingsProvider放到SystemServer进程中来运行 ActivityManagerService.installSystemProviders(); //④在内部保存WindowManagerService(以后简称WMS) ActivityManagerService.self().setWindowManager(wm); //⑤和WMS交互,弹出“启动进度“对话框 ActivityManagerNative.getDefault().showBootMessage( context.getResources().getText( //该字符串中文为:“正在启动应用程序” com.android.internal.R.string.android_upgrading_starting_apps), false); //⑥AMS是系统的核心,只有它准备好后,才能调用其他服务的systemReady //注意,有少量服务在AMS systemReady之前就绪,它们不影响此处的分析 ActivityManagerService.self().systemReady(newRunnable() { public void run() { startSystemUi(contextF);//启动systemUi。如此,状态栏就准备好了 if(batteryF != null) batteryF.systemReady(); if(networkManagementF != null) networkManagementF.systemReady(); ...... Watchdog.getInstance().start();//启动Watchdog ......//调用其他服务的systemReady函数 } ~~~ 在以上代码中,一共列出了6个重要调用及这些调用的简单说明,本节将分析除与WindowManagerService(以后简称WMS)交互的4、5外的其余四项调用。 先来分析1处调用。