ARTICLE DETAIL

资讯详情

深耕网站建设与运营推广的一线实战洞察。

Android 8 开机动画简单分析

Android 8 开机动画简单分析 1.由于是初步的学习所以用了一个比较老的安卓8所以肯定和Android新版本有出入。如果高版本不一样的话只能说是版本差异了。2.liunx内核启动的第一个进程就是init进程是surfaceflinger系统服务的父进程。在编译的时候呢 surfaceflinger的 Android.mk里有这么一行,根据参考得知这个是把surfaceflinger.rc装到init.rc里。LOCAL_INIT_RC。LOCAL_INIT_RC : surfaceflinger.rc具体是怎么装的呢这么装的在这个文件下build/core/base_rules.mk说实话很复杂看不懂我菜。ifndef LOCAL_IS_HOST_MODULE # Rule to install the modules companion init.rc. my_init_rc : $(LOCAL_INIT_RC_$(my_32_64_bit_suffix)) $(LOCAL_INIT_RC) ifneq ($(strip $(my_init_rc)),) my_init_rc_pairs : $(foreach rc,$(my_init_rc),$(LOCAL_PATH)/$(rc):$(TARGET_OUT$(partition_tag)_ETC)/init/$(notdir $(rc))) my_init_rc_installed : $(foreach rc,$(my_init_rc_pairs),$(call word-colon,2,$(rc)))然后在运行的时候就会在这个地方也就是init程序读取surfaceflingersystem\core\init\init.cpp2.什么时候启动surfaceflinger呢在下面这个文件里有启动时间 ,参考文章:init.rc./system/core/rootdir/init.rc由于这个surfaceflginger是class core的所以在boot的时候就随着core的启动也启动了。3.什么时候启动的开机动画呢在这个surfaceflinger的init函数里有这样一个线程:mStartPropertySetThread这个线程里有个方法设置了开机动画的属性使得开机动画启动了。bool StartPropertySetThread::threadLoop() { // Set property service.sf.present_timestamp, consumer need check its readiness property_set(kTimestampProperty, mTimestampPropertyValue ? 1 : 0); // Clear BootAnimation exit flag property_set(service.bootanim.exit, 0); // Start BootAnimation if not started property_set(ctl.start, bootanim); // Exit immediately return false; }4.为什么一设置这个property属性就开机动画了呢是因为在init.cpp里的main方法里开启了一个这个服务。start_property_service();这个服务可以读到property_set的发送这里有个epoll的知识点相当于用手机点外卖然后转到handle_property_set_fd这个方法里有一个函数handle_control_message(name.c_str() 4, value.c_str());这个函数呢就是会启动开机动画void handle_control_message(const std::string msg, const std::string name) { Service* svc ServiceManager::GetInstance().FindServiceByName(name); if (svc nullptr) { LOG(ERROR) no such service name ; return; } if (msg start) { svc-Start(); } else if (msg stop) { svc-Stop(); } else if (msg restart) { svc-Restart(); } else { LOG(ERROR) unknown control msg msg ; } }总结一下:init启动 -拉起surfaceflinger - surfaceflinger执行init方法- 执行startPropertySetThread-设置开机动画属性-开机动画启动。
返回列表