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