1 /* 2 * System server main initialization. 3 * 4 * The system server is responsible for becoming the Binder 5 * context manager, supplying the root ServiceManager object 6 * through which other services can be found. 7 */ 8 9 #define LOG_TAG "sysproc" 10 11 #include <binder/IPCThreadState.h> 12 #include <binder/ProcessState.h> 13 #include <binder/IServiceManager.h> 14 #include <utils/TextOutput.h> 15 #include <utils/Log.h> 16 17 #include <SurfaceFlinger.h> 18 #include <AudioFlinger.h> 19 #include <CameraService.h> 20 #include <AudioPolicyService.h> 21 #include <MediaPlayerService.h> 22 23 #include <android_runtime/AndroidRuntime.h> 24 25 #include <signal.h> 26 #include <stdlib.h> 27 #include <stdio.h> 28 #include <unistd.h> 29 #include <sys/time.h> 30 #include <cutils/properties.h> 31 32 using namespace android; 33 34 namespace android { 35 /** 36 * This class is used to kill this process when the runtime dies. 37 */ 38 class GrimReaper : public IBinder::DeathRecipient { 39 public: 40 GrimReaper() { } 41 42 virtual void binderDied(const wp<IBinder>& who) 43 { 44 LOGI("Grim Reaper killing system_server..."); 45 kill(getpid(), SIGKILL); 46 } 47 }; 48 49 } // namespace android 50 51 52 53 extern "C" status_t system_init() 54 { 55 LOGI("Entered system_init()"); 56 57 sp<ProcessState> proc(ProcessState::self()); 58 59 sp<IServiceManager> sm = defaultServiceManager(); 60 LOGI("ServiceManager: %p\n", sm.get()); 61 62 sp<GrimReaper> grim = new GrimReaper(); 63 sm->asBinder()->linkToDeath(grim, grim.get(), 0); 64 65 char propBuf[PROPERTY_VALUE_MAX]; 66 property_get("system_init.startsurfaceflinger", propBuf, "1"); 67 if (strcmp(propBuf, "1") == 0) { 68 // Start the SurfaceFlinger 69 SurfaceFlinger::instantiate(); 70 } 71 72 // On the simulator, audioflinger et al don't get started the 73 // same way as on the device, and we need to start them here 74 if (!proc->supportsProcesses()) { 75 76 // Start the AudioFlinger 77 AudioFlinger::instantiate(); 78 79 // Start the media playback service 80 MediaPlayerService::instantiate(); 81 82 // Start the camera service 83 CameraService::instantiate(); 84 85 // Start the audio policy service 86 AudioPolicyService::instantiate(); 87 } 88 89 // And now start the Android runtime. We have to do this bit 90 // of nastiness because the Android runtime initialization requires 91 // some of the core system services to already be started. 92 // All other servers should just start the Android runtime at 93 // the beginning of their processes's main(), before calling 94 // the init function. 95 LOGI("System server: starting Android runtime.\n"); 96 97 AndroidRuntime* runtime = AndroidRuntime::getRuntime(); 98 99 LOGI("System server: starting Android services.\n"); 100 runtime->callStatic("com/android/server/SystemServer", "init2"); 101 102 // If running in our own process, just go into the thread 103 // pool. Otherwise, call the initialization finished 104 // func to let this process continue its initilization. 105 if (proc->supportsProcesses()) { 106 LOGI("System server: entering thread pool.\n"); 107 ProcessState::self()->startThreadPool(); 108 IPCThreadState::self()->joinThreadPool(); 109 LOGI("System server: exiting thread pool.\n"); 110 } 111 return NO_ERROR; 112 } 113 114