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 module's 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程序读取surfaceflinger
system\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->设置开机动画属性->开机动画启动。