Android初始化流程简要分析.docx

上传人:b****4 文档编号:24229088 上传时间:2023-05-25 格式:DOCX 页数:53 大小:586.72KB
下载 相关 举报
Android初始化流程简要分析.docx_第1页
第1页 / 共53页
Android初始化流程简要分析.docx_第2页
第2页 / 共53页
Android初始化流程简要分析.docx_第3页
第3页 / 共53页
Android初始化流程简要分析.docx_第4页
第4页 / 共53页
Android初始化流程简要分析.docx_第5页
第5页 / 共53页
点击查看更多>>
下载资源
资源描述

Android初始化流程简要分析.docx

《Android初始化流程简要分析.docx》由会员分享,可在线阅读,更多相关《Android初始化流程简要分析.docx(53页珍藏版)》请在冰豆网上搜索。

Android初始化流程简要分析.docx

Android初始化流程简要分析

Android初始化流程简要分析

liranke

TABLEOFCONTENTS

1Initprocess2

1.1Mainfunction(引自sdk参考文档)2

1.1.1Processstep:

2

1.1.2Startservices:

3

1.2Flowchart:

4

1.2.1Flowchart:

4

1.3Analyse:

5

1.3.1FD:

5

1.4Systemstatus7

1.4.1Processlist7

2Adbd9

3Servicemanager9

3.1Introcuce9

3.2Compiler10

3.3Flow:

10

3.3.1MainofFrameworks\base\cmds\servicemanager\service_manager.c10

3.4Main_runtimer.cpp16

4Mountd17

4.1Analyse17

5Debuggerd18

5.1Chart18

6Rild18

6.1Chart18

6.1.1RILArchitecture:

18

6.1.2RILFlow:

19

7zygote20

7.1Introduce20

7.2app_process21

7.2.1compile:

21

7.2.2Classchart:

22

7.2.3Flowchart:

22

7.3ZygoteInit24

7.3.1compile:

24

7.3.2ZygoteInitMainfunctionflowchart24

8system_server26

8.1Compile:

26

8.2Analyse:

27

8.2.1ServerClasschart27

8.2.2Syste_init28

8.2.3startSystemServer29

8.2.4runSelectLoopMode29

8.2.5context=ActivityManagerService.main(factoryTest)的执行过程36

9Media38

10Bootsound38

11Dbus38

12Installd38

12.1Chart38

12.2Analyse39

1Initprocess

Initisthefirstprocessafterkernelisstarted.Initcodelocalatsystem/core/init(Android)dir,mainfunctionisincludedinit.c.Initiscalledbykernel_initfunctionlocallingatinit(kernel)dir,viaexecvefunction.

1.1Mainfunction(引自sdk参考文档)

Initisthefirstprocessafterkernelisstarted.Initcodelocalatsystem/core/init(Android)dir,mainfunctionisincludedinit.c.Initiscalledbykernel_initfunctionlocallingatinit(kernel)dir,viaexecvefunction.

1.1.1Processstep:

1.      Mountbasicfilesystem,andnitializelogsystem.

2.      Parse/init.rcand/init.%hardware%.rc.

3.      Executeearly-initactionininit.rc.

4.      Devicespecificinitialize.

5.      Initializepropertysystem,andloadandroidimage,thenprint”ANDROID”.

6.      Executeinitactionininit.rc.

7.      Startpropertyservice.

8.      Executeearly-bootandbootactionsininit.rc.

9.      Executepropertyactionininit.rc.

10.  Enterintoanindefinitelooptowaitfordevice/propertyset/childprocessexitevents.Forexample,ifanSDcardisplugined,initwillreceiveadeviceaddevent,soitcanmakenodeforthedevice.Mostoftheimportantprocessisforkedininit,soifanyofthemcrashed,initwillreceiveaSIGCHLDthentranslateitintoachildprocessexitevent,sointheloopinitcanhandletheprocessexiteventandexecutethecommandsdefinedin*.rc(itwillruncommandonrestart).

1.1.2 Startservices:

The.rcfileisascriptfiledefinedbyAndroid.Thedefaultisdevice/system/rootdir/init.rc.Wecantakealootatthefileformat(device/system/init/readme.txtisagoodoverallintroductionofthescript).Basicallythescriptfilecontainsactionsandservices.

Init.rcwillrunthefollowingservices:

console:

starashell.Thesourceisindevice/system/bin/sh.

adbd:

startadbdaemon.Thesourceisindevice/tools/adbd.Bydefaultisdisabled.

servicemanager:

startbindersystem.Thesourceisindevice/commands/binder.

mountd:

mountallfsdefinedin/system/etc/mountd.confifstarted,receivecommandsthroughlocalsockettomountanyfs.Thesourceisindevice/system/bin/mountd.

debuggerd:

startdebugsystem.Thesourceisindevice/system/bin/debuggerd.

rild:

startradiointerfacelayerdaemon.Thesourceisindevice/commands/rild.

zygote:

startAndroidJavaRuntimeandstartsystemserver.It’sthemostimportantservice.Thesourceisindevice/servers/app.

media:

startAudioFlinger,MediaPlayerServiceandCameraService.Thesourceisindevice/commands/mediaserver.

bootsound:

playthedefaultbootsound/system/media/audio/ui/boot.mp3.Thesourceisindevice/commands/playmp3.

dbus:

startdbusdaemon,it’sonlyusedbyBlueZ.Thesourceisindevice/system/Bluetooth/dbus-daemon.

hcid:

redirecthcid’sstdoutandstderrtotheAndroidloggingsystem.Thesourceisindevice/system/bin/logwrapper.Bydefaultisdisabled.

hfag:

startBluetoothhandsfreeaudiogateway,it’sonlyusedbyBlueZ.Thesourceisindevice/system/Bluetooth/bluez-utils.Bydefaultisdisabled.

hsag:

startBluetoothheadsetaudiogateway,it’sonlyusedbyBlueZ.Thesourceisindevice/system/Bluetooth/bluez-utils.Bydefaultisdisabled.

installd:

startinstallpackagedaemon.Thesourceisindevice/servers/installd.

flash_recovery:

load/system/recovery.img.Thesourceisindevice/commands/recovery/mtdutils.

1.2Flowchart:

 

1.2.1 Flowchart:

1.3Analyse:

1.3.1 FD:

FDInclude:

device_fd,property_set_fd,signal_recv_fd,signal_fd(globalvalue)

ufds:

structpollfdufds[4]={device_fd,property_set_fd,signal_recv_fd,keychord_fd}

1.device_fd

2.property_set_fd

(1)

(2)Property_set_fdC/Schart:

#definePROP_SERVICE_NAME"property_service"

3.signal_recv_fd

signal_recv_fdandsignal_fd:

/*createasignallingmechanismforthesigchldhandler*/

if(socketpair(AF_UNIX,SOCK_STREAM,0,s)==0){

signal_fd=s[0];

signal_recv_fd=s[1];

fcntl(s[0],F_SETFD,FD_CLOEXEC);

fcntl(s[0],F_SETFL,O_NONBLOCK);

fcntl(s[1],F_SETFD,FD_CLOEXEC);

fcntl(s[1],F_SETFL,O_NONBLOCK);

}

……

//readsignal

read(signal_recv_fd,tmp,sizeof(tmp);

while(!

wait_for_one_process(0));//阻塞

4.signal_fd(seetosignal_recv_fd)

1.4Systemstatus

1.4.1Processlist

USERPIDPPIDVSIZERSSWCHANPCNAME

root10548196c00b8c140000d5ccS/init

root2000c006bf7000000000Skthreadd

root3200c005cc5000000000Sksoftirqd/0

root4200c007e40800000000Swatchdog/0

root5200c0068eec00000000Sevents/0

root6200c0068eec00000000Skhelper

root10200c0224f9000000000Ssuspend/0

root81200c0068eec00000000Skblockd/0

root89200c01f2f7c00000000Skseriod

root111200c0068eec00000000Skmmcd

root117200c0068eec00000000Sbtaddconn

root118200c0068eec00000000Sbtdelconn

root135200c00448e000000000Sbpmd

root141200c008b5f400000000Spdflush

root142200c008b5f400000000Spdflush

root143200c008f94800000000Skswapd0

root189200c0068eec00000000Saio/0

root195200c01721f000000000Smtdblockd

root340200c01b4eb000000000Saccessorynotif

root349200c0068eec00000000Scamera_task/0

root376200c006143800000000Sw1_control

root378200c006143800000000Sw1_bus_master1

root386200c0068eec00000000Scharge?

root428200c02ca26c00000000Skrfcommd

root430200c0068eec00000000Srpciod/0

root724200c021690800000000Smmcqd

root7261772180c019dbc4afe0c1dcS/system/bin/sh

system7271840188c022d8a0afe0c47cS/system/bin/servicemanager

root72911920336ffffffffafe0c1dcS/system/bin/mountd

root7301704176c0257854afe0ce0cS/system/bin/debuggerd

root73114132628c027e2f8afe0ce0cS/opl/bin/tcmd

root7321852248c00b92b0afe0c5a4S/opl/bin/adapter

radio733112796648ffffffffbeaab18cS/system/bin/rild

root73417200014172c00b92b0afe0c5a4Szygote

root7351338484512ffffffffafe0c47cS/system/bin/mediaserver

root73611080216c00b8c14bedc021cS/system/bin/dbus-daemon

root7371832208c02b6e80afe0c1dcS/system/bin/installd

root7401856260c00b92b0afe0c5a4S/opl/bin/bpd

root7411828172c00b8c14afe0d27cS/opl/bin/battmond

root7681720272c02265ecafe0c1dcS/system/bin/logcat

root7691716264c02265ecafe0c1dcS/system/bin/logcat

root816200c0068eec00000000Sbattery.0

system82573457412828360ffffffffafe0c47cSsystem_server

radio87773415826020040ffffffffafe0d404Scom.android.phone

app_587973410088813616ffffffffafe0d404Sandroid.process.acore

system88273414466424296ffffffffafe0d404Sandroid.process.omsservice

app_458847349230410932ffffffffafe0d404Scom.motorola.motohome

app_2289073411706830228ffffffffafe0d404Soms.home

app_39187349876012652ffffffffafe0d404Soms.widgetmanager

app_592873410088813336ffffffffafe0d404Scom.android.inputmethod.borqs

app_2493073410517619168ffffffffafe0d404Scom.db4o.servo.search

app_1896073410418015208ffffffffafe0d404Scom.android.mms

app_897973411886014044ffffffffafe0d404Sandroid.process.media

app_99917349198012264ffffffffafe0d404Scom.android.alarmclock

app_1599873410314412908ffffffffafe0d404Soms.dcd

system10187349473213792ffffffffafe0d404Soms.dm

app_1410257349563613036ffffffffafe0d404Scom.android.calendar

app_4210417349329211316ffffffffafe0d404Scom.motorola.smsautoreg

app_4010907349715215192ffffffffafe0d404Scom.motorola.mtc

app_3811027349383212868ffffffffafe0d404Scom.streamezzo.browser.android

app_2611157349659615084ffffffffafe0d404Soms.mediacenter

app_3711267349820815212ffffffffafe0d404Scom.hyfsoft.docviewer

app_2011467349926015320ffffffffafe0d404Scom.android.music

app_47115773410020415964ffffffffafe0d404Scom.motorola.camera

app_11118373412267223576ffffffffafe0d404Scom.android.browser

app_6119973411703220388ffffffffafe0d404Soms.mobilemusic

system12447349929215940ffffffffafe0d404Scom.android.settings

app_2313117349693216004ffffffffafe0d404Soms.bru

root1334200c021690800000000Smmcqd

app_8135173410030815876ffffffffafe0d404Scom.android.camera

app_1142473411190417024ffffffffafe0d404Soms.messaging

app_4143673410117215504ffffffffafe0d404Soms.mail

app_2148473410071618128ffffffffafe0d404Scom.ms

app_16166373410102416748ffffffffafe0d404Soms.android.filemanager

root168413364176ffffffff0000e8f4S/sbin/adbd

root16921684776348c0059cd4afe0d0acS/system/bin/sh

root1724169292035600000000afe0c1dcRps

从真正的应用层的角度来看,所有的应用程序(如settings,media……)的父进程都是zygote.因为任何一个应用都是一个VM。

2Adbd

SeetoA

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 总结汇报 > 其它

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1