SystemServer 是Android系统用来创建系统服务的类。
入口: 找到main方法。
public static void main(String[] args) {
new SystemServer().run();
}
在main方法中,创建了一个SystemServer匿名类,调用run()方法。往下看:
// Start services.
try {
startBootstrapServices();
startCoreServices();
startOtherServices();
} catch (Throwable ex) {
Slog.e("System", "******************************************");
Slog.e("System", "************ Failure starting system services", ex);
throw ex;
}
在run方法的核心代码中有调用了三个start开头的方法,顾名思义分别启动了:引导类服务(BootstrapServices)、核心服务(CoreServices)以及其他服务(OtherServices)。
每一个具体包含哪些:
1): BootstrapServices
activity管理服务: mActivityManagerService = mSystemServiceManager.startService( ActivityManagerService.Lifecycle.class).getService();
电量管理服务: mPowerManagerService = mSystemServiceManager.startService(PowerManagerService.class);
页面展示服务: mDisplayManagerService = mSystemServiceManager.startService(DisplayManagerService.class);
包管理服务: mPackageManagerService = PackageManagerService.main(mSystemContext, installer,
mFactoryTestMode != FactoryTest.FACTORY_TEST_OFF, mOnlyCore);
2):CoreService
mSystemServiceManager.startService(LightsService.class);
370
371 // Tracks the battery level. Requires LightService.
372 mSystemServiceManager.startService(BatteryService.class);
373
374 // Tracks application usage stats.
375 mSystemServiceManager.startService(UsageStatsService.class);
376 mActivityManagerService.setUsageStatsManager(
377 LocalServices.getService(UsageStatsManagerInternal.class));
378 // Update after UsageStatsService is available, needed before performBootDexOpt.
379 mPackageManagerService.getUsageStatsIfNoPackageUsageInfo();
380
381 // Tracks whether the updatable WebView is in a ready state and watches for update installs.
382 mSystemServiceManager.startService(WebViewUpdateService.class);
383 }
3)OtherServices:
final Context context = mSystemContext;
391 AccountManagerService accountManager = null;
392 ContentService contentService = null;
393 VibratorService vibrator = null;
394 IAlarmManager alarm = null;
395 MountService mountService = null;
396 NetworkManagementService networkManagement = null;
397 NetworkStatsService networkStats = null;
398 NetworkPolicyManagerService networkPolicy = null;
399 ConnectivityService connectivity = null;
400 NetworkScoreService networkScore = null;
401 NsdService serviceDiscovery= null;
402 WindowManagerService wm = null;
403 BluetoothManagerService bluetooth = null;
404 UsbService usb = null;
405 SerialService serial = null;
406 NetworkTimeUpdateService networkTimeUpdater = null;
407 CommonTimeManagementService commonTimeMgmtService = null;
408 InputManagerService inputManager = null;
409 TelephonyRegistry telephonyRegistry = null;
410 ConsumerIrService consumerIr = null;
411 AudioService audioService = null;
412 MmsServiceBroker mmsService = null;
413