




已阅读5页,还剩11页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Android 启动流程 博客分类:Android资讯AndroidJavaITeye脚本Socket SystemServer的启动frameworks/base/services/java/com/android/server/SystemServer.java: run()其中调用ActivityManagerService.installSystemProviders(),最终会调用到frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/下的各个content providers的onCreate()函数,初始化数据库内容。android 启动流程other ref:/jacktu/archive/2010/07/02/1769939.htmlAndroid从Linux系统启动有4个步骤;(1) init进程启动(2) Native服务启动(3) System Server,Android服务启动(4) Home启动总体启动框架图如:android 启动流程第一步:initial进程(systemcoreinit) init进程,它是一个由内核启动的用户级进程。内核自行启动(已经被载入内存,开始运行,并已初始化所有的设备驱动程序和数据结构等)之后,就通过启动一个用户级程序init的方式,完成引导进程。init始终是第一个进程.Init.rcInit.marvell.rcandroid 启动流程Init进程一起来就根据init.rc和init.xxx.rc脚本文件建立了几个基本的服务: * servicemanamger * zygote。最后Init并不退出,而是担当起property service的功能。1.1脚本文件initSystem/Core/InitInit.c: parse_config_file(Init.rc) parse_config_file(Init.marvel.rc)解析脚本文件:Init.rc和Init.xxxx.rc(硬件平台相关)Init.rc是Android自己规定的初始化脚本(Android Init Language, System/Core/Init/readme.txt)该脚本包含四个类型的声明: * Actions * Commands * Services * Options.1.2 服务启动机制我们来看看Init是这样解析.rc文件开启服务的。(1)打开.rc文件,解析文件内容 systemcoreinitinit.c将service信息放置到service_list中。 systemcoreinit parser.c(2)restart_service() systemcoreinitinit.cservice_startexecve().建立service进程。第二步 ZygoteServicemanager和zygote进程就奠定了Android的基础。Zygote这个进程起来才会建立起真正的Android运行空间,初始化建立的Service都是Navtive service.在.rc脚本文件中zygote的描述:service zygote /system/bin/app_process -Xzygote /system/bin -zygote -start-system-server所以Zygote从main()frameworksbasecmdsapp_processapp_main.cpp开始。(1) main()frameworksbasecmdsapp_processapp_main.cpp * 建立Java Runtime * runtime.start(ernal.os.ZygoteInit, startSystemServer);(2) runtime.startframeworks/base/core/jni/AndroidRuntime.cpp * 建立虚拟机:startVM(.) * 运行:ernal.os.ZygoteInit:main函数。(3)main()ernal.os.ZygoteInit/正真的Zygote。 * registerZygoteSocket();/登记Listen端口 * startSystemServer(); * 进入Zygote服务框架。经过这几个步骤,Zygote就建立好了,利用Socket通讯,接收ActivityManangerService的请求,Fork应用程序。第三步 System Server上fork了一个进程: com.android.server.SystemServer.于是 SystemServer(SystemServer.java)就建立了。Android的所有服务循环框架都是建立 SystemServer(SystemServer.java)上。在SystemServer.java中看不到循环结构,只是可以看到建立了 init2的实现函数,建立了一大堆服务,并AddService到service Manager。main() com/android/server/SystemServerinit1();Init1()是在Native空间实现的(com_andoird_server_systemServer.cpp)。我们一看这个函数就知道了,init1-system_init() System_init.cpp在system_init()我们看到了循环闭合管理框架。Call com/android/server/SystemServer, init2.ProcessState:self()-startThreadPool(); IPCThreadState:self()-joinThreadPool();init2()SystemServer.java中建立了Android中所有要用到的服务。这个init2()建立了一个线程,来New Service和AddService来建立服务第三步 Home启动后半段,我们可以看到系统在启动完所有的Android服务后,做了这样一些动作:(1) 使用xxx.systemReady()通知各个服务,系统已经就绪。(2) 特别对于ActivityManagerService.systemReady(回调)Widget.wallpaper,imm(输入法)等ready通知。Home就是在ActivityManagerService.systemReady()通知的过程中建立的。下面是ActivityManagerService.systemReady()的伪代码:systemReady()ActivityManagerService.javaresumeTopActivityLocked()startHomeActivityLocked();/如果是第一个则启动HomeActivity。startActivityLocked(。)CATEGORY_HOME android 启动流程In this topic you will learn some information about Android process management. First lets take a look at the launched processes during Android booting.USER PID PPID VSIZE RSS WCHAN PC NAMEroot 1 0 264 176 c00acc6c 0000c36c S /initroot 28 1 724 308 c0051354 afe0c4cc S /system/bin/shsystem 30 1 796 248 c026516c afe0b74c S /system/bin/servicemanagerroot 31 1 1824 316 ffffffff afe0b50c S /system/bin/mountdroot 32 1 652 248 c02976e0 afe0c0bc S /system/bin/debuggerdradio 33 1 5344 664 ffffffff afe0bdbc S /system/bin/rildroot 34 1 71028 18828 c00ad308 afe0b874 S zygotemedia 37 1 16812 3456 ffffffff afe0b74c S /system/bin/mediaserverroot 39 1 788 288 c02f9ae4 afe0b50c S /system/bin/installdsystem 86 34 187756 21836 ffffffff afe0b74c S system_serverradio 118 34 103476 13896 ffffffff afe0c824 S com.android.phoneapp_4 124 34 117848 19248 ffffffff afe0c824 S cess.acoreapp_5 139 34 98672 11516 ffffffff afe0c824 S com.android.mmsapp_3 151 34 92096 10976 ffffffff afe0c824 S com.android.alarmclockapp_6 161 34 94436 12616 ffffffff afe0c824 S com.android.calendarapp_9 173 34 93248 11728 ffffffff afe0c824 S cess.mediaapp_15 182 34 91848 9764 ffffffff afe0c824 S com.android.voicedialerapp_16 190 34 94524 10812 ffffffff afe0c824 S cess.imThey can be divided into three kinds.Root Processinit is the first process after kernel booting. The major task it performs:l Parser and execute init.rc and init.%hardware%.rcl Automatically generate device node under /devl Start log and property servicel Monitor for device, property set and child process exit eventsNative Application ProcessAccording to init.rc, init will fork the following native application process.console: star a shell.servicemanager: start binder IPC service manager.mountd: mount all fs defined in /system/etc/mountd.conf if started, receive commands through local socket to mount any fs.debuggerd: start debug system.rild: start radio interface layer daemon.zygote: start Android Java VM Runtime and start system server. Its the most important process.mediaserver: start AudioFlinger, MediaPlayerService and CameraService.installd: start install package daemon.JAVA Application ProcessEvery JAVA application process is forked from zygote process. system_server is a special JAVA process, which is directly forked from zygote. Other JAVA process is created from ActivityManagerService(run in system_server process) like pid = Process.start(android.app.ActivityThread,mSimpleProcessManagement ? cessName : null, uid, uid,gids, (.flags&ApplicationInfo.FLAG_DEBUGGABLE) != 0), null);While Process.java use UNIX domain socket to communicate with zygote. So the overall picture is shown as following.android 启动流程System ServerIts the first JAVA application launched by zygote. It starts the core Android services, e.g. ActivityManager, WindowManager, PackageManager etc. Its the Android core engine.Persistent ApplicationDuring booting, ActivityManagerService.systemReady will start all persistent applications.List apps = ActivityThread.getPackageManager().getPersistentApplications(PackageManager.GET_SHARED_LIBRARY_FILES);if (apps != null) int N = apps.size();int i;for (i=0; iN; i+) ApplicationInfo info= (ApplicationInfo)apps.get(i);if (info != null &!info.packageName.equals(android) addAppLocked(info);Currently only Phone application is registered as a persistent app in AndroidManifest.xml like this.So during booting, only phone application is automatically launched. Its the “com.android.phone” process.The First ActivityThe first activity is launched by senting Intent.CATEGORY_HOME intent from ActivityManagerService.Intent intent = new Intent(mTopAction,mTopData != null ? Uri.parse(mTopData) : null);intent.setComponent(mTopComponent);if (mFactoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) intent.addCategory(Intent.CATEGORY_HOME);ActivityInfo aInfo =intent.resolveActivityInfo(mContext.getPackageManager(),PackageManager.GET_SHARED_LIBRARY_FILES);if (aInfo != null) intent.setComponent(new ComponentName(aInfo.applicationInfo.packageName, aI);/ Dont do this if the home app is currently being/ instrumented.ProcessRecord app = getProcessRecordLocked(aIcessName,aInfo.applicationInfo.uid);if (app = null | app.instrumentationClass = null) intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);startActivityLocked(null, intent, null, null, 0, aInfo,null, null, 0, 0, 0, false);Its the “cess.acore” process. (The process name is defined in AndroidManifest.xml)Auto-launched Application After BootingWhen activity idle is detected in ActivityManagerService, it will broadcast ACTION_BOOT_COMPLETED intent at the first time.if (mFactoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) / Tell anyone interested that we are done booting!synchronized (this) broadcastIntentLocked(null, null,new Intent(Intent.ACTION_BOOT_COMPLETED, null),null, null, 0, null, null,android.Manifest.permission.RECEIVE_BOOT_COMPLETED,false, false, MY_PID, Process.SYSTEM_UID);Currently, MMS, AlarmClock, Calendar, MediaProvider, VoiceDialer and IM have registered as a receiver for ACTION_BOOT_COMPLETED intent in their AndroidManifest.xml. So they will be automatically launched. (This explains the remained JAVA process.)Email also registers as a receiver for ACTION_BOOT_COMPLETED intent in its AndroidManifest.xml, but it defines android:enable=”false”. So it wont be launched.DownloadProvider also registers as a receiver for ACTION_BOOT_COMPLETED intent in its AndroidManifest.xml, but it defines android:exported=”false”. So it wont be launched.Behind the JAVA processsystem_server is a special case. It calls ActivityThread.javas systemMain static function, which creates an instance of ActivityThread. ActivityThread then creates an instance of ApplicationThread, Application and ApplicationContext.Every other JAVA process works in a different way. Its controlled by system_server while forked by zygote. When any JAVA process other than system_server is forked from zygote, it automatically calls ActivityThread.javas main static function(See Process.java and the following code snippet).try ZygoteInit.invokeStaticMain(cloader, className, mainArgs); catch (RuntimeException ex) logAndPrintError (newStderr, Error starting. , ex);The ActivityThr
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026届贵州省安顺市平坝区第二中学英语九上期末学业水平测试试题含解析
- 2026届北京八十中学化学九上期中调研试题含解析
- 海外保镖安全常识培训课件
- 记账报税基础知识培训课件
- 记承天寺夜游课件教学
- 记录天气变化课件
- 海口均安安全生产培训课件
- 让爷爷奶奶高兴课件
- 让地球动起来课件
- 农药经营店培训课件内容
- 老年患者麻醉专家共识
- 棋牌室员工管理制度
- 《中华人民共和国慈善法》培训解读课件
- CJ/T 249-2007城镇污水处理厂污泥处置混合填埋泥质
- 2025年版简易房屋租赁合同模板
- 医疗机构从业人员行为规范培训
- 2025年4月自考00908网络营销与策划试题及答案
- 医疗背景下的园艺景观规划设计方法
- 2025年行测真题及答案详解
- 《戏剧影视表演剧目创作》课件-1.任务1 了解时代背景与规定情境
- 2025深圳市标准劳动合同范本
评论
0/150
提交评论