frameworks/base/core/java/com/android/internal/os/ZygoteInit.java文件中:
Step1、startSystemServer函数
- public class ZygoteInit {
- ......
- private static boolean startSystemServer()
- throws MethodAndArgsCaller, RuntimeException {
- /* Hardcoded command line to start the system server */
- String args[] = {
- "--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.Arguments parsedArgs = null;
- int pid;
- try {
- parsedArgs = new ZygoteConnection.Arguments(args);
- ......
- /* Request to fork the system server process */
- //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 (IllegalArgumentException ex) {
- ......
- }
- /* For child process */
- //新创建的子进程会执行handleSystemServerProcess函数。
- if (pid == 0) {
- handleSystemServerProcess(parsedArgs);
- }
- return true;
- }
- ......
- }
- public class ZygoteInit {
- ......
- private static void handleSystemServerProcess(
- ZygoteConnection.Arguments parsedArgs)
- throws ZygoteInit.MethodAndArgsCaller {
- //Zygote进程创建的子进程会继承Zygote进程创建的Socket文件描述符,而这里的子进程又不会用到它,因此,这里就调用closeServerSocket函数来关闭它。
- closeServerSocket();
- /*
- * Pass the remaining arguments to SystemServer.
- * "--nice-name=system_server com.android.server.SystemServer"
- */
- // 进一步执行启动SystemServer组件的操作
- RuntimeInit.zygoteInit(parsedArgs.remainingArgs);
- /* should never reach here */
- }
- ......
- }
函数定义在frameworks/base/core/java/com/android/internal/os/RuntimeInit.java文件中:
- public class RuntimeInit {
- ......
- public static final void zygoteInit(String[] argv)
- throws ZygoteInit.MethodAndArgsCaller {
- ......
- //执行一个Binder进程间通信机制的初始化工作,这个工作完成之后,这个进程中的Binder对象就可以方便地进行进程间通信了
- //函数zygoteInitNative是一个Native函数,实现在frameworks/base/core/jni/AndroidRuntime.cpp文件中,这里我们就不再细看了
- zygoteInitNative();
- ......
- //调用上面传进来的com.android.server.SystemServer类的main函数。
- // Remaining arguments are passed to the start class's static main
- String startClass = argv[curArg++];
- String[] startArgs = new String[argv.length - curArg];
- System.arraycopy(argv, curArg, startArgs, 0, startArgs.length);
- invokeStaticMain(startClass, startArgs);
- }
- ......
- }
这个函数定义在frameworks/base/services/java/com/android/server/SystemServer.java文件中:
- public class SystemServer
- {
- ......
- native public static void init1(String[] args);
- ......
- public static void main(String[] args) {
- ......
- init1(args);//首先会执行JNI方法init1,然后init1会调用这里的init2函数
- ......
- }
- public static final void init2() {
- Slog.i(TAG, "Entered the Android system server!");
- //创建一个ServerThread线程对象来执行一些系统关键服务的启动操作,
- //例如 PackageManagerService和ActivityManagerService
- Thread thr = new ServerThread();
- thr.setName("android.server.ServerThread");
- thr.start();
- }
- ......
- }
Step2 、 frameworks/base/services/jni/com_android_server_SystemServer.cpp文件中:
- namespace android {
- extern "C" int system_init();
- static void android_server_SystemServer_init1(JNIEnv* env, jobject clazz)
- {
- system_init();
- }
- /*
- * JNI registration.
- */
- static JNINativeMethod gMethods[] = {
- /* name, signature, funcPtr */
- { "init1", "([Ljava/lang/String;)V", (void*) android_server_SystemServer_init1 },
- };
- int register_android_server_SystemServer(JNIEnv* env)
- {
- return jniRegisterNativeMethods(env, "com/android/server/SystemServer",
- gMethods, NELEM(gMethods));
- }
- }; // namespace android
函数system_init实现在libsystem_server库中,源代码位于frameworks/base/cmds/system_server/library/system_init.cpp文件中:
- extern "C" status_t system_init()
- {
- LOGI("Entered system_init()");
- sp<ProcessState> proc(ProcessState::self());
- sp<IServiceManager> sm = defaultServiceManager();
- LOGI("ServiceManager: %p\n", sm.get());
- sp<GrimReaper> grim = new GrimReaper();
- sm->asBinder()->linkToDeath(grim, grim.get(), 0);
- char propBuf[PROPERTY_VALUE_MAX];
- property_get("system_init.startsurfaceflinger", propBuf, "1");
- if (strcmp(propBuf, "1") == 0) {
- // Start the SurfaceFlinger
- SurfaceFlinger::instantiate();
- }
- // Start the sensor service
- SensorService::instantiate();
- // On the simulator, audioflinger et al don't get started the
- // same way as on the device, and we need to start them here
- if (!proc->supportsProcesses()) {
- // Start the AudioFlinger
- AudioFlinger::instantiate();
- // Start the media playback service
- MediaPlayerService::instantiate();
- // Start the camera service
- CameraService::instantiate();
- // Start the audio policy service
- AudioPolicyService::instantiate();
- }
- // And now start the Android runtime. We have to do this bit
- // of nastiness because the Android runtime initialization requires
- // some of the core system services to already be started.
- // All other servers should just start the Android runtime at
- // the beginning of their processes's main(), before calling
- // the init function.
- LOGI("System server: starting Android runtime.\n");
- AndroidRuntime* runtime = AndroidRuntime::getRuntime();
- LOGI("System server: starting Android services.\n");
- runtime->callStatic("com/android/server/SystemServer", "init2");
- // If running in our own process, just go into the thread
- // pool. Otherwise, call the initialization finished
- // func to let this process continue its initilization.
- if (proc->supportsProcesses()) {
- LOGI("System server: entering thread pool.\n");
- ProcessState::self()->startThreadPool();
- IPCThreadState::self()->joinThreadPool();
- LOGI("System server: exiting thread pool.\n");
- }
- return NO_ERROR;
- }
这个函数定义在frameworks/base/core/jni/AndroidRuntime.cpp文件中:
- /*
- * Call a static Java Programming Language function that takes no arguments and returns void.
- */
- status_t AndroidRuntime::callStatic(const char* className, const char* methodName)
- {
- JNIEnv* env;
- jclass clazz;
- jmethodID methodId;
- env = getJNIEnv();
- if (env == NULL)
- return UNKNOWN_ERROR;
- clazz = findClass(env, className);
- if (clazz == NULL) {
- LOGE("ERROR: could not find class '%s'\n", className);
- return UNKNOWN_ERROR;
- }
- methodId = env->GetStaticMethodID(clazz, methodName, "()V");
- if (methodId == NULL) {
- LOGE("ERROR: could not find method %s.%s\n", className, methodName);
- return UNKNOWN_ERROR;
- }
- env->CallStaticVoidMethod(clazz, methodId);
- return NO_ERROR;
- }
Step3、
这个函数定义在frameworks/base/services/java/com/android/server/SystemServer.java文件中:
- class ServerThread extends Thread {
- private static final String TAG = "SystemServer";
- private final static boolean INCLUDE_DEMO = false;
- private static final int LOG_BOOT_PROGRESS_SYSTEM_RUN = 3010;
- private ContentResolver mContentResolver;
- private class AdbSettingsObserver extends ContentObserver {
- public AdbSettingsObserver() {
- super(null);
- }
- @Override
- public void onChange(boolean selfChange) {
- boolean enableAdb = (Settings.Secure.getInt(mContentResolver,
- Settings.Secure.ADB_ENABLED, 0) > 0);
- // setting this secure property will start or stop adbd
- SystemProperties.set("persist.service.adb.enable", enableAdb ? "1" : "0");
- }
- }
- @Override
- public void run() {
- 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);
- // Check whether we failed to shut down last time we tried.
- {
- final String shutdownAction = SystemProperties.get(
- ShutdownThread.SHUTDOWN_ACTION_PROPERTY, "");
- if (shutdownAction != null && shutdownAction.length() > 0) {
- boolean reboot = (shutdownAction.charAt(0) == '1');
- final String reason;
- if (shutdownAction.length() > 1) {
- reason = shutdownAction.substring(1, shutdownAction.length());
- } else {
- reason = null;
- }
- ShutdownThread.rebootOrShutdown(reboot, reason);
- }
- }
- String factoryTestStr = SystemProperties.get("ro.factorytest");
- int factoryTest = "".equals(factoryTestStr) ? SystemServer.FACTORY_TEST_OFF
- : Integer.parseInt(factoryTestStr);
- LightsService lights = null;
- PowerManagerService power = null;
- BatteryService battery = null;
- ConnectivityService connectivity = null;
- IPackageManager pm = null;
- Context context = null;
- WindowManagerService wm = null;
- BluetoothService bluetooth = null;
- BluetoothA2dpService bluetoothA2dp = null;
- HeadsetObserver headset = null;
- DockObserver dock = null;
- UsbService usb = null;
- UiModeManagerService uiMode = null;
- RecognitionManagerService recognition = null;
- ThrottleService throttle = null;
- // Critical services...
- try {
//EntropyService服务 - Slog.i(TAG, "Entropy Service");
- ServiceManager.addService("entropy", new EntropyService());
- //电源管理服务
- Slog.i(TAG, "Power Manager");
- power = new PowerManagerService();
- ServiceManager.addService(Context.POWER_SERVICE, power);
- //ActivityManagerService服务
- Slog.i(TAG, "Activity Manager");
- context = ActivityManagerService.main(factoryTest);
- //TelephonyRegistry服务
- Slog.i(TAG, "Telephony Registry");
- ServiceManager.addService("telephony.registry", new TelephonyRegistry(context));
- AttributeCache.init(context);
- //PackageManagerService包管理服务
- Slog.i(TAG, "Package Manager");
- pm = PackageManagerService.main(context,
- factoryTest != SystemServer.FACTORY_TEST_OFF);
- ActivityManagerService.setSystemProcess();
- //内容解决者
- mContentResolver = context.getContentResolver();
- //账号、密码、权限管理服务
- // The AccountManager must come before the ContentService
- try {
- Slog.i(TAG, "Account Manager");
- ServiceManager.addService(Context.ACCOUNT_SERVICE,
- new AccountManagerService(context));
- } catch (Throwable e) {
- Slog.e(TAG, "Failure starting Account Manager", e);
- }
- //内容服务
- Slog.i(TAG, "Content Manager");
- ContentService.main(context,
- factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL);
- //内容提供者
- Slog.i(TAG, "System Content Providers");
- ActivityManagerService.installSystemProviders();
- //电池服务
- Slog.i(TAG, "Battery Service");
- battery = new BatteryService(context);
- ServiceManager.addService("battery", battery);
- //亮屏服务
- Slog.i(TAG, "Lights Service");
- lights = new LightsService(context);
- //手机震动服务
- Slog.i(TAG, "Vibrator Service");
- ServiceManager.addService("vibrator", new VibratorService(context));
- //在开始亮屏服务、内容提供者服务、电池服务启动后,才初始化电源服务
- // only initialize the power service after we have started the
- // lights service, content providers and the battery service.
- power.init(context, lights, ActivityManagerService.getDefault(), battery);
- //闹钟服务
- Slog.i(TAG, "Alarm Manager");
- AlarmManagerService alarm = new AlarmManagerService(context);
- ServiceManager.addService(Context.ALARM_SERVICE, alarm);
- //初始化看门狗
- Slog.i(TAG, "Init Watchdog");
- Watchdog.getInstance().init(context, battery, power, alarm,
- ActivityManagerService.self());
- //窗口管理服务
- Slog.i(TAG, "Window Manager");
- wm = WindowManagerService.main(context, power,
- factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL);
- ServiceManager.addService(Context.WINDOW_SERVICE, wm);
- ((ActivityManagerService)ServiceManager.getService("activity"))
- .setWindowManager(wm);
- //蓝牙服务
- // Skip Bluetooth if we have an emulator kernel
- // TODO: Use a more reliable check to see if this product should
- // support Bluetooth - see bug 988521
- if (SystemProperties.get("ro.kernel.qemu").equals("1")) {
- Slog.i(TAG, "Registering null Bluetooth Service (emulator)");
- ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, null);
- } else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) {
- Slog.i(TAG, "Registering null Bluetooth Service (factory test)");
- ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, null);
- } else {
- Slog.i(TAG, "Bluetooth Service");
- bluetooth = new BluetoothService(context);
- ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, bluetooth);
- bluetooth.initAfterRegistration();
- bluetoothA2dp = new BluetoothA2dpService(context, bluetooth);
- ServiceManager.addService(BluetoothA2dpService.BLUETOOTH_A2DP_SERVICE,
- bluetoothA2dp);
- int bluetoothOn = Settings.Secure.getInt(mContentResolver,
- Settings.Secure.BLUETOOTH_ON, 0);
- if (bluetoothOn > 0) {
- bluetooth.enable();
- }
- }
- } catch (RuntimeException e) {
- Slog.e("System", "Failure starting core service", e);
- }
- DevicePolicyManagerService devicePolicy = null;
- StatusBarManagerService statusBar = null;
- InputMethodManagerService imm = null;
- AppWidgetService appWidget = null;
- NotificationManagerService notification = null;
- WallpaperManagerService wallpaper = null;
- LocationManagerService location = null;
- if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
- try {
- Slog.i(TAG, "Device Policy");
- devicePolicy = new DevicePolicyManagerService(context);
- ServiceManager.addService(Context.DEVICE_POLICY_SERVICE, devicePolicy);
- } catch (Throwable e) {
- Slog.e(TAG, "Failure starting DevicePolicyService", e);
- }
- try {
- Slog.i(TAG, "Status Bar");
- statusBar = new StatusBarManagerService(context);
- ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);
- } catch (Throwable e) {
- Slog.e(TAG, "Failure starting StatusBarManagerService", e);
- }
- try {
- Slog.i(TAG, "Clipboard Service");
- ServiceManager.addService(Context.CLIPBOARD_SERVICE,
- new ClipboardService(context));
- } catch (Throwable e) {
- Slog.e(TAG, "Failure starting Clipboard Service", e);
- }
- //输入法管理服务
- try {
- Slog.i(TAG, "Input Method Service");
- imm = new InputMethodManagerService(context, statusBar);
- ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm);
- } catch (Throwable e) {
- Slog.e(TAG, "Failure starting Input Manager Service", e);
- }
- //网络状态服务
- try {
- Slog.i(TAG, "NetStat Service");
- ServiceManager.addService("netstat", new NetStatService(context));
- } catch (Throwable e) {
- Slog.e(TAG, "Failure starting NetStat Service", e);
- }
- //网络管理服务
- try {
- Slog.i(TAG, "NetworkManagement Service");
- ServiceManager.addService(
- Context.NETWORKMANAGEMENT_SERVICE,
- NetworkManagementService.create(context));
- } catch (Throwable e) {
- Slog.e(TAG, "Failure starting NetworkManagement Service", e);
- }
- //网络连接服务
- try {
- Slog.i(TAG, "Connectivity Service");
- connectivity = ConnectivityService.getInstance(context);
- ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
- } catch (Throwable e) {
- Slog.e(TAG, "Failure starting Connectivity Service", e);
- }
- //节流阀控制,提高modem使用效率,避免数据过大或过小情况下不必要的重复连接和断开。
- try {
- Slog.i(TAG, "Throttle Service");
- throttle = new ThrottleService(context);
- ServiceManager.addService(
- Context.THROTTLE_SERVICE, throttle);
- } catch (Throwable e) {
- Slog.e(TAG, "Failure starting ThrottleService", e);
- }
- //可访问管理服务
- try {
- Slog.i(TAG, "Accessibility Manager");
- ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
- new AccessibilityManagerService(context));
- } catch (Throwable e) {
- Slog.e(TAG, "Failure starting Accessibility Manager", e);
- }
- //磁盘加载服务(sd卡等)
- try {
- /*
- * NotificationManagerService is dependant on MountService,
- * (for media / usb notifications) so we must start MountService first.
- */
- Slog.i(TAG, "Mount Service");
- ServiceManager.addService("mount", new MountService(context));
- } catch (Throwable e) {
- Slog.e(TAG, "Failure starting Mount Service", e);
- }
- //通知管理服务
- try {
- Slog.i(TAG, "Notification Manager");
- notification = new NotificationManagerService(context, statusBar, lights);
- ServiceManager.addService(Context.NOTIFICATION_SERVICE, notification);
- } catch (Throwable e) {
- Slog.e(TAG, "Failure starting Notification Manager", e);
- }
- //监控磁盘空间服务
- try {
- Slog.i(TAG, "Device Storage Monitor");
- ServiceManager.addService(DeviceStorageMonitorService.SERVICE,
- new DeviceStorageMonitorService(context));
- } catch (Throwable e) {
- Slog.e(TAG, "Failure starting DeviceStorageMonitor service", e);
- }
- //定位管理服务
- try {
- Slog.i(TAG, "Location Manager");
- location = new LocationManagerService(context);
- ServiceManager.addService(Context.LOCATION_SERVICE, location);
- } catch (Throwable e) {
- Slog.e(TAG, "Failure starting Location Manager", e);
- }
- //搜索管理服务
- try {
- Slog.i(TAG, "Search Service");
- ServiceManager.addService(Context.SEARCH_SERVICE,
- new SearchManagerService(context));
- } catch (Throwable e) {
- Slog.e(TAG, "Failure starting Search Service", e);
- }
- //开启守护进程
- if (INCLUDE_DEMO) {
- Slog.i(TAG, "Installing demo data...");
- (new DemoThread(context)).start();
- }
- //DropBoxManagerService用于生成和管理系统运行时的一些日志文件。这些日志文件大多记录的是系统或某个应用程序出错时的信息。
- try {
- Slog.i(TAG, "DropBox Service");
- ServiceManager.addService(Context.DROPBOX_SERVICE,
- new DropBoxManagerService(context, new File("/data/system/dropbox")));
- } catch (Throwable e) {
- Slog.e(TAG, "Failure starting DropBoxManagerService", e);
- }
- //壁纸管理服务
- try {
- Slog.i(TAG, "Wallpaper Service");
- wallpaper = new WallpaperManagerService(context);
- ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper);
- } catch (Throwable e) {
- Slog.e(TAG, "Failure starting Wallpaper Service", e);
- }
- //音频服务
- try {
- Slog.i(TAG, "Audio Service");
- ServiceManager.addService(Context.AUDIO_SERVICE, new AudioService(context));
- } catch (Throwable e) {
- Slog.e(TAG, "Failure starting Audio Service", e);
- }
- //HeadsetObserver耳机监听
- try {
- Slog.i(TAG, "Headset Observer");
- // Listen for wired headset changes
- headset = new HeadsetObserver(context);
- } catch (Throwable e) {
- Slog.e(TAG, "Failure starting HeadsetObserver", e);
- }
- //DockObserver手机亮度的监听
- try {
- Slog.i(TAG, "Dock Observer");
- // Listen for dock station changes
- dock = new DockObserver(context, power);
- } catch (Throwable e) {
- Slog.e(TAG, "Failure starting DockObserver", e);
- }
- //usb服务
- try {
- Slog.i(TAG, "USB Service");
- // Listen for USB changes
- usb = new UsbService(context);
- ServiceManager.addService(Context.USB_SERVICE, usb);
- } catch (Throwable e) {
- Slog.e(TAG, "Failure starting UsbService", e);
- }
- //ui模式管理服务
- try {
- Slog.i(TAG, "UI Mode Manager Service");
- // Listen for UI mode changes
- uiMode = new UiModeManagerService(context);
- } catch (Throwable e) {
- Slog.e(TAG, "Failure starting UiModeManagerService", e);
- }
- //备份管理服务
- try {
- Slog.i(TAG, "Backup Service");
- ServiceManager.addService(Context.BACKUP_SERVICE,
- new BackupManagerService(context));
- } catch (Throwable e) {
- Slog.e(TAG, "Failure starting Backup Service", e);
- }
- //appWidget服务
- try {
- Slog.i(TAG, "AppWidget Service");
- appWidget = new AppWidgetService(context);
- ServiceManager.addService(Context.APPWIDGET_SERVICE, appWidget);
- } catch (Throwable e) {
- Slog.e(TAG, "Failure starting AppWidget Service", e);
- }
- try {
- Slog.i(TAG, "Recognition Service");
- recognition = new RecognitionManagerService(context);
- } catch (Throwable e) {
- Slog.e(TAG, "Failure starting Recognition Service", e);
- }
- try {
- Slog.i(TAG, "DiskStats Service");
- ServiceManager.addService("diskstats", new DiskStatsService(context));
- } catch (Throwable e) {
- Slog.e(TAG, "Failure starting DiskStats Service", e);
- }
- }
- // make sure the ADB_ENABLED setting value matches the secure property value
- Settings.Secure.putInt(mContentResolver, Settings.Secure.ADB_ENABLED,
- "1".equals(SystemProperties.get("persist.service.adb.enable")) ? 1 : 0);
- // register observer to listen for settings changes
- mContentResolver.registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.ADB_ENABLED),
- false, new AdbSettingsObserver());
- // Before things start rolling, be sure we have decided whether
- // we are in safe mode.
- final boolean safeMode = wm.detectSafeMode();
- if (safeMode) {
- try {
- ActivityManagerNative.getDefault().enterSafeMode();
- // Post the safe mode state in the Zygote class
- Zygote.systemInSafeMode = true;
- // Disable the JIT for the system_server process
- VMRuntime.getRuntime().disableJitCompilation();
- } catch (RemoteException e) {
- }
- } else {
- // Enable the JIT for the system_server process
- VMRuntime.getRuntime().startJitCompilation();
- }
- // It is now time to start up the app processes...
- if (devicePolicy != null) {
- devicePolicy.systemReady();
- }
- if (notification != null) {
- notification.systemReady();
- }
- if (statusBar != null) {
- statusBar.systemReady();
- }
- wm.systemReady();
- power.systemReady();
- try {
- pm.systemReady();
- } catch (RemoteException e) {
- }
- // These are needed to propagate to the runnable below.
- final StatusBarManagerService statusBarF = statusBar;
- final BatteryService batteryF = battery;
- final ConnectivityService connectivityF = connectivity;
- final DockObserver dockF = dock;
- final UsbService usbF = usb;
- final ThrottleService throttleF = throttle;
- final UiModeManagerService uiModeF = uiMode;
- final AppWidgetService appWidgetF = appWidget;
- final WallpaperManagerService wallpaperF = wallpaper;
- final InputMethodManagerService immF = imm;
- final RecognitionManagerService recognitionF = recognition;
- final LocationManagerService locationF = location;
- // We now tell the activity manager it is okay to run third party
- // code. It will call back into us once it has gotten to the state
- // where third party code can really run (but before it has actually
- // started launching the initial applications), for us to complete our
- // initialization.
- ((ActivityManagerService)ActivityManagerNative.getDefault())
- .systemReady(new Runnable() {
- public void run() {
- Slog.i(TAG, "Making services ready");
- 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();
- // It is now okay to let the various system services start their
- // third party code...
- 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();
- }
- });
- // For debug builds, log event loop stalls to dropbox for analysis.
- if (StrictMode.conditionallyEnableDebugLogging()) {
- Slog.i(TAG, "Enabled StrictMode for system server main thread.");
- }
- Looper.loop();
- Slog.d(TAG, "System ServerThread is exiting!");
- }
- }
这个函数除了启动了很多系统服务,自己慢慢研究