文章目錄
- Android 開機動畫的啟動過程BootAnimation(基于Android10.0.0-r41)
- 1.開機動畫的啟動過程概述
- 2.為什么設置了屬性之后就會播放?
Android 開機動畫的啟動過程BootAnimation(基于Android10.0.0-r41)
1.開機動畫的啟動過程概述
下面就是BootAnimation的重要部分。
開機動畫主要跟三個東西有關系
bootanimation surfaceflinger init
查看下Android.bp編譯文件,cc_binary就是我們編譯出來的可執行文件
最終的輸出路徑是在
系統啟動的第一個進程是init,init進程會根據init.rc配置啟動surfaceflinger進程。就是下面這個.rc進程
但是此時的Bootanim.rc不會啟動。是disabled。
一般一個進程啟動了,都會有一個對應的main方法。
路徑frameworks/native/services/surfaceflinger
int main(int, char**) {signal(SIGPIPE, SIG_IGN);hardware::configureRpcThreadpool(1 /* maxThreads */,false /* callerWillJoin */);startGraphicsAllocatorService();// When SF is launched in its own process, limit the number of// binder threads to 4.ProcessState::self()->setThreadPoolMaxThreadCount(4);// start the thread poolsp<ProcessState> ps(ProcessState::self());ps->startThreadPool();// instantiate surfaceflinger//創建對象sp<SurfaceFlinger> flinger = surfaceflinger::createSurfaceFlinger();setpriority(PRIO_PROCESS, 0, PRIORITY_URGENT_DISPLAY);set_sched_policy(0, SP_FOREGROUND);// Put most SurfaceFlinger threads in the system-background cpuset// Keeps us from unnecessarily using big cores// Do this after the binder thread pool initif (cpusets_enabled()) set_cpuset_policy(0, SP_SYSTEM);// initialize before clients can connect//執行init方法flinger->init();// publish surface flingersp<IServiceManager> sm(defaultServiceManager());sm->addService(String16(SurfaceFlinger::getServiceName()), flinger, false,IServiceManager::DUMP_FLAG_PRIORITY_CRITICAL | IServiceManager::DUMP_FLAG_PROTO);startDisplayService(); // dependency on SF getting registered abovestruct sched_param param = {0};param.sched_priority = 2;if (sched_setscheduler(0, SCHED_FIFO, ¶m) != 0) {ALOGE("Couldn't set SCHED_FIFO");}// run surface flinger in this thread//執行run方法flinger->run();return 0;
}
首先進入init方法
開啟一個線程,Start()之后這個線程就運行起來了。
線程run起來
bootanim設置屬性,控制bootanim的一個服務要啟動起來,就是這里設置屬性之后就會起來了,就開始播放開機動畫。
property_set("service.bootanim.exit", "0");// Start BootAnimation if not startedproperty_set("ctl.start", "bootanim");
2.為什么設置了屬性之后就會播放?
/system/core/init.cpp
啟動屬性服務
跨進程通信CreateSocket
void StartPropertyService(Epoll* epoll) {selinux_callback cb;cb.func_audit = SelinuxAuditCallback;selinux_set_callback(SELINUX_CB_AUDIT, cb);property_set("ro.property_service.version", "2");//獲取fdproperty_set_fd = CreateSocket(PROP_SERVICE_NAME, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK,false, 0666, 0, 0, nullptr);if (property_set_fd == -1) {PLOG(FATAL) << "start_property_service socket creation failed";}//監聽fd句柄listen(property_set_fd, 8);if (auto result = epoll->RegisterHandler(property_set_fd, handle_property_set_fd); !result) {PLOG(FATAL) << result.error();}
}
回調方法handle_property_set_fd,然后調用下面這個方法
然后進到HandleControlMessage,此時我們發現這個方法不知道是哪個頭文件引入進來的,所以得搜索一下。
遞歸搜索當前目錄以及子目錄。
grep "HandleControlMessage" ./ -rn
通過名字查找服務,也就是前面設置的屬性值bootanim
找到對應的map,根據msg獲取服務的狀態是什么樣子的,然后根據name名字去找到對應設置的服務。
繪制圖像需要依賴surfaceflinger來繪制,所以開機動畫是在surfaceflinger之后啟動的。
init啟動。surfaceflinger進程的init執行,然后StartPropetySetThread線程的啟動,然后再通知init進程啟動開機動畫進程,然后是bootanimation的main方法執行,