海安公司网站建设360网站推广怎么做
前言
SystemServer 是 Android 系统的核心进程,由 Zygote 孵化,负责启动和管理所有核心系统服务,像是常见的ActivityManagerService、WindowManagerService、PackageManagerService、PowerManagerService等服务,都是在SystemServer的main方法中能够初始化的,这些服务都是运行在system_server进程的线程中。它是 Android 框架层的“大脑”,直接决定了系统的功能性和稳定性。
Zygote进程进入system_server进程
我们在Android 12系统源码_系统启动(二)Zygote进程中有讲过 ZygoteInit的main方法,在解析到 start-system-server 参数后会调用 forkSystemServer方法。
public class ZygoteInit {public static void main(String[] argv) {...代码省略...if (startSystemServer) {//注释1,fork出system_server子进程Runnable r = forkSystemServer(abiList, zygoteSocketName, zygoteServer);//如果是父进程则返回null,如果是system_server子进程则返回SystemServerRunnableif (r != null) {r.run();//注释2,在子进程(system_server)中执行,SystemServerRunnable的run方法会进入了SystemServer的main方法return;}}...代码省略...}private static Runnable forkSystemServer(String abiList, String socketName,ZygoteServer zygoteServer) {...代码省略.../* Hardcoded command line to start the system server */String[] args = {"--setuid=1000",//用户id"--setgid=1000",//组id"--setgroups=1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,1018,1021,1023,"+ "1024,1032,1065,3001,3002,3003,3006,3007,3009,3010,3011,3012","--capabilities=" + capabilities + "," + capabilities,"--nice-name=system_server","--runtime-args","--target-sdk-version=" + VMRuntime.SDK_VERSION_CUR_DEVELOPMENT,"com.android.server.SystemServer",//SystemServer类名,只有这个条目是非--开头的};if (pid == 0) {...代码省略...//由于zygoteServer只有Zygote会使用,子进程system_server不需要使用,于是会将其关闭。zygoteServer.closeServerSocket();//继续调用handleSystemServerProcess方法return handleSystemServerProcess(parsedArgs);}return null;}private static Runnable handleSystemServerProcess(ZygoteArguments parsedArgs) {...代码省略...//调用ZygoteInit的zygoteInit方法return ZygoteInit.zygoteInit(parsedArgs.mTargetSdkVersion,parsedArgs.mDisabledCompatChanges,parsedArgs.mRemainingArgs, cl);}public static Runnable zygoteInit(int targetSdkVersion, long[] disabledCompatChanges,String[] argv, ClassLoader classLoader) {...代码省略...//调用RuntimeInit的applicationInit方法return RuntimeInit.applicationInit(targetSdkVersion, disabledCompatChanges, argv,classLoader);}
}>frameworks/base/core/java/com/android/internal/os/RuntimeInit.javapublic class RuntimeInit {protected static Runnable applicationInit(int targetSdkVersion, long[] disabledCompatChanges,String[] argv, ClassLoader classLoader) {...代码省略...final Arguments args = new Arguments(argv);//解析参数argvreturn findStaticMain(args.startClass, args.startArgs, classLoader);}static class Arguments {String startClass;//类路径String[] startArgs;//参数Arguments(String args[]) throws IllegalArgumentException {parseArgs(args);}private void parseArgs(String args[])throws IllegalArgumentException {int curArg = 0;for (; curArg < args.length; curArg++) {String arg = args[curArg];if (arg.equals("--")) {curArg++;break;} else if (!arg.startsWith("--")) {//com.android.server.SystemServer字符串break;}}if (curArg == args.length) {throw new IllegalArgumentException("Missing classname argument to RuntimeInit!");}startClass = args[curArg++];startArgs = new String[args.length - curArg];System.arraycopy(args, curArg, startArgs, 0, startArgs.length);} }protected static Runnable findStaticMain(String className, String[] argv, ClassLoader classLoader) {Class<?> cl;...代码省略..//获取到SystemServer的类类型cl = Class.forName(className, true, classLoader);...代码省略..Method m;//获取到main方法的方法idm = cl.getMethod("main", new Class[] { String[].class });...代码省略..//这个就是ZygoteInit类中forkSystemServer的返回值rreturn new MethodAndArgsCaller(m, argv);}static class MethodAndArgsCaller implements Runnable {private final Method mMethod;private final String[] mArgs;public MethodAndArgsCaller(Method method, String[] args) {mMethod = method;mArgs = args;}public void run() {...代码省略...//通过反射调用mMethod静态方法,这里触发的其实就是SystemServer的main方法mMethod.invoke(null, new Object[] { mArgs });...代码省略...}}
Zygote进程对应的ZygoteInit的main方法会调用forkSystemServer方法fork出system_server这个子进程,该方法会解析args参数,最终返回MethodAndArgsCaller对象,并进入system_server进程,然后在system_server进程中调用MethodAndArgsCaller的run方法,最终会进入SystemServer的main方法。
SystemServer的main方法
frameworks/base/services/java/com/android/server/SystemServer.java
public final class SystemServer implements Dumpable {public static void main(String[] args) {new SystemServer().run();}private void run() {TimingsTraceAndSlog t = new TimingsTraceAndSlog();...代码省略... t.traceBegin("InitBeforeStartServices"); //日志打印:SystemServerTiming: startBootstrapServices//SystemProperties相关属性设置......代码省略...//Here we go! 关键日志打印Slog.i(TAG, "Entered the Android system server!");...代码省略...//创建Looper对象Looper.prepareMainLooper();...代码省略...//加载动态链接库System.loadLibrary("android_servers");...代码省略...//创建一个systemContext,和普通应用的Context一样,system也需要通过Context来获取一些进程的信息环境createSystemContext();// ...代码省略...t.traceEnd(); //日志打印:startBootstrapServices took to complete: 1588ms...代码省略... // Start services.try {t.traceBegin("StartServices");//日志打印:SystemServerTiming: StartServices//启动引导服务startBootstrapServices(t);//启动核心服务startCoreServices(t);//启动其他服务startOtherServices(t);} catch (Throwable ex) {Slog.e("System", "******************************************");Slog.e("System", "************ Failure starting system services", ex);throw ex;} finally {t.traceEnd(); //日志打印:StartServices took to complete: 3997ms} ...代码省略... // Loop forever.Looper.loop();throw new RuntimeException("Main thread loop unexpectedly exited"); }
}
frameworks/base/services/core/java/com/android/server/utils/TimingsTraceAndSlog.java
public final class TimingsTraceAndSlog extends TimingsTraceLog {public static final String SYSTEM_SERVER_TIMING_TAG = "SystemServerTiming";@Overridepublic void traceBegin(@NonNull String name) {//打印开始日志,tag为SystemServerTiming,name为开始关键字Slog.i(mTag, name);super.traceBegin(name);}
}
frameworks/base/core/java/android/util/TimingsTraceLog.java
public class TimingsTraceLog {public void traceBegin(String name) {...代码省略...mCurrentLevel++;mStartNames[mCurrentLevel] = name;mStartTimes[mCurrentLevel] = SystemClock.elapsedRealtime();}public void traceEnd() {...代码省略...final String name = mStartNames[mCurrentLevel];final long duration = SystemClock.elapsedRealtime() - mStartTimes[mCurrentLevel];mCurrentLevel--;//打印结束日志信息,tag为SystemServerTiming,name为结束关键字,并记录从开始到结束总共花了多长时间logDuration(name, duration);}public void logDuration(String name, long timeMs) {Slog.d(mTag, name + " took to complete: " + timeMs + "ms");}
}
SystemProperties相关属性设置
public final class SystemServer implements Dumpable {private static final String SYSPROP_START_COUNT = "sys.system_server.start_count";private static final String SYSPROP_START_ELAPSED = "sys.system_server.start_elapsed";private static final String SYSPROP_START_UPTIME = "sys.system_server.start_uptime";private void run() {...代码省略...//将启动次数、启动时间写入系统属性SystemProperties.set(SYSPROP_START_COUNT, String.valueOf(mStartCount));SystemProperties.set(SYSPROP_START_ELAPSED, String.valueOf(mRuntimeStartElapsedTime));SystemProperties.set(SYSPROP_START_UPTIME, String.valueOf(mRuntimeStartUptime));// 写入系统事件日志(便于调试)EventLog.writeEvent(EventLogTags.SYSTEM_SERVER_START,mStartCount, mRuntimeStartUptime, mRuntimeStartElapsedTime);//设置默认时区String timezoneProperty = SystemProperties.get("persist.sys.timezone");if (!isValidTimeZoneId(timezoneProperty)) {//检查时区配置是否有效,无效则默认设为 GMT(格林尼治标准时间)Slog.w(TAG, "persist.sys.timezone is not valid (" + timezoneProperty+ "); setting to GMT.");SystemProperties.set("persist.sys.timezone", "GMT");}//处理语言和区域设置if (!SystemProperties.get("persist.sys.language").isEmpty()) {final String languageTag = Locale.getDefault().toLanguageTag();//Android现在统一使用 Locale 类管理区域设置。SystemProperties.set("persist.sys.locale", languageTag);//清除以前的旧版语言和国家属性SystemProperties.set("persist.sys.language", "");SystemProperties.set("persist.sys.country", "");SystemProperties.set("persist.sys.localevar", "");}...代码省略...//设置 Dalvik/ART 运行时库SystemProperties.set("persist.sys.dalvik.vm.lib.2", VMRuntime.getRuntime().vmLibrary());...代码省略...}
}
启动引导服务
public final class SystemServer implements Dumpable {private void startBootstrapServices(@NonNull TimingsTraceAndSlog t) {t.traceBegin("startBootstrapServices");//日志打印:SystemServerTiming: startBootstrapServicest.traceBegin("StartWatchdog");//日志打印:SystemServerTiming: StartWatchdog//看门狗final Watchdog watchdog = Watchdog.getInstance();watchdog.start();t.traceEnd();//日志打印:SystemServerTiming: StartWatchdog took to complete: 7ms...代码省略...//开启AMSt.traceBegin("StartActivityManager");//日志打印:SystemServerTiming: StartActivityManager//调用SystemServiceManager的startService方法,开启ActivityTaskManagerService服务ActivityTaskManagerService atm = mSystemServiceManager.startService(ActivityTaskManagerService.Lifecycle.class).getService();//调用ActivityManagerService.Lifecycle的startService方法,开启ActivityManagerService服务mActivityManagerService = ActivityManagerService.Lifecycle.startService(mSystemServiceManager, atm);//让ActivityManagerService持有SystemServiceManager的引用mActivityManagerService.setSystemServiceManager(mSystemServiceManager);mActivityManagerService.setInstaller(installer);mWindowManagerGlobalLock = atm.getGlobalLock();t.traceEnd();//日志打印:StartActivityManager took to complete: 348ms...代码省略...t.traceBegin("StartPowerManager");//日志打印:StartPowerManager//电源管理服务mPowerManagerService = mSystemServiceManager.startService(PowerManagerService.class);t.traceEnd();//日志打印:StartPowerManager took to complete: 20mst.traceBegin("StartRecoverySystemService");//SystemServerTiming: StartRecoverySystemService//RecoverySystem服务mSystemServiceManager.startService(RecoverySystemService.Lifecycle.class);t.traceEnd();//SystemServerTiming: StartRecoverySystemService took to complete: 1ms...代码省略...t.traceBegin("StartLightsService");//SystemServerTiming: StartLightsService//屏幕亮度服务mSystemServiceManager.startService(LightsService.class);t.traceEnd();//SystemServerTiming: StartLightsService took to complete: 3ms...代码省略...t.traceBegin("StartDisplayManager");//SystemServerTiming: StartDisplayManager//屏幕设备管理服务mDisplayManagerService = mSystemServiceManager.startService(DisplayManagerService.class);t.traceEnd();//SystemServerTiming: StartDisplayManager took to complete: 15ms//在初始化PackageManagerService服务之前我们要保证至少有个默认屏幕设备t.traceBegin("WaitForDisplay");//SystemServerTiming: WaitForDisplaymSystemServiceManager.startBootPhase(t, SystemService.PHASE_WAIT_FOR_DEFAULT_DISPLAY);t.traceEnd();SystemServerTiming: WaitForDisplay took to complete: 9ms...代码省略...t.traceBegin("StartPackageManagerService");//SystemServerTiming: StartPackageManagerServicetry {Watchdog.getInstance().pauseWatchingCurrentThread("packagemanagermain");//PackageManagerService服务mPackageManagerService = PackageManagerService.main(mSystemContext, installer,domainVerificationService, mFactoryTestMode != FactoryTest.FACTORY_TEST_OFF,mOnlyCore);} finally {Watchdog.getInstance().resumeWatchingCurrentThread("packagemanagermain");}SystemServerDexLoadReporter.configureSystemServerDexReporter(mPackageManagerService);mFirstBoot = mPackageManagerService.isFirstBoot();mPackageManager = mSystemContext.getPackageManager();t.traceEnd();//SystemServerTiming: StartPackageManagerService took to complete: 1022ms...代码省略...t.traceBegin("StartUserManagerService");//SystemServerTiming: StartUserManagerService//用户管理服务mSystemServiceManager.startService(UserManagerService.LifeCycle.class);t.traceEnd();//SystemServerTiming: StartUserManagerService took to complete: 0ms...代码省略...t.traceBegin("SetSystemProcess");//SystemServerTiming: SetSystemProcessmActivityManagerService.setSystemProcess();t.traceEnd();//SystemServerTiming: SetSystemProcess took to complete: 5ms...代码省略...t.traceBegin("InitWatchdog");//SystemServerTiming: InitWatchdogwatchdog.init(mSystemContext, mActivityManagerService);t.traceEnd();//SystemServerTiming: InitWatchdog took to complete: 0ms...代码省略...t.traceBegin("StartOverlayManagerService");//SystemServerTiming: StartOverlayManagerServicemSystemServiceManager.startService(new OverlayManagerService(mSystemContext));t.traceEnd();//SystemServerTiming: StartOverlayManagerService took to complete: 77ms...代码省略...t.traceBegin("StartSensorService");//SystemServerTiming: StartSensorServicemSystemServiceManager.startService(SensorService.class);t.traceEnd(); //SystemServerTiming: StartSensorService took to complete: 1mst.traceEnd();//SystemServerTiming: startBootstrapServices took to complete: 1588ms}
}
启动核心服务
public final class SystemServer implements Dumpable {private void startCoreServices(@NonNull TimingsTraceAndSlog t) {t.traceBegin("startCoreServices");//SystemServerTiming: startCoreServicest.traceBegin("StartSystemConfigService");//SystemServerTiming: StartSystemConfigServicemSystemServiceManager.startService(SystemConfigService.class);//系统设置t.traceEnd();//SystemServerTiming: StartSystemConfigService took to complete: 0mst.traceBegin("StartBatteryService");//SystemServerTiming: StartBatteryServicemSystemServiceManager.startService(BatteryService.class);//电池状态监控t.traceEnd();//SystemServerTiming: StartBatteryService took to complete: 15mst.traceBegin("StartUsageService");//SystemServerTiming: StartUsageServicemSystemServiceManager.startService(UsageStatsService.class);//用户状态服务mActivityManagerService.setUsageStatsManager(LocalServices.getService(UsageStatsManagerInternal.class));t.traceEnd();//SystemServerTiming: StartUsageService took to complete: 5msif (mPackageManager.hasSystemFeature(PackageManager.FEATURE_WEBVIEW)) {t.traceBegin("StartWebViewUpdateService");//SystemServerTiming: StartWebViewUpdateServicemWebViewUpdateService = mSystemServiceManager.startService(WebViewUpdateService.class);t.traceEnd();//SystemServerTiming: StartWebViewUpdateService took to complete: 1ms}t.traceBegin("StartCachedDeviceStateService");//SystemServerTiming: StartCachedDeviceStateServicemSystemServiceManager.startService(CachedDeviceStateService.class);t.traceEnd();//SystemServerTiming: StartCachedDeviceStateService took to complete: 0ms// Tracks cpu time spent in binder callst.traceBegin("StartBinderCallsStatsService");//SystemServerTiming: StartBinderCallsStatsServicemSystemServiceManager.startService(BinderCallsStatsService.LifeCycle.class);t.traceEnd();//SystemServerTiming: StartBinderCallsStatsService took to complete: 0ms// Tracks time spent in handling messages in handlers.t.traceBegin("StartLooperStatsService");//SystemServerTiming: StartLooperStatsServicemSystemServiceManager.startService(LooperStatsService.Lifecycle.class);t.traceEnd();//SystemServerTiming: StartLooperStatsService took to complete: 1ms// Manages apk rollbacks.t.traceBegin("StartRollbackManagerService");//SystemServerTiming: StartRollbackManagerServicemSystemServiceManager.startService(ROLLBACK_MANAGER_SERVICE_CLASS);t.traceEnd();//SystemServerTiming: StartRollbackManagerService took to complete: 19ms// Tracks native tombstones.t.traceBegin("StartNativeTombstoneManagerService");//SystemServerTiming: StartNativeTombstoneManagerServicemSystemServiceManager.startService(NativeTombstoneManagerService.class);t.traceEnd();//SystemServerTiming: StartNativeTombstoneManagerService took to complete: 4ms// Service to capture bugreports.t.traceBegin("StartBugreportManagerService");//SystemServerTiming: StartBugreportManagerServicemSystemServiceManager.startService(BugreportManagerService.class);t.traceEnd();//SystemServerTiming: StartBugreportManagerService took to complete: 1ms// Serivce for GPU and GPU driver.t.traceBegin("GpuService");//SystemServerTiming: GpuServicemSystemServiceManager.startService(GpuService.class);//GPU服务t.traceEnd();//SystemServerTiming: GpuService took to complete: 0mst.traceEnd(); // SystemServerTiming: startCoreServices took to complete: 47ms}
}
启动其他服务
public final class SystemServer implements Dumpable {private static final String ACCOUNT_SERVICE_CLASS ="com.android.server.accounts.AccountManagerService$Lifecycle";private static final String STORAGE_MANAGER_SERVICE_CLASS ="com.android.server.StorageManagerService$Lifecycle";private static final String STORAGE_STATS_SERVICE_CLASS ="com.android.server.usage.StorageStatsService$Lifecycle";private static final String USB_SERVICE_CLASS ="com.android.server.usb.UsbService$Lifecycle"; private void startOtherServices(@NonNull TimingsTraceAndSlog t) {t.traceBegin("startOtherServices");//SystemServerTiming: startOtherServicesfinal Context context = mSystemContext;DynamicSystemService dynamicSystem = null;IStorageManager storageManager = null;//StorageManagerService,管理存储设备(如 SD 卡挂载)NetworkManagementService networkManagement = null;//管理网络连接(Wi-Fi、移动数据)IpSecService ipSecService = null;VpnManagerService vpnManager = null;//VNP管理服务VcnManagementService vcnManagement = null;NetworkStatsService networkStats = null;NetworkPolicyManagerService networkPolicy = null;NsdService serviceDiscovery = null;WindowManagerService wm = null;//管理窗口布局和动画。SerialService serial = null;NetworkTimeUpdateService networkTimeUpdater = null;InputManagerService inputManager = null;//处理触摸、按键等输入事件。TelephonyRegistry telephonyRegistry = null;ConsumerIrService consumerIr = null;MmsServiceBroker mmsService = null;HardwarePropertiesManagerService hardwarePropertiesService = null;PacProxyService pacProxyService = null; ...代码省略...mContentResolver = context.getContentResolver();// The AccountManager must come before the ContentServicet.traceBegin("StartAccountManagerService");//SystemServerTiming: StartAccountManagerService//账号管理服务mSystemServiceManager.startService(ACCOUNT_SERVICE_CLASS);t.traceEnd();//SystemServerTiming: StartAccountManagerService took to complete: 12ms...代码省略...t.traceBegin("StartInputManagerService");//SystemServerTiming: StartInputManagerServiceinputManager = new InputManagerService(context);t.traceEnd();//SystemServerTiming: StartInputManagerService took to complete: 12mst.traceBegin("DeviceStateManagerService");//SystemServerTiming: DeviceStateManagerServicemSystemServiceManager.startService(DeviceStateManagerService.class);t.traceEnd();//SystemServerTiming: DeviceStateManagerService took to complete: 3msif (!disableCameraService) {t.traceBegin("StartCameraServiceProxy");//SystemServerTiming: StartCameraServiceProxymSystemServiceManager.startService(CameraServiceProxy.class);t.traceEnd();//SystemServerTiming: StartCameraServiceProxy took to complete: 6ms}t.traceBegin("StartWindowManagerService");//SystemServerTiming: StartWindowManagerService// WMS needs sensor service readymSystemServiceManager.startBootPhase(t, SystemService.PHASE_WAIT_FOR_SENSOR_SERVICE);wm = WindowManagerService.main(context, inputManager, !mFirstBoot, mOnlyCore,new PhoneWindowManager(), mActivityManagerService.mActivityTaskManager);ServiceManager.addService(Context.WINDOW_SERVICE, wm, /* allowIsolated= */ false,DUMP_FLAG_PRIORITY_CRITICAL | DUMP_FLAG_PROTO);ServiceManager.addService(Context.INPUT_SERVICE, inputManager,/* allowIsolated= */ false, DUMP_FLAG_PRIORITY_CRITICAL);t.traceEnd();//SystemServerTiming: StartWindowManagerService took to complete: 73mst.traceBegin("SetWindowManagerService");//SystemServerTiming: SetWindowManagerService//创建屏幕设备对象mActivityManagerService.setWindowManager(wm);t.traceEnd();//SystemServerTiming: SetWindowManagerService took to complete: 72mst.traceBegin("WindowManagerServiceOnInitReady");//SystemServerTiming: WindowManagerServiceOnInitReadywm.onInitReady();t.traceEnd();//SystemServerTiming: WindowManagerServiceOnInitReady took to complete: 13ms ...代码省略...t.traceBegin("StartInputManager");//SystemServerTiming: StartInputManagerinputManager.setWindowManagerCallbacks(wm.getInputManagerCallback());inputManager.start();t.traceEnd();//SystemServerTiming: StartInputManager took to complete: 19mst.traceBegin("DisplayManagerWindowManagerAndInputReady");//SystemServerTiming: DisplayManagerWindowManagerAndInputReadymDisplayManagerService.windowManagerAndInputReady();t.traceEnd();//SystemServerTiming: DisplayManagerWindowManagerAndInputReady took to complete: 0msif (mFactoryTestMode == FactoryTest.FACTORY_TEST_LOW_LEVEL) {Slog.i(TAG, "No Bluetooth Service (factory test)");} else if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {Slog.i(TAG, "No Bluetooth Service (Bluetooth Hardware Not Present)");} else {t.traceBegin("StartBluetoothService");//SystemServerTiming: StartBluetoothService//蓝牙服务mSystemServiceManager.startService(BluetoothService.class);t.traceEnd();//SystemServerTiming: StartBluetoothService took to complete: 2ms} ...代码省略...t.traceBegin("MakeDisplayReady");//SystemServerTiming: MakeDisplayReadytry {wm.displayReady();} catch (Throwable e) {reportWtf("making display ready", e);}t.traceEnd(); //SystemServerTiming: MakeDisplayReady took to complete: 17msif (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) {if (!"0".equals(SystemProperties.get("system_init.startmountservice"))) {t.traceBegin("StartStorageManagerService");//SystemServerTiming: StartStorageManagerServicetry {/** NotificationManagerService is dependant on StorageManagerService,* (for media / usb notifications) so we must start StorageManagerService first.*/mSystemServiceManager.startService(STORAGE_MANAGER_SERVICE_CLASS);storageManager = IStorageManager.Stub.asInterface(ServiceManager.getService("mount"));} catch (Throwable e) {reportWtf("starting StorageManagerService", e);}t.traceEnd();//SystemServerTiming: StartStorageManagerService took to complete: 19mst.traceBegin("StartStorageStatsService");//SystemServerTiming: StartStorageStatsServicetry {mSystemServiceManager.startService(STORAGE_STATS_SERVICE_CLASS);} catch (Throwable e) {reportWtf("starting StorageStatsService", e);}t.traceEnd();//SystemServerTiming: StartStorageStatsService took to complete: 5ms}}...代码省略...t.traceBegin("StartUiModeManager");//SystemServerTiming: StartUiModeManager//UI Mode 模式管理mSystemServiceManager.startService(UiModeManagerService.class);t.traceEnd();//SystemServerTiming: StartUiModeManager took to complete: 2ms...代码省略...t.traceBegin("StartStatusBarManagerService");//SystemServerTiming: StartStatusBarManagerServicetry {statusBar = new StatusBarManagerService(context);//系统栏管理服务ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);} catch (Throwable e) {reportWtf("starting StatusBarManagerService", e);}t.traceEnd();//SystemServerTiming: StartStatusBarManagerService took to complete: 0ms...代码省略...t.traceBegin("StartNetworkManagementService");//SystemServerTiming: StartNetworkManagementServicetry {networkManagement = NetworkManagementService.create(context);ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement);} catch (Throwable e) {reportWtf("starting NetworkManagement Service", e);}t.traceEnd();//SystemServerTiming: StartNetworkManagementService took to complete: 4ms...代码省略...t.traceBegin("StartFontManagerService");//SystemServerTiming: StartFontManagerService//字体服务mSystemServiceManager.startService(new FontManagerService.Lifecycle(context, safeMode));t.traceEnd();//SystemServerTiming: StartFontManagerService took to complete: 111ms ...代码省略...t.traceBegin("StartNetworkPolicyManagerService");//SystemServerTiming: StartNetworkManagementServicetry {networkPolicy = new NetworkPolicyManagerService(context, mActivityManagerService,networkManagement);ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy);} catch (Throwable e) {reportWtf("starting NetworkPolicy Service", e);}t.traceEnd();//SystemServerTiming: StartNetworkManagementService took to complete: 4msif (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) {// Wifi Service must be started first for wifi-related services.t.traceBegin("StartWifi");//SystemServerTiming: StartWifi//WIFI服务mSystemServiceManager.startServiceFromJar(WIFI_SERVICE_CLASS, WIFI_APEX_SERVICE_JAR_PATH);t.traceEnd();//SystemServerTiming: StartWifi took to complete: 163mst.traceBegin("StartWifiScanning");//SystemServerTiming: StartWifiScanning//WIFI扫描服务mSystemServiceManager.startServiceFromJar(WIFI_SCANNING_SERVICE_CLASS, WIFI_APEX_SERVICE_JAR_PATH);t.traceEnd();//SystemServerTiming: StartWifiScanning took to complete: 13ms}if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI_RTT)) {t.traceBegin("StartRttService");//SystemServerTiming: StartRttService//RTT服务mSystemServiceManager.startServiceFromJar(WIFI_RTT_SERVICE_CLASS, WIFI_APEX_SERVICE_JAR_PATH);t.traceEnd();//SystemServerTiming: StartRttService took to complete: 1ms}if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI_DIRECT)) {t.traceBegin("StartWifiP2P");//SystemServerTiming: StartWifiP2P//P2P服务mSystemServiceManager.startServiceFromJar(WIFI_P2P_SERVICE_CLASS, WIFI_APEX_SERVICE_JAR_PATH);t.traceEnd();//SystemServerTiming: StartWifiP2P took to complete: 8ms}...代码省略...t.traceBegin("StartVpnManagerService");//SystemServerTiming: StartVpnManagerServicetry {vpnManager = VpnManagerService.create(context);ServiceManager.addService(Context.VPN_MANAGEMENT_SERVICE, vpnManager);} catch (Throwable e) {reportWtf("starting VPN Manager Service", e);}t.traceEnd();//SystemServerTiming: StartVpnManagerService took to complete: 3ms...代码省略...t.traceBegin("StartSystemUpdateManagerService");//SystemServerTiming: StartSystemUpdateManagerServicetry {ServiceManager.addService(Context.SYSTEM_UPDATE_SERVICE,new SystemUpdateManagerService(context));} catch (Throwable e) {reportWtf("starting SystemUpdateManagerService", e);}t.traceEnd();//SystemServerTiming: StartSystemUpdateManagerService took to complete: 1ms...代码省略...t.traceBegin("StartNotificationManager");//SystemServerTiming: StartNotificationManagermSystemServiceManager.startService(NotificationManagerService.class);SystemNotificationChannels.removeDeprecated(context);SystemNotificationChannels.createAll(context);notification = INotificationManager.Stub.asInterface(ServiceManager.getService(Context.NOTIFICATION_SERVICE));t.traceEnd();//SystemServerTiming: StartNotificationManager took to complete: 30mst.traceBegin("StartDeviceMonitor");//SystemServerTiming: StartDeviceMonitormSystemServiceManager.startService(DeviceStorageMonitorService.class);t.traceEnd();//SystemServerTiming: StartDeviceMonitor took to complete: 8mst.traceBegin("StartLocationManagerService");//SystemServerTiming: StartLocationManagerServicemSystemServiceManager.startService(LocationManagerService.Lifecycle.class);t.traceEnd();//SystemServerTiming: StartLocationManagerService took to complete: 3ms...代码省略...if (context.getResources().getBoolean(R.bool.config_enableWallpaperService)) {t.traceBegin("StartWallpaperManagerService");//SystemServerTiming: StartWallpaperManagerServicemSystemServiceManager.startService(WALLPAPER_SERVICE_CLASS);t.traceEnd();//SystemServerTiming: StartWallpaperManagerService took to complete: 2ms} else {Slog.i(TAG, "Wallpaper service disabled by config");}t.traceBegin("StartAudioService");//SystemServerTiming: StartAudioServiceif (!isArc) {mSystemServiceManager.startService(AudioService.Lifecycle.class);} else {String className = context.getResources().getString(R.string.config_deviceSpecificAudioService);try {mSystemServiceManager.startService(className + "$Lifecycle");} catch (Throwable e) {reportWtf("starting " + className, e);}}t.traceEnd();//SystemServerTiming: StartAudioService took to complete: 98ms...代码省略...t.traceBegin("StartAdbService");//SystemServerTiming: StartAdbServicetry {mSystemServiceManager.startService(ADB_SERVICE_CLASS);//开启ADB调试服务} catch (Throwable e) {Slog.e(TAG, "Failure starting AdbService");}t.traceEnd();//SystemServerTiming: StartAdbService took to complete: 1msif (mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST)|| mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY)|| isEmulator) {// Manage USB host and device supportt.traceBegin("StartUsbService");//SystemServerTiming: StartUsbServicemSystemServiceManager.startService(USB_SERVICE_CLASS);//开启USB服务t.traceEnd();//SystemServerTiming: StartUsbService took to complete: 1ms}...代码省略...t.traceBegin("StartClipboardService");//SystemServerTiming: StartClipboardService//剪切板服务mSystemServiceManager.startService(ClipboardService.class);t.traceEnd();//SystemServerTiming: StartClipboardService took to complete: 2mst.traceBegin("AppServiceManager");//SystemServerTiming: AppServiceManagermSystemServiceManager.startService(AppBindingService.Lifecycle.class);t.traceEnd();//SystemServerTiming: AppServiceManager took to complete: 0mst.traceBegin("startTracingServiceProxy");//SystemServerTiming: startTracingServiceProxymSystemServiceManager.startService(TracingServiceProxy.class);t.traceEnd();//SystemServerTiming: startTracingServiceProxy took to complete: 1ms...代码省略...t.traceBegin("MakeWindowManagerServiceReady");//SystemServerTiming: MakeWindowManagerServiceReadytry {wm.systemReady();} catch (Throwable e) {reportWtf("making Window Manager Service ready", e);}t.traceEnd();//SystemServerTiming: MakeWindowManagerServiceReady took to complete: 2ms...代码省略...final Configuration config = wm.computeNewConfiguration(DEFAULT_DISPLAY);DisplayMetrics metrics = new DisplayMetrics();context.getDisplay().getMetrics(metrics);context.getResources().updateConfiguration(config, metrics);// The system context's theme may be configuration-dependent.final Theme systemTheme = context.getTheme();if (systemTheme.getChangingConfigurations() != 0) {systemTheme.rebase();}t.traceBegin("MakePowerManagerServiceReady");//SystemServerTiming: MakePowerManagerServiceReadytry {// TODO: use boot phasemPowerManagerService.systemReady(mActivityManagerService.getAppOpsService());} catch (Throwable e) {reportWtf("making Power Manager Service ready", e);}t.traceEnd();//SystemServerTiming: MakePowerManagerServiceReady took to complete: 19ms//调用ActivityManagerService的systemReady方法mActivityManagerService.systemReady(() -> {Slog.i(TAG, "Making services ready");}t.traceBegin("StartSystemUI");//SystemServerTiming: StartSystemUItry {startSystemUi(context, windowManagerF);} catch (Throwable e) {reportWtf("starting System UI", e);}t.traceEnd();//SystemServerTiming: StartSystemUI took to complete: 10mst.traceEnd(); //SystemServerTiming: startOtherServices took to complete: 2362ms}
}