The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Mathias Agopian | 0795272 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 11 | #include <binder/IPCThreadState.h> |
| 12 | #include <binder/ProcessState.h> |
| 13 | #include <binder/IServiceManager.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14 | #include <utils/TextOutput.h> |
| 15 | #include <utils/Log.h> |
| 16 | |
| 17 | #include <SurfaceFlinger.h> |
| 18 | #include <AudioFlinger.h> |
| 19 | #include <CameraService.h> |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 20 | #include <AudioPolicyService.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | #include <MediaPlayerService.h> |
Mathias Agopian | 1bf7978 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 22 | #include <SensorService.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | |
| 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 | |
| 33 | using namespace android; |
| 34 | |
| 35 | namespace android { |
| 36 | /** |
| 37 | * This class is used to kill this process when the runtime dies. |
| 38 | */ |
| 39 | class GrimReaper : public IBinder::DeathRecipient { |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 40 | public: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
| 54 | extern "C" status_t system_init() |
| 55 | { |
| 56 | LOGI("Entered system_init()"); |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 57 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | sp<ProcessState> proc(ProcessState::self()); |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 59 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | sp<IServiceManager> sm = defaultServiceManager(); |
| 61 | LOGI("ServiceManager: %p\n", sm.get()); |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 62 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | sp<GrimReaper> grim = new GrimReaper(); |
| 64 | sm->asBinder()->linkToDeath(grim, grim.get(), 0); |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 65 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 Agopian | c12b7ba | 2011-05-26 21:52:39 -0700 | [diff] [blame] | 73 | property_get("system_init.startsensorservice", propBuf, "1"); |
| 74 | if (strcmp(propBuf, "1") == 0) { |
| 75 | // Start the sensor service |
| 76 | SensorService::instantiate(); |
| 77 | } |
Mathias Agopian | 1bf7978 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 78 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | // And now start the Android runtime. We have to do this bit |
| 80 | // of nastiness because the Android runtime initialization requires |
| 81 | // some of the core system services to already be started. |
| 82 | // All other servers should just start the Android runtime at |
| 83 | // the beginning of their processes's main(), before calling |
| 84 | // the init function. |
| 85 | LOGI("System server: starting Android runtime.\n"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | AndroidRuntime* runtime = AndroidRuntime::getRuntime(); |
| 87 | |
| 88 | LOGI("System server: starting Android services.\n"); |
Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 89 | JNIEnv* env = runtime->getJNIEnv(); |
| 90 | if (env == NULL) { |
| 91 | return UNKNOWN_ERROR; |
| 92 | } |
| 93 | jclass clazz = env->FindClass("com/android/server/SystemServer"); |
| 94 | if (clazz == NULL) { |
| 95 | return UNKNOWN_ERROR; |
| 96 | } |
| 97 | jmethodID methodId = env->GetStaticMethodID(clazz, "init2", "()V"); |
| 98 | if (methodId == NULL) { |
| 99 | return UNKNOWN_ERROR; |
| 100 | } |
| 101 | env->CallStaticVoidMethod(clazz, methodId); |
| 102 | |
Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame^] | 103 | LOGI("System server: entering thread pool.\n"); |
| 104 | ProcessState::self()->startThreadPool(); |
| 105 | IPCThreadState::self()->joinThreadPool(); |
| 106 | LOGI("System server: exiting thread pool.\n"); |
| 107 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | return NO_ERROR; |
| 109 | } |