SystemServer.java
类中方法执行
在这个类中有main()方法,这个类从main()方法开始执行。
- main():
public static void main(String[] args){
new SystemServer().run();
}
在main()方法中去生成一个SystemServer对象,并执行这个对象的run()方法。
public SystemServer(){
//省略代码;
}
- run():
private void run(){
//省略代码;
Looper.prepareMainLooper();
//加载native服务;
System.loadLibrary("android_servers");
//检测上次是否成功关机;
performPendingShutdown();
//生成Context,初始化系统上下文,其实是生成一个ContextImpl对象;
createSystemContext();
//生成一个SystemServiceManager对象,并把它添加到LocalServices中,其中mSystemContext参数就是通过createSystemContext()方法来生成的;
mSystemServiceManager = new SystemServiceManager(mSystemContext);
mSystemServiceManager.setRuntimeRestarted(mRuntimeRestart);
LocalServices.addService(SystemServiceManager.class,mSystemServiceManager);
//使用单例模式生成SystemServerInitThreadPool线程池对象;
SystemServerInitThreadPool.get();
//---;
//启动一些服务;
//启动引导服务;
startBootstarpServices();
//启动核心服务;
startCoreServices();
//启动其他服务;
startOtherServices();
SystemServerInitThreadPool.shutdown();
//---;
//开始消息循环;
Looper.loop();
}
- startBootstrapService():
private void startBootstrapService(){
//---;
//创建SystemConfig,进行权限的获取;
SystemServerInitThreadPool.get().submit(SystemConfig::getInstance,TAG_SYSTEM_CONFIG);
//启动Installer安装器服务;
Installer installer = mSystemServiceManager.startService(Installer.class);
//开启设备识别器服务;
mSystemServiceManager.startService(DeviceIdentifiersPolicyService.class);
//启动并初始化ActivityManagerService,Installer服务赋值给AMS;
mActivityManagerService = mSystemServiceManager.startService(ActivityManagerService.lifecycle.class).getService();
mActivityManagerService.setSystemServiceManager(mSystemServiceManager);
mActivityManagerService.setInstaller(installer);
//启动PowerManagerService电量管理服务;
mPowerManagerService = mSystemServiceManager.startService(PowerManagerService.class);
//初始化电量管理器;
mActivityManagerService.initPowerManagement();
//---;
//启动RecoverySystem服务;
mSystemServiceManager.startService(RecoverySystemService.class);
//标记裸机已经启动完了,如果我们困在运行时的重启循环中,这个标记可以跳出循环;
RescueParty.noteBoot(mSystemContext);
//启动灯光服务,包括背景亮度、闪光灯等;
mSystemServiceManager.startService(LightService.class);
//启动显示服务,用来显示UI;
mDisplayManagerService = mSystemServiceManager.startService(DisplayManagerService.class);
//开始开机动画;
mSystemServiceManager.startBootPhase(SystemService.PHASE_WAIT_FOR_DEFAULT_DISPLAY);
//加密模式下,只运行内核应用,此处先设置标志位;
String cryptState = SystemProperties.get("vold.decrypt");
if (ENCRYPTING_STATE.equals(cryptState)) {
mOnlyCore = true;
} else if (ENCRYPTED_STATE.equals(cryptState)) {
mOnlyCore = true;
}
//---;
//获取包管理器;
mPackageManagerService = PackageManagerService.main(mSystemContext,installer,mFactoryTestMode != FactoryTest.FACTORY_TEST_OFF,mOnlyCore);
//---;
//启动用户管理服务;
mSystemServiceManager.startService(UserManagerService.LifeCycle.class);
//从系统包中初始化属性资源;
AttributeCache.init(mSystemContext);
//设置系统进程;
mActivityManagerService.setSystemProcess();
//设置ui的调整策略;
mDisplayManagerService.setupSchedulerPolicies();
//启动OverlayManagerService;
mSystemServiceManager.startService(new OverManagerService(mSystemContext,installer));
//启动传感器服务;
mSersorServiceStart = SystemServerInitThreadPool.get().submit(() -> {
BootTimingsTraceLog traceLog = new BootTimingsTraceLog(
SYSTEM_SERVER_TIMING_ASYNC_TAG, Trace.TRACE_TAG_SYSTEM_SERVER);
traceLog.traceBegin(START_SENSOR_SERVICE);
startSensorService();
}
- startCoreServices():
private void startCoreService(){
//启动DropBox服务,用来记录系统日志;
mSystemServiceManager.startService(DropBoxManagerService.class);
//启动电池服务;
mSystemServiceManager.startService(BatteryService.class);
//启动使用状态服务;
mSystemServiceManager.startService(UsageStateService.class);
mActivityManagerService.setUsageStatsManager(LocalServices.getService(UsageStatsManagerInternal.class));
//启动WebView更新服务;
mWebViewUpdateService = mSystemServiceManager.startService(WebViewUpdateService.class);
}
- startOtherServices():
private void startOtherServices(){
//在这个方法里也启动了好多其他的服务,这个方法代码一千多行,暂时不分析;
}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-------------------last line for now------------------