android从init到开机动画启动关闭流程一简易图(surfaceflinger启动的位置)

学习下,记录下,分享下

android从init到开机动画启动关闭流程一简易图(surfaceflinger启动的位置)_第1张图片

 

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<ProcessState> proc(ProcessState::self());

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

    sp<GrimReaper> 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;


 

 

你可能感兴趣的:(android从init到开机动画启动关闭流程一简易图(surfaceflinger启动的位置))