android從init到開機動畫啟動關閉流程一簡易圖(surfaceflinger啟動的位置)

學習下,記錄下,分享下

init主進程啟動,解析init.rc後依次exec fork啟動相關的進程,其中以class main和core為首的service將會率先啟動,這裡SF將會觸發init啟動一個bootanimation進程,其會開始啟動動畫顯示,後臺其他服務進程完成初始化,待Systemserver的其他核心service啟動後,ActivityManagerService將會初始化完成並啟動第一個lunch activity即桌面程序,在渲染圖像前,需要讓SF停止動畫的顯示,故由AMS通知SF停止顯示,以方便Lunch最終display到UI上。這段顯示的時間,基本就是後臺服務的初始化運行,其中以SystemServer的耗時較長,導致開機動畫一直循環顯示。

通過 property_get(“system_init.startsurfaceflinger”, propBuf, “1”);
在init.rc來決定啟動的sufaceflinger在systemsever還是直接由init的main啟動。

extern "C" status_t system_init()
{
    ALOGI("Entered system_init()");

    sp proc(ProcessState::self());

    sp sm = defaultServiceManager();
    ALOGI("ServiceManager: %p\n", sm.get());

    sp grim = new GrimReaper();
    sm->asBinder()->linkToDeath(grim, grim.get(), 0);

    char propBuf[PROPERTY_VALUE_MAX];
    property_get("system_init.startsurfaceflinger", propBuf, "1");
    if (strcmp(propBuf, "1") == 0) {
        // Start the SurfaceFlinger   //在 init.rc中通過setprop system_init.startsurfaceflinger 0或者1,屬性值為如果是1則在Systemserver中直接啟動,否則以一個單獨的main進程啟動                                                                                                 SurfaceFlinger::instantiate();    }

    property_get("system_init.startsensorservice", propBuf, "1");
    if (strcmp(propBuf, "1") == 0) {
        // Start the sensor service
        SensorService::instantiate();
    }

    // And now start the Android runtime.  We have to do this bit
    // of nastiness because the Android runtime initialization requires
    // some of the core system services to already be started.
    // All other servers should just start the Android runtime at
    // the beginning of their processes's main(), before calling
    // the init function.
    ALOGI("System server: starting Android runtime.\n");
    AndroidRuntime* runtime = AndroidRuntime::getRuntime();

    ALOGI("System server: starting Android services.\n");
    JNIEnv* env = runtime->getJNIEnv();
    if (env == NULL) {
        return UNKNOWN_ERROR;
    }
    jclass clazz = env->FindClass("com/android/server/SystemServer");
    if (clazz == NULL) {
        return UNKNOWN_ERROR;
    }
    jmethodID methodId = env->GetStaticMethodID(clazz, "init2", "()V");
    if (methodId == NULL) {
        return UNKNOWN_ERROR;
    }
    env->CallStaticVoidMethod(clazz, methodId);

    ALOGI("System server: entering thread pool.\n");
    ProcessState::self()->startThreadPool();
    IPCThreadState::self()->joinThreadPool();
    ALOGI("System server: exiting thread pool.\n");

    return NO_ERROR;

發佈留言