Android系统SystemServer进程启动过程源码分析
16lz
2021-01-23
frameworks/base/core/java/com/android/internal/os/ZygoteInit.java文件中:
Step1、startSystemServer函数
[java] view plain copy
- publicclassZygoteInit{
- ......
- privatestaticbooleanstartSystemServer()
- throwsMethodAndArgsCaller,RuntimeException{
- /*Hardcodedcommandlinetostartthesystemserver*/
- Stringargs[]={
- "--setuid=1000",
- "--setgid=1000",
- "--setgroups=1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,1018,3001,3002,3003",
- "--capabilities=130104352,130104352",
- "--runtime-init",
- "--nice-name=system_server",
- "com.android.server.SystemServer",
- };
- ZygoteConnection.ArgumentsparsedArgs=null;
- intpid;
- try{
- parsedArgs=newZygoteConnection.Arguments(args);
- ......
- /*Requesttoforkthesystemserverprocess*/
- //startSystemServer()调用Zygote的native方法 forkSystemServer(),java端的Zygote的准备工作就结束了,接下来就交给C/C++端的Zygote来执行fork任务了,在/dalvik/vm/native/dalvik_system_Zygote.c 中,Dalvik_dalvik_system_Zygote_forkSystemServer函数中(自己去看源码)
- 这个里面的fork进程主要是使用linux的fork进程
- //Zygote进程通过Zygote.forkSystemServer函数来创建一个新的进程来启动SystemServer组件
- pid=Zygote.forkSystemServer(
- parsedArgs.uid,parsedArgs.gid,
- parsedArgs.gids,debugFlags,null,
- parsedArgs.permittedCapabilities,
- parsedArgs.effectiveCapabilities);
- }catch(IllegalArgumentExceptionex){
- ......
- }
- /*Forchildprocess*/
- //新创建的子进程会执行handleSystemServerProcess函数。
- if(pid==0){
- handleSystemServerProcess(parsedArgs);
- }
- returntrue;
- }
- ......
- }
- publicclassZygoteInit{
- ......
- privatestaticvoidhandleSystemServerProcess(
- ZygoteConnection.ArgumentsparsedArgs)
- throwsZygoteInit.MethodAndArgsCaller{
-
- //Zygote进程创建的子进程会继承Zygote进程创建的Socket文件描述符,而这里的子进程又不会用到它,因此,这里就调用closeServerSocket函数来关闭它。
- closeServerSocket();
- /*
- *PasstheremainingargumentstoSystemServer.
- *"--nice-name=system_servercom.android.server.SystemServer"
- */
- //进一步执行启动SystemServer组件的操作
- RuntimeInit.zygoteInit(parsedArgs.remainingArgs);
- /*shouldneverreachhere*/
- }
- ......
- }
函数定义在frameworks/base/core/java/com/android/internal/os/RuntimeInit.java文件中:
[java] view plain copy
- publicclassRuntimeInit{
- ......
- publicstaticfinalvoidzygoteInit(String[]argv)
- throwsZygoteInit.MethodAndArgsCaller{
- ......
- //执行一个Binder进程间通信机制的初始化工作,这个工作完成之后,这个进程中的Binder对象就可以方便地进行进程间通信了
- //函数zygoteInitNative是一个Native函数,实现在frameworks/base/core/jni/AndroidRuntime.cpp文件中,这里我们就不再细看了
- zygoteInitNative();
- ......
- //调用上面传进来的com.android.server.SystemServer类的main函数。
- //Remainingargumentsarepassedtothestartclass'sstaticmain
- StringstartClass=argv[curArg++];
- String[]startArgs=newString[argv.length-curArg];
- System.arraycopy(argv,curArg,startArgs,0,startArgs.length);
- invokeStaticMain(startClass,startArgs);
- }
- ......
- }
这个函数定义在frameworks/base/services/java/com/android/server/SystemServer.java文件中:
[java] view plain copy
- publicclassSystemServer
- {
- ......
- nativepublicstaticvoidinit1(String[]args);
- ......
- publicstaticvoidmain(String[]args){
- ......
- init1(args);//首先会执行JNI方法init1,然后init1会调用这里的init2函数
- ......
- }
- publicstaticfinalvoidinit2(){
- Slog.i(TAG,"EnteredtheAndroidsystemserver!");
- //创建一个ServerThread线程对象来执行一些系统关键服务的启动操作,
- //例如PackageManagerService和ActivityManagerService
- Threadthr=newServerThread();
- thr.setName("android.server.ServerThread");
- thr.start();
- }
- ......
- }
Step2 、 frameworks/base/services/jni/com_android_server_SystemServer.cpp文件中:
[cpp] view plain copy
- namespaceandroid{
- extern"C"intsystem_init();
- staticvoidandroid_server_SystemServer_init1(JNIEnv*env,jobjectclazz)
- {
- system_init();
- }
- /*
- *JNIregistration.
- */
- staticJNINativeMethodgMethods[]={
- /*name,signature,funcPtr*/
- {"init1","([Ljava/lang/String;)V",(void*)android_server_SystemServer_init1},
- };
- intregister_android_server_SystemServer(JNIEnv*env)
- {
- returnjniRegisterNativeMethods(env,"com/android/server/SystemServer",
- gMethods,NELEM(gMethods));
- }
- };//namespaceandroid
函数system_init实现在libsystem_server库中,源代码位于frameworks/base/cmds/system_server/library/system_init.cpp文件中:
[cpp] view plain copy
- extern"C"status_tsystem_init()
- {
- LOGI("Enteredsystem_init()");
- sp<ProcessState>proc(ProcessState::self());
- sp<IServiceManager>sm=defaultServiceManager();
- LOGI("ServiceManager:%p\n",sm.get());
- sp<GrimReaper>grim=newGrimReaper();
- sm->asBinder()->linkToDeath(grim,grim.get(),0);
- charpropBuf[PROPERTY_VALUE_MAX];
- property_get("system_init.startsurfaceflinger",propBuf,"1");
- if(strcmp(propBuf,"1")==0){
- //StarttheSurfaceFlinger
- SurfaceFlinger::instantiate();
- }
- //Startthesensorservice
- SensorService::instantiate();
- //Onthesimulator,audioflingeretaldon'tgetstartedthe
- //samewayasonthedevice,andweneedtostartthemhere
- if(!proc->supportsProcesses()){
- //StarttheAudioFlinger
- AudioFlinger::instantiate();
- //Startthemediaplaybackservice
- MediaPlayerService::instantiate();
- //Startthecameraservice
- CameraService::instantiate();
- //Starttheaudiopolicyservice
- AudioPolicyService::instantiate();
- }
- //AndnowstarttheAndroidruntime.Wehavetodothisbit
- //ofnastinessbecausetheAndroidruntimeinitializationrequires
- //someofthecoresystemservicestoalreadybestarted.
- //AllotherserversshouldjuststarttheAndroidruntimeat
- //thebeginningoftheirprocesses'smain(),beforecalling
- //theinitfunction.
- LOGI("Systemserver:startingAndroidruntime.\n");
- AndroidRuntime*runtime=AndroidRuntime::getRuntime();
- LOGI("Systemserver:startingAndroidservices.\n");
- runtime->callStatic("com/android/server/SystemServer","init2");
- //Ifrunninginourownprocess,justgointothethread
- //pool.Otherwise,calltheinitializationfinished
- //functoletthisprocesscontinueitsinitilization.
- if(proc->supportsProcesses()){
- LOGI("Systemserver:enteringthreadpool.\n");
- ProcessState::self()->startThreadPool();
- IPCThreadState::self()->joinThreadPool();
- LOGI("Systemserver:exitingthreadpool.\n");
- }
- returnNO_ERROR;
- }
这个函数定义在frameworks/base/core/jni/AndroidRuntime.cpp文件中:
[cpp] view plain copy
- /*
- *CallastaticJavaProgrammingLanguagefunctionthattakesnoargumentsandreturnsvoid.
- */
- status_tAndroidRuntime::callStatic(constchar*className,constchar*methodName)
- {
- JNIEnv*env;
- jclassclazz;
- jmethodIDmethodId;
- env=getJNIEnv();
- if(env==NULL)
- returnUNKNOWN_ERROR;
- clazz=findClass(env,className);
- if(clazz==NULL){
- LOGE("ERROR:couldnotfindclass'%s'\n",className);
- returnUNKNOWN_ERROR;
- }
- methodId=env->GetStaticMethodID(clazz,methodName,"()V");
- if(methodId==NULL){
- LOGE("ERROR:couldnotfindmethod%s.%s\n",className,methodName);
- returnUNKNOWN_ERROR;
- }
- env->CallStaticVoidMethod(clazz,methodId);
- returnNO_ERROR;
- }
Step3、
这个函数定义在frameworks/base/services/java/com/android/server/SystemServer.java文件中:
[java] view plain copy
- classServerThreadextendsThread{
- privatestaticfinalStringTAG="SystemServer";
- privatefinalstaticbooleanINCLUDE_DEMO=false;
- privatestaticfinalintLOG_BOOT_PROGRESS_SYSTEM_RUN=3010;
- privateContentResolvermContentResolver;
- privateclassAdbSettingsObserverextendsContentObserver{
- publicAdbSettingsObserver(){
- super(null);
- }
- @Override
- publicvoidonChange(booleanselfChange){
- booleanenableAdb=(Settings.Secure.getInt(mContentResolver,
- Settings.Secure.ADB_ENABLED,0)>0);
- //settingthissecurepropertywillstartorstopadbd
- SystemProperties.set("persist.service.adb.enable",enableAdb?"1":"0");
- }
- }
- @Override
- publicvoidrun(){
- EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN,
- SystemClock.uptimeMillis());
- Looper.prepare();
- android.os.Process.setThreadPriority(
- android.os.Process.THREAD_PRIORITY_FOREGROUND);
- BinderInternal.disableBackgroundScheduling(true);
- android.os.Process.setCanSelfBackground(false);
- //Checkwhetherwefailedtoshutdownlasttimewetried.
- {
- finalStringshutdownAction=SystemProperties.get(
- ShutdownThread.SHUTDOWN_ACTION_PROPERTY,"");
- if(shutdownAction!=null&&shutdownAction.length()>0){
- booleanreboot=(shutdownAction.charAt(0)=='1');
- finalStringreason;
- if(shutdownAction.length()>1){
- reason=shutdownAction.substring(1,shutdownAction.length());
- }else{
- reason=null;
- }
- ShutdownThread.rebootOrShutdown(reboot,reason);
- }
- }
- StringfactoryTestStr=SystemProperties.get("ro.factorytest");
- intfactoryTest="".equals(factoryTestStr)?SystemServer.FACTORY_TEST_OFF
- :Integer.parseInt(factoryTestStr);
- LightsServicelights=null;
- PowerManagerServicepower=null;
- BatteryServicebattery=null;
- ConnectivityServiceconnectivity=null;
- IPackageManagerpm=null;
- Contextcontext=null;
- WindowManagerServicewm=null;
- BluetoothServicebluetooth=null;
- BluetoothA2dpServicebluetoothA2dp=null;
- HeadsetObserverheadset=null;
- DockObserverdock=null;
- UsbServiceusb=null;
- UiModeManagerServiceuiMode=null;
- RecognitionManagerServicerecognition=null;
- ThrottleServicethrottle=null;
- //Criticalservices...
- try{
//EntropyService服务
- Slog.i(TAG,"EntropyService");
- ServiceManager.addService("entropy",newEntropyService());
- //电源管理服务
- Slog.i(TAG,"PowerManager");
- power=newPowerManagerService();
- ServiceManager.addService(Context.POWER_SERVICE,power);
- //ActivityManagerService服务
- Slog.i(TAG,"ActivityManager");
- context=ActivityManagerService.main(factoryTest);
-
- //TelephonyRegistry服务
- Slog.i(TAG,"TelephonyRegistry");
- ServiceManager.addService("telephony.registry",newTelephonyRegistry(context));
- AttributeCache.init(context);
- //PackageManagerService包管理服务
- Slog.i(TAG,"PackageManager");
- pm=PackageManagerService.main(context,
- factoryTest!=SystemServer.FACTORY_TEST_OFF);
- ActivityManagerService.setSystemProcess();
- //内容解决者
- mContentResolver=context.getContentResolver();
-
- //账号、密码、权限管理服务
- //TheAccountManagermustcomebeforetheContentService
- try{
- Slog.i(TAG,"AccountManager");
- ServiceManager.addService(Context.ACCOUNT_SERVICE,
- newAccountManagerService(context));
- }catch(Throwablee){
- Slog.e(TAG,"FailurestartingAccountManager",e);
- }
- //内容服务
- Slog.i(TAG,"ContentManager");
- ContentService.main(context,
- factoryTest==SystemServer.FACTORY_TEST_LOW_LEVEL);
-
- //内容提供者
- Slog.i(TAG,"SystemContentProviders");
- ActivityManagerService.installSystemProviders();
- //电池服务
- Slog.i(TAG,"BatteryService");
- battery=newBatteryService(context);
- ServiceManager.addService("battery",battery);
- //亮屏服务
- Slog.i(TAG,"LightsService");
- lights=newLightsService(context);
- //手机震动服务
- Slog.i(TAG,"VibratorService");
- ServiceManager.addService("vibrator",newVibratorService(context));
- //在开始亮屏服务、内容提供者服务、电池服务启动后,才初始化电源服务
- //onlyinitializethepowerserviceafterwehavestartedthe
- //lightsservice,contentprovidersandthebatteryservice.
- power.init(context,lights,ActivityManagerService.getDefault(),battery);
- //闹钟服务
- Slog.i(TAG,"AlarmManager");
- AlarmManagerServicealarm=newAlarmManagerService(context);
- ServiceManager.addService(Context.ALARM_SERVICE,alarm);
- //初始化看门狗
- Slog.i(TAG,"InitWatchdog");
- Watchdog.getInstance().init(context,battery,power,alarm,
- ActivityManagerService.self());
- //窗口管理服务
- Slog.i(TAG,"WindowManager");
- wm=WindowManagerService.main(context,power,
- factoryTest!=SystemServer.FACTORY_TEST_LOW_LEVEL);
- ServiceManager.addService(Context.WINDOW_SERVICE,wm);
- ((ActivityManagerService)ServiceManager.getService("activity"))
- .setWindowManager(wm);
-
- //蓝牙服务
- //SkipBluetoothifwehaveanemulatorkernel
- //TODO:Useamorereliablechecktoseeifthisproductshould
- //supportBluetooth-seebug988521
- if(SystemProperties.get("ro.kernel.qemu").equals("1")){
- Slog.i(TAG,"RegisteringnullBluetoothService(emulator)");
- ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE,null);
- }elseif(factoryTest==SystemServer.FACTORY_TEST_LOW_LEVEL){
- Slog.i(TAG,"RegisteringnullBluetoothService(factorytest)");
- ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE,null);
- }else{
- Slog.i(TAG,"BluetoothService");
- bluetooth=newBluetoothService(context);
- ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE,bluetooth);
- bluetooth.initAfterRegistration();
- bluetoothA2dp=newBluetoothA2dpService(context,bluetooth);
- ServiceManager.addService(BluetoothA2dpService.BLUETOOTH_A2DP_SERVICE,
- bluetoothA2dp);
- intbluetoothOn=Settings.Secure.getInt(mContentResolver,
- Settings.Secure.BLUETOOTH_ON,0);
- if(bluetoothOn>0){
- bluetooth.enable();
- }
- }
- }catch(RuntimeExceptione){
- Slog.e("System","Failurestartingcoreservice",e);
- }
- DevicePolicyManagerServicedevicePolicy=null;
- StatusBarManagerServicestatusBar=null;
- InputMethodManagerServiceimm=null;
- AppWidgetServiceappWidget=null;
- NotificationManagerServicenotification=null;
- WallpaperManagerServicewallpaper=null;
- LocationManagerServicelocation=null;
- if(factoryTest!=SystemServer.FACTORY_TEST_LOW_LEVEL){
- try{
- Slog.i(TAG,"DevicePolicy");
- devicePolicy=newDevicePolicyManagerService(context);
- ServiceManager.addService(Context.DEVICE_POLICY_SERVICE,devicePolicy);
- }catch(Throwablee){
- Slog.e(TAG,"FailurestartingDevicePolicyService",e);
- }
- try{
- Slog.i(TAG,"StatusBar");
- statusBar=newStatusBarManagerService(context);
- ServiceManager.addService(Context.STATUS_BAR_SERVICE,statusBar);
- }catch(Throwablee){
- Slog.e(TAG,"FailurestartingStatusBarManagerService",e);
- }
- try{
- Slog.i(TAG,"ClipboardService");
- ServiceManager.addService(Context.CLIPBOARD_SERVICE,
- newClipboardService(context));
- }catch(Throwablee){
- Slog.e(TAG,"FailurestartingClipboardService",e);
- }
- //输入法管理服务
- try{
- Slog.i(TAG,"InputMethodService");
- imm=newInputMethodManagerService(context,statusBar);
- ServiceManager.addService(Context.INPUT_METHOD_SERVICE,imm);
- }catch(Throwablee){
- Slog.e(TAG,"FailurestartingInputManagerService",e);
- }
- //网络状态服务
- try{
- Slog.i(TAG,"NetStatService");
- ServiceManager.addService("netstat",newNetStatService(context));
- }catch(Throwablee){
- Slog.e(TAG,"FailurestartingNetStatService",e);
- }
- //网络管理服务
- try{
- Slog.i(TAG,"NetworkManagementService");
- ServiceManager.addService(
- Context.NETWORKMANAGEMENT_SERVICE,
- NetworkManagementService.create(context));
- }catch(Throwablee){
- Slog.e(TAG,"FailurestartingNetworkManagementService",e);
- }
- //网络连接服务
- try{
- Slog.i(TAG,"ConnectivityService");
- connectivity=ConnectivityService.getInstance(context);
- ServiceManager.addService(Context.CONNECTIVITY_SERVICE,connectivity);
- }catch(Throwablee){
- Slog.e(TAG,"FailurestartingConnectivityService",e);
- }
- //节流阀控制,提高modem使用效率,避免数据过大或过小情况下不必要的重复连接和断开。
- try{
- Slog.i(TAG,"ThrottleService");
- throttle=newThrottleService(context);
- ServiceManager.addService(
- Context.THROTTLE_SERVICE,throttle);
- }catch(Throwablee){
- Slog.e(TAG,"FailurestartingThrottleService",e);
- }
-
- //可访问管理服务
- try{
- Slog.i(TAG,"AccessibilityManager");
- ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
- newAccessibilityManagerService(context));
- }catch(Throwablee){
- Slog.e(TAG,"FailurestartingAccessibilityManager",e);
- }
- //磁盘加载服务(sd卡等)
- try{
- /*
- *NotificationManagerServiceisdependantonMountService,
- *(formedia/usbnotifications)sowemuststartMountServicefirst.
- */
- Slog.i(TAG,"MountService");
- ServiceManager.addService("mount",newMountService(context));
- }catch(Throwablee){
- Slog.e(TAG,"FailurestartingMountService",e);
- }
- //通知管理服务
- try{
- Slog.i(TAG,"NotificationManager");
- notification=newNotificationManagerService(context,statusBar,lights);
- ServiceManager.addService(Context.NOTIFICATION_SERVICE,notification);
- }catch(Throwablee){
- Slog.e(TAG,"FailurestartingNotificationManager",e);
- }
- //监控磁盘空间服务
- try{
- Slog.i(TAG,"DeviceStorageMonitor");
- ServiceManager.addService(DeviceStorageMonitorService.SERVICE,
- newDeviceStorageMonitorService(context));
- }catch(Throwablee){
- Slog.e(TAG,"FailurestartingDeviceStorageMonitorservice",e);
- }
- //定位管理服务
- try{
- Slog.i(TAG,"LocationManager");
- location=newLocationManagerService(context);
- ServiceManager.addService(Context.LOCATION_SERVICE,location);
- }catch(Throwablee){
- Slog.e(TAG,"FailurestartingLocationManager",e);
- }
- //搜索管理服务
- try{
- Slog.i(TAG,"SearchService");
- ServiceManager.addService(Context.SEARCH_SERVICE,
- newSearchManagerService(context));
- }catch(Throwablee){
- Slog.e(TAG,"FailurestartingSearchService",e);
- }
- //开启守护进程
- if(INCLUDE_DEMO){
- Slog.i(TAG,"Installingdemodata...");
- (newDemoThread(context)).start();
- }
- //DropBoxManagerService用于生成和管理系统运行时的一些日志文件。这些日志文件大多记录的是系统或某个应用程序出错时的信息。
- try{
- Slog.i(TAG,"DropBoxService");
- ServiceManager.addService(Context.DROPBOX_SERVICE,
- newDropBoxManagerService(context,newFile("/data/system/dropbox")));
- }catch(Throwablee){
- Slog.e(TAG,"FailurestartingDropBoxManagerService",e);
- }
- //壁纸管理服务
- try{
- Slog.i(TAG,"WallpaperService");
- wallpaper=newWallpaperManagerService(context);
- ServiceManager.addService(Context.WALLPAPER_SERVICE,wallpaper);
- }catch(Throwablee){
- Slog.e(TAG,"FailurestartingWallpaperService",e);
- }
- //音频服务
- try{
- Slog.i(TAG,"AudioService");
- ServiceManager.addService(Context.AUDIO_SERVICE,newAudioService(context));
- }catch(Throwablee){
- Slog.e(TAG,"FailurestartingAudioService",e);
- }
-
- //HeadsetObserver耳机监听
- try{
- Slog.i(TAG,"HeadsetObserver");
- //Listenforwiredheadsetchanges
- headset=newHeadsetObserver(context);
- }catch(Throwablee){
- Slog.e(TAG,"FailurestartingHeadsetObserver",e);
- }
-
- //DockObserver手机亮度的监听
- try{
- Slog.i(TAG,"DockObserver");
- //Listenfordockstationchanges
- dock=newDockObserver(context,power);
- }catch(Throwablee){
- Slog.e(TAG,"FailurestartingDockObserver",e);
- }
- //usb服务
- try{
- Slog.i(TAG,"USBService");
- //ListenforUSBchanges
- usb=newUsbService(context);
- ServiceManager.addService(Context.USB_SERVICE,usb);
- }catch(Throwablee){
- Slog.e(TAG,"FailurestartingUsbService",e);
- }
- //ui模式管理服务
- try{
- Slog.i(TAG,"UIModeManagerService");
- //ListenforUImodechanges
- uiMode=newUiModeManagerService(context);
- }catch(Throwablee){
- Slog.e(TAG,"FailurestartingUiModeManagerService",e);
- }
-
- //备份管理服务
- try{
- Slog.i(TAG,"BackupService");
- ServiceManager.addService(Context.BACKUP_SERVICE,
- newBackupManagerService(context));
- }catch(Throwablee){
- Slog.e(TAG,"FailurestartingBackupService",e);
- }
- //appWidget服务
- try{
- Slog.i(TAG,"AppWidgetService");
- appWidget=newAppWidgetService(context);
- ServiceManager.addService(Context.APPWIDGET_SERVICE,appWidget);
- }catch(Throwablee){
- Slog.e(TAG,"FailurestartingAppWidgetService",e);
- }
- try{
- Slog.i(TAG,"RecognitionService");
- recognition=newRecognitionManagerService(context);
- }catch(Throwablee){
- Slog.e(TAG,"FailurestartingRecognitionService",e);
- }
- try{
- Slog.i(TAG,"DiskStatsService");
- ServiceManager.addService("diskstats",newDiskStatsService(context));
- }catch(Throwablee){
- Slog.e(TAG,"FailurestartingDiskStatsService",e);
- }
- }
- //makesuretheADB_ENABLEDsettingvaluematchesthesecurepropertyvalue
- Settings.Secure.putInt(mContentResolver,Settings.Secure.ADB_ENABLED,
- "1".equals(SystemProperties.get("persist.service.adb.enable"))?1:0);
- //registerobservertolistenforsettingschanges
- mContentResolver.registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.ADB_ENABLED),
- false,newAdbSettingsObserver());
- //Beforethingsstartrolling,besurewehavedecidedwhether
- //weareinsafemode.
- finalbooleansafeMode=wm.detectSafeMode();
- if(safeMode){
- try{
- ActivityManagerNative.getDefault().enterSafeMode();
- //PostthesafemodestateintheZygoteclass
- Zygote.systemInSafeMode=true;
- //DisabletheJITforthesystem_serverprocess
- VMRuntime.getRuntime().disableJitCompilation();
- }catch(RemoteExceptione){
- }
- }else{
- //EnabletheJITforthesystem_serverprocess
- VMRuntime.getRuntime().startJitCompilation();
- }
- //Itisnowtimetostartuptheappprocesses...
- if(devicePolicy!=null){
- devicePolicy.systemReady();
- }
- if(notification!=null){
- notification.systemReady();
- }
- if(statusBar!=null){
- statusBar.systemReady();
- }
- wm.systemReady();
- power.systemReady();
- try{
- pm.systemReady();
- }catch(RemoteExceptione){
- }
- //Theseareneededtopropagatetotherunnablebelow.
- finalStatusBarManagerServicestatusBarF=statusBar;
- finalBatteryServicebatteryF=battery;
- finalConnectivityServiceconnectivityF=connectivity;
- finalDockObserverdockF=dock;
- finalUsbServiceusbF=usb;
- finalThrottleServicethrottleF=throttle;
- finalUiModeManagerServiceuiModeF=uiMode;
- finalAppWidgetServiceappWidgetF=appWidget;
- finalWallpaperManagerServicewallpaperF=wallpaper;
- finalInputMethodManagerServiceimmF=imm;
- finalRecognitionManagerServicerecognitionF=recognition;
- finalLocationManagerServicelocationF=location;
- //Wenowtelltheactivitymanageritisokaytorunthirdparty
- //code.Itwillcallbackintousonceithasgottentothestate
- //wherethirdpartycodecanreallyrun(butbeforeithasactually
- //startedlaunchingtheinitialapplications),forustocompleteour
- //initialization.
- ((ActivityManagerService)ActivityManagerNative.getDefault())
- .systemReady(newRunnable(){
- publicvoidrun(){
- Slog.i(TAG,"Makingservicesready");
- if(statusBarF!=null)statusBarF.systemReady2();
- if(batteryF!=null)batteryF.systemReady();
- if(connectivityF!=null)connectivityF.systemReady();
- if(dockF!=null)dockF.systemReady();
- if(usbF!=null)usbF.systemReady();
- if(uiModeF!=null)uiModeF.systemReady();
- if(recognitionF!=null)recognitionF.systemReady();
- Watchdog.getInstance().start();
- //Itisnowokaytoletthevarioussystemservicesstarttheir
- //thirdpartycode...
- if(appWidgetF!=null)appWidgetF.systemReady(safeMode);
- if(wallpaperF!=null)wallpaperF.systemReady();
- if(immF!=null)immF.systemReady();
- if(locationF!=null)locationF.systemReady();
- if(throttleF!=null)throttleF.systemReady();
- }
- });
- //Fordebugbuilds,logeventloopstallstodropboxforanalysis.
- if(StrictMode.conditionallyEnableDebugLogging()){
- Slog.i(TAG,"EnabledStrictModeforsystemservermainthread.");
- }
- Looper.loop();
- Slog.d(TAG,"SystemServerThreadisexiting!");
- }
- }
这个函数除了启动了很多系统服务,自己慢慢研究
更多相关文章
- Android Service 中 onStartCommand()函数返回值含义
- android使用sharedPreferences()方法读写文件操作
- 在系统里设置文件默认打开APP
- Android实现屏幕截图并保存截图到指定文件
- Android 中读取SD卡文件时抛出NullPointerException错误解决办法
- Android media媒体库分析之:分类别统计媒体文件大小