| 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> |
| Mathias Agopian | 1bf7978 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 18 | #include <SensorService.h> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | |
| 20 | #include <android_runtime/AndroidRuntime.h> |
| 21 | |
| 22 | #include <signal.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <stdio.h> |
| 25 | #include <unistd.h> |
| 26 | #include <sys/time.h> |
| 27 | #include <cutils/properties.h> |
| 28 | |
| 29 | using namespace android; |
| 30 | |
| 31 | namespace android { |
| 32 | /** |
| 33 | * This class is used to kill this process when the runtime dies. |
| 34 | */ |
| 35 | class GrimReaper : public IBinder::DeathRecipient { |
| Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 36 | public: |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | GrimReaper() { } |
| 38 | |
| 39 | virtual void binderDied(const wp<IBinder>& who) |
| 40 | { |
| Steve Block | 6215d3f | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 41 | ALOGI("Grim Reaper killing system_server..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | kill(getpid(), SIGKILL); |
| 43 | } |
| 44 | }; |
| 45 | |
| 46 | } // namespace android |
| 47 | |
| 48 | |
| 49 | |
| 50 | extern "C" status_t system_init() |
| 51 | { |
| Steve Block | 6215d3f | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 52 | ALOGI("Entered system_init()"); |
| Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 53 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | sp<ProcessState> proc(ProcessState::self()); |
| Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 55 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | sp<IServiceManager> sm = defaultServiceManager(); |
| Steve Block | 6215d3f | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 57 | ALOGI("ServiceManager: %p\n", sm.get()); |
| Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 58 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | sp<GrimReaper> grim = new GrimReaper(); |
| 60 | sm->asBinder()->linkToDeath(grim, grim.get(), 0); |
| Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 61 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | char propBuf[PROPERTY_VALUE_MAX]; |
| 63 | property_get("system_init.startsurfaceflinger", propBuf, "1"); |
| 64 | if (strcmp(propBuf, "1") == 0) { |
| 65 | // Start the SurfaceFlinger |
| 66 | SurfaceFlinger::instantiate(); |
| 67 | } |
| 68 | |
| Mathias Agopian | c12b7ba | 2011-05-26 21:52:39 -0700 | [diff] [blame] | 69 | property_get("system_init.startsensorservice", propBuf, "1"); |
| 70 | if (strcmp(propBuf, "1") == 0) { |
| 71 | // Start the sensor service |
| 72 | SensorService::instantiate(); |
| 73 | } |
| Mathias Agopian | 1bf7978 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 74 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | // And now start the Android runtime. We have to do this bit |
| 76 | // of nastiness because the Android runtime initialization requires |
| 77 | // some of the core system services to already be started. |
| 78 | // All other servers should just start the Android runtime at |
| 79 | // the beginning of their processes's main(), before calling |
| 80 | // the init function. |
| Steve Block | 6215d3f | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 81 | ALOGI("System server: starting Android runtime.\n"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | AndroidRuntime* runtime = AndroidRuntime::getRuntime(); |
| 83 | |
| Steve Block | 6215d3f | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 84 | ALOGI("System server: starting Android services.\n"); |
| Elliott Hughes | d195e5a | 2011-04-13 15:39:37 -0700 | [diff] [blame] | 85 | JNIEnv* env = runtime->getJNIEnv(); |
| 86 | if (env == NULL) { |
| 87 | return UNKNOWN_ERROR; |
| 88 | } |
| 89 | jclass clazz = env->FindClass("com/android/server/SystemServer"); |
| 90 | if (clazz == NULL) { |
| 91 | return UNKNOWN_ERROR; |
| 92 | } |
| 93 | jmethodID methodId = env->GetStaticMethodID(clazz, "init2", "()V"); |
| 94 | if (methodId == NULL) { |
| 95 | return UNKNOWN_ERROR; |
| 96 | } |
| 97 | env->CallStaticVoidMethod(clazz, methodId); |
| 98 | |
| Steve Block | 6215d3f | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 99 | ALOGI("System server: entering thread pool.\n"); |
| Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 100 | ProcessState::self()->startThreadPool(); |
| 101 | IPCThreadState::self()->joinThreadPool(); |
| Steve Block | 6215d3f | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 102 | ALOGI("System server: exiting thread pool.\n"); |
| Jeff Brown | 10e8971 | 2011-07-08 18:52:57 -0700 | [diff] [blame] | 103 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | return NO_ERROR; |
| 105 | } |