下载此文档

Android 开机启动流程.docx


文档分类:IT计算机 | 页数:约13页 举报非法文档有奖
1/13
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/13 下载此文档
文档列表 文档介绍
该【Android 开机启动流程 】是由【kunpengchaoyue】上传分享,文档一共【13】页,该文档可以免费在线阅读,需要了解更多关于【Android 开机启动流程 】的内容,可以使用淘豆网的站内搜索功能,选择自己适合的文档,以下文字是截取该文章内的部分文字,如需要获得完整电子版,请下载此文档到您的设备,方便您编辑和打印。Android的开机流程
系统引导bootloader
源码:bootable/bootloader/*
说明:加电后,CPU将先执行bootloader程序,此处有三种选择
开机按Camera+Power启动到fastboot,即命令或SD卡烧写模式,不加载内核及文件系统,此处可以进行工厂模式的烧写
开机按Home+Power启动到recovery模式,,,基本的文件系统,用于工程模式的烧写
开机按Power,正常启动系统,,,基本文件系统,用于正常启动手机(以下只分析正常启动的情况)
内核kernel
源码:kernel/*
说明:kernel由bootloader加载
文件系统及应用init
源码:system/core/init/*
配置文件:system/rootdir/,
说明:init是一个由内核启动的用户级进程,:启动服务(这里的服务指linux底层服务,如adbd提供adb支持,vold提供SD卡挂载等),执行命令和按其中的配置语句执行相应功能
重要的后台程序zygote
源码:frameworks/base/cmds/
说明:,该服务对应的命令是
/system/bin/app_process
建立JavaRuntime,建立虚拟机
建立Socket接收ActivityManangerService的请求,用于Fork应用程序
启动SystemServer
系统服务systemserver
源码:frameworks/base/services/java/com/android/server/
说明:被zygote启动,通过SystemManager管理android的服务(这里的服务指frameworks/base/services下的服务,如卫星定位服务,剪切板服务等)
桌面launcher
源码:,packages/apps/launcher*实现
说明:()通知各个服务,系统已经就绪,()通知的过程中建立的,最终调用()启launcher
解锁
源码:
frameworks/policies/base/phone/com/android/internal/policy/impl/*lock*
说明:()通知WindowManagerService,进而调用PhoneWindowManager,最终通过LockPatternKeyguardView显示解锁界面,跟踪代码可以看到解锁界面并不是一个
Activity,这是只是向特定层上绘图,其代码了存放在特殊的位置

1)源码:frameworks/base/services/java/com/android/server/am/
2)说明:().systemReady()通知ActivityManager启动成功,ActivityManager会通过置变量mBooting,通知它的另一线程,。

综上所述,系统层次关于启动最核心的部分是zygote(即app_process)和systemserver,zygote它负责最基本的虚拟机的建立,以支持各个应用程序的启动,而systemserver用于管理android后台服务,启动步骤及顺序。


Android启动过程详解
Android从Linux系统启动有4个步骤(1)init进程启动
Native服务启动
SystemServer,Android服务启动
Home启动总体启动框架图如:
HomeActivity
LJ
Kandare
Sensor
Coniiectivitjr
Location
Search
Battervr
Service
Service
Service
Manager
Service
Service
Activi^r
Window
Package
Power
Account
Content
...
Manager
L—』
Manager
Manager
h
Manager
山▲
Manager
Manager
ZygoteFork
Service
第一步:initial进程(system/core/init)
init进程,它是一个由内核启动的用户级进程。内核自行启动(已经被载入内存,开始运行,并已初始化所有的设备驱动程序和数据结构等)之后,就通过启动一个用户级程序init
Androidbooting
4的方式,完成引导进程。init始终是第一个进程.


:servicemanamgerzygote
。。。
最后Init并不退出,而是担当起propertyservice的功能。
******@System/Core/Init
:parse_config_file()***@parse_config_file()
解析脚本文件:(硬件平台相关)
(AndroidInitLanguage,System/Core/Init/)该脚本包含四个类型的声明:
Actions
Commands
Services
Options.


,解析文件内容***@system/core/init/。***@system/core/
(2)restart_service()***@system/core/init/
exeeve(…)建立service进程。
Androidbooting5
第二步Zygote
Servicemanager和zygote进程就奠定了Android的基础。Zygote这个进程起来才会建立起真正的Android运行空间,:
servicezygote/system/bin/app_process-Xzygote/system/bin--zygote--start-system-server所以Zygote从main(...)***@frameworks/base/cmds/。
main(.)***@frameworks/base/cmds/
("",startSystemServer);
runtime.******@
建立虚拟机
运行::main函数。
main()***@〃正真的Zygote。
registerZygoteSocket();〃登i记Listen端口
startSystemServer();
进入Zygote服务框架。
经过这几个步骤,Zygote就建立好了,利用Socket通讯,接收ActivityManangerService的请求,Fork应用程序。
第三步SystemServer
******@:@()就建立了。Android的所有服务循环框架都是建立SystemServer@()上。,只是可以看到建立了init2的实现函数,建立了一大堆服务,并AddService到serviceManager。
main()***@com/android/server/SystemServer
{
init1();
}
Init1()是在Native空间实现的()。我们一看这个函数就知道了,init1->system_init()***@()我们看到了循环闭合管理框架。
{
Call"com/android/server/SystemServer","init2"
ProcessState::self()->startThreadPool();
IPCThreadState::self()->joinThreadPool();
}
init2()***@。
这个init2()建立了一个线程,来NewService和AddService来建立服务
第三步Home启动
在******@,我们可以看到系统在启动完所有的Android服务后,做了这样一些动作:
(1)()通知各个服务,系统已经就绪。
(2)(回调)
,imm输入法)等ready通知。
()通知的过程中建立的。下面是
Androidbooting6
()的伪代码:systemReady()***@
resumeTopActivityLocked()startHomeActivityLocked();〃如果是第一个则启动HomeActivity。
startActivityLocked(。。。)CATEGORY_HOME
AndroidBooting:
:device/system/:
.
Parse/.%hardware%.rc.
Executeearly-initactioninthetwofilesparsedinstep2.
,makealldevicenodein/devanddownloadfirmwares.
.
Executeinitactioninthetwofilesparsedinstep2.
Startpropertyservice.
Executeearly-bootandbootactionsinthetwofilesparsedinstep2.
Executepropertyactioninthetwofilesparsedinstep2.
Enterintoanindefinitelooptowaitfordevice/propertyset/,ifanSDcardisplugined,initwillreceiveadeviceaddevent,,soifanyofthemcrashed,initwillreceiveaSIGCHLDthentranslateitintoachildprocessexitevent,sointheloopinitcanhandletheprocessexiteventandexecutethecommandsdefinedin*.rc(itwillruncommandonrestart).
.Wecantakealootatthefileformat(device/system/init/).Basicallythescriptfilecontainsactionsandservices.
Actions
'strigger,thatactionisaddedtothetailofato-be-executedqueue(unlessitisalreadyonthequeue).
(devicecreation/destruction,propertysetting,processrestarting)"between"theexecutionofthecommandsinactivities.
Actionstaketheformof:
on<trigger>
<command>
<command>
<command>
Services
Servicesareprogramswhichinitlaunchesand(optionally):
service<name><pathname>[<argument>]*
<option>
<option>
Options
.
Triggers
Triggersarestringswhichcanbeusedtomatchcertainkindsofeventsandusedtocauseanactiontooccur.
Androidbooting7
Thebuiltinsupportedcommandsaredefinedindevice/system/init/.
Theinitprogramonlyexecutesfivekindsoftriggers:“early-init",“init",“early-boot",“boot",“property:*"..
class_startdefault
Thislineisacommandfortheactioncorrespondingto“boot"“default".Bydefault,ifnoclassoptionisdefinedforaservice,theservice'sclassnameis“default".Sothislinewillstartalltheservicesintheorderofpositioninthefilebydefault.(BTW,youcanstartanyserviceusingstartcommands,ifyoulike.)Anyserviceisrunasaforkedprocessofinit,takealookatthesourcecodeofservice_startindevice/system/.
,thefollowingserviceswillbeexecutedstepbystep:console:.
adbd:.servicemanager:.
mountd:mountallfsdefinedin/system/etc/,.
debuggerd::.
zygote:'.
media:startAudioFlinger,.
bootsound:playthedefaultbootsound/system/media/audio/ui/.
dbus:startdbusdaemon,it'
device/system/Bluetooth/dbus-daemon.
hcid:redirecthcid'.
hfag:startBluetoothhandsfreeaudiogateway,it'-.
hsag:startBluetoothheadsetaudiogateway,it'-.
installd::load/system/.
Zygoteservicedoesthefollowingtasksstepbystep:
CreateJAVAVM.
RegisterandroidnativefunctionforJAVAVM.
.
LoadZygoteInitclass
Registerzygotesocket
Loadpreloadclasses(thedefaultfileisdevice/java/android/preloaded-classes)
Loadpreloadresources
CallZygote::forkSystemServer(implementedindevice/dalvik/vm/),,whosesourceisindevice/java/services/com/android/server.
Androidbooting9

CallJNInativeinit1functionimplementedindevice/libs/android_servers/.
口Ifrunningonsimulator,instantiateAudioFlinger,MediaPlayerServiceandCameraServicehere.
,whosesourceisindevice/java/services/com/android/.
口Ifnotrunningonsimulator,callIPCThreadState::self()->joinThreadPool()toenterintoservicedispatcher.
SystemServer::init2willstartanewthreadtostartallJAVAservicesasfollows:
CoreServices:
StartingPowerManager//
CreatingActivityManager
StartingTelephonyRegistry//
StartingPackageManager//
SetActivityManagerServiceasSystemProcess
StartingContextManager
StartingSystemContextProviders
StartingBatteryService//
StartingAlarmManager//
StartingSensorService
StartingWindowManager
StartingBluetoothService//
StartingMountService//
Otherservices//
StartingStatusBarService
StartingHardwareService
StartingNetStatService
StartingConnectivityService
StartingNotificationManager
StartingDeviceStorageMonitorService
StartingLocationManager
StartingSearchService
StartingClipboardService
StartingCheckinService
StartingWallpaperService
StartingAudioService
StartingHeadsetObserver
StartingAdbSettingsObserver
FinallySystemServer::.
Androidbooting9
Thereisanotherwaytostartsystemserver,whichisthroughaprogramnamedsystem_serverwhosesourceisdevice/servers/system/:whydoesAndroidhavetwomethodstostartsystemservices?Myguessisthatdirectlystartsystem_servermayhavesynchronousproblemwithzygotebecausesystem_serverwillcallJNItostartSystemServer::init2,

Android 开机启动流程 来自淘豆网m.daumloan.com转载请标明出处.

非法内容举报中心
文档信息
  • 页数13
  • 收藏数0 收藏
  • 顶次数0
  • 上传人kunpengchaoyue
  • 文件大小110 KB
  • 时间2022-11-25