System Server
Android 系统服务进程 system_server,运行着各种服务,比如 PMS, AMS, WMS 等等。 该进程是启动时,由 Zygote 启动。
frameworks/base/core/java/com/android/internal/os/ZygoteInit.java
private static Runnable forkSystemServer(String abiList, string socketName, ZygoteServer zygoteServer) { ...... String args[] = { ...... "com.android.server.SystemServer" }; ...... pid = Zygote.forkSystemServer(...) if (pid == 0) { ...... zygoteServer.closeServerSocket(); return handleSystemServerProcess(parsedArgs); } return null; }
frameworks/base/services/java/com/android/server/SystemServer.java
public static void main(String[] args) { new SystemServer().run(); } private void run() { ...... // Initialize native services. System.loadLibrary("android_servers"); // Check whether we failed to shut down last time. performPendingShutdown(); // Initialize the system context createSystemContext(); // Create the system service manager. mSystemServiceManager = new SystemServiceManager(mSystemContext); mSystemServiceManager.setStartInfo(...); LocalServices.addService(SystemServiceManager.class, mSystemServiceManager); // prepare the thread pool for init tasks that can be parallelized SystemServerInitThreadPool.get(); // Start services. try { traceBeginAndSlog("StartServices"); startBootstrapServices(); startCoreServices(); startOtherServices(); SystemServerInitThreadPool.shutdown(); } catch (Throwable ex) { ... } finally { traceEnd(); } // Loop forever. Looper.loop(); throw new RuntimeException("Main thread loop unexpectedly exited"); } private void startBootstrapService() { Installer installer = mSystemServiceManager.startService(Installer.class); mSystemServiceManager.startService(DevicesIdentifiersPolicyService.class); mActivityManagerService = mSystemServiceManager.startService(ActivityManagerService.Lifecycle.class).getService(); mActivityManagerService.setSystemServiceManager(mSystemServiceManager); mActivityManagerService.setInstaller(installer); mPowerManagerService = mSystemServiceManager.startService(PowerManagerService.class); mActivityManagerService.initPowerManagement(); mSystemServiceManager.startService(RecoverySystemService.class); mSystemServiceManager.startService(LisghtService.class); mDisplayManagerService = mSystemServiceManager.startService(DisplayManagerService.class); mSYstemServiceManager.startBootPhase(SystemService.PHASE_WAIT_FOR_DEFAULT_DISPLAY); mPackageManagerService = PackageManagerService.main(...); mSystemServiceManager.startService(UserManagerService.LifeCycle.class); ...... } private void startCoreService() { mSystemServiceManager.startService(BatterService.class); mSystemServiceManager.startService(UsageStatsService.class); mWebViewUpdateService = mSystemServiceManager.startService(WebViewUpdateService.class); } private void startOtherServices() { // VibrateService IStorageManager NewWorkManagementService IpSecService NetworkStatsService NetworkPolicyManagerService ConnectivityService NsdService WindowManagerService SerialService NetworkTimeUpdateService CommonTimeManagementService InputManagerService TelephonyRegistry ConsumerIrService MmsServiceBroker HardwarePropertiesManagerService }