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