Android系统在启动的过程中,会启动一个应用程序管理服务PackageManagerService,这个服务负 责扫描系统中特定的目录,找到里面的应用程序文件,即以Apk为后缀的文件,然后对这些文件进解析, 得到应用程序的相关信息,完成m_init 函数来进一步执行操作。 Step 3. 函数system_init实现在libsystem_server库中,源代码位于 frameworks/base/cmds/system_server/library/ 文件中: view plain 1・ extern "C" status_t system_init() { LOGI("Entered system_init()"); 4・ 5・ sp<ProcessState> proc(ProcessState::self()); 6. 7・ sp<IServiceManager> sm = defaultServiceManager(); LOGI("ServiceManager: %p\n", ()); 9. 10. sp<GrimReaper> grim = new GrimReaper(); 11. sm->asBinder()->linkToDeath(grim, grim・get(), 0); 12. 13. char propBuf[PROPERTY_VALUE_MAX]; 14. property_get("", propBuf, "1"); 15. if (strcmp(propBuf, "1") == 0) { 16. // Start the SurfaceFlinger 17. SurfaceFlinger::instantiate(); 18. } 19. 20. // Start the sensor service 21. SensorService::instantiate(); 22. 23. // On the simulator, audioflinger et al don't get started the 24. // same way as on the device, and we need to start them here 25. if (!proc->supportsProcesses()) { 26. 27. // Start the AudioFlinger 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 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 = AndroidRu