When encountering a problem, the application often enters the desktop when it receives the BOOT_COMPLETED broadcast.
Then a colleague proposed: You can receive the PRE_BOOT_COMPLETED broadcast.
So I studied the transmission of this broadcast.
========================================
Address of this article: http://oliveexcel.iteye.com/blog/2302947
========================================
Everything starts with SystemServer.main():
SystemServer.main()
-> SystemServer.run()
-> mPackageManagerService.performBootDexOpt()
-> Among them, find the corresponding ResolveInfo list through Intent.ACTION_PRE_BOOT_COMPLETED (can be regarded as a package list), and execute performBootDexOpt() on each of the packages, giving priority to the corresponding package (the code has a rough look, through the socket connect in the Installer After installd, the conversion from dex to ota will be performed to satisfy the loading of Android ART).
-> mPackageManagerService.systemReady()
-> From the timing point of view, the loading of the package that receives this broadcast should be prior to systemReady(), that is, prior to the loading of other packages
-> mActivityManagerService.systemReady()
-> deliverPreBootCompleted()
-> Find all Receivers that receive this broadcast, and filter out unauthorized applications through Application.FLAG_SYSTEM
-> PreBootContinuation.go()
-> broadcastIntentLocked()
-> Finish sending the broadcast
To sum up, the broadcast is issued in ActivityManagerService.systemReady().