android 启动流程
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha
adb shell 后 用 ps 命令 回车 可以看到 运行的进程。 如下结果:
cts 是测试
====
ps
USER PID PPID VSIZE RSS WCHAN PC NAME
root 1 0 300 208 c009b74c 0000ca4c S /init
root 2 0 0 0 c004e72c 00000000 S kthreadd
root 3 2 0 0 c003fdc8 00000000 S ksoftirqd/0
root 4 2 0 0 c004b2c4 00000000 S events/0
root 5 2 0 0 c004b2c4 00000000 S khelper
root 6 2 0 0 c004b2c4 00000000 S suspend
root 7 2 0 0 c004b2c4 00000000 S kblockd/0
root 8 2 0 0 c004b2c4 00000000 S cqueue
root 9 2 0 0 c018179c 00000000 S kseriod
root 10 2 0 0 c004b2c4 00000000 S kmmcd
root 11 2 0 0 c006fc74 00000000 S pdflush
root 12 2 0 0 c006fc74 00000000 S pdflush
root 13 2 0 0 c00744e4 00000000 S kswapd0
root 14 2 0 0 c004b2c4 00000000 S aio/0
root 22 2 0 0 c017ef48 00000000 S mtdblockd
root 23 2 0 0 c004b2c4 00000000 S kstriped
root 24 2 0 0 c004b2c4 00000000 S hid_compat
root 25 2 0 0 c004b2c4 00000000 S rpciod/0
root 26 2 0 0 c019d16c 00000000 S mmcqd
root 27 1 740 256 c0158eb0 afd0d8ac S /system/bin/sh
system 28 1 808 264 c01a94a4 afd0db4c S /system/bin/servicemanager
root 29 1 3736 436 ffffffff afd0e1bc S /system/bin/vold
root 30 1 3716 400 ffffffff afd0e1bc S /system/bin/netd
root 31 1 668 240 c01b52b4 afd0e4dc S /system/bin/debuggerd
radio 32 1 5392 548 ffffffff afd0e1bc S /system/bin/rild
root 33 1 101956 15508 c009b74c afd0dc74 S zygote
media 34 1 22764 1208 ffffffff afd0db4c S /system/bin/mediaserver
root 35 1 812 340 c02181f4 afd0d8ac S /system/bin/installd
keystore 36 1 1616 280 c01b52b4 afd0e4dc S /system/bin/keystore
root 37 1 740 256 c003da38 afd0e7bc S /system/bin/sh
root 38 1 840 344 c00b8fec afd0e90c S /system/bin/qemud
root 40 1 3400 192 ffffffff 0000ecc4 S /sbin/adbd
root 51 37 796 312 c02181f4 afd0d8ac S /system/bin/qemu-props
system 59 33 178760 25892 ffffffff afd0db4c S system_server
app_23 109 33 139644 18480 ffffffff afd0eb08 S jp.co.omronsoft.openwnn
radio 113 33 147592 17820 ffffffff afd0eb08 S com.android.phone
app_25 114 33 145304 19044 ffffffff afd0eb08 S com.android.launcher
system 119 33 137000 13900 ffffffff afd0eb08 S com.android.settings
app_0 152 33 137520 17104 ffffffff afd0eb08 S android.process.acore
app_9 160 33 131632 14776 ffffffff afd0eb08 S com.android.alarmclock
app_22 171 33 131956 14260 ffffffff afd0eb08 S com.android.music
app_12 179 33 141220 18308 ffffffff afd0eb08 S com.android.quicksearchbox
app_7 194 33 130796 13736 ffffffff afd0eb08 S com.android.protips
app_2 203 33 133560 15260 ffffffff afd0eb08 S android.process.media
app_15 214 33 144568 14692 ffffffff afd0eb08 S com.android.mms
app_30 230 33 135100 16052 ffffffff afd0eb08 S com.android.email
app_19 250 33 135596 15880 ffffffff afd0eb08 S com.android.browser
root 262 40 740 332 c003da38 afd0e7bc S /system/bin/sh
root 264 262 888 336 00000000 afd0d8ac R ps
#
init 进程:
当liunx内核完成启动之后,启动的第一个进程,它属于用户级进程,也属于一个引导进程。
1 创建文件目录 2 挂载sdcard 3 引导其他的进程:ril-d (打电话 modem) bootsound bootanim ... servicemanager zygote
servicemanager进程:管理了底层的服务
zygote 进程:1 创建了runtime 2 创建了dalvik vm 3 创建上层所有的应用(给这里应用分配内存空间,进程的id,进程能访问的)
只有servicemanager进程 和zygote 进程这个两个进程都起来之后,才会建立一个真正的android空间
2 com.android.phone 电话应用:
持久应用:
条件:
1 应用程序的apk文件必须存在于:/system/app
2 应用的AndroidManifest.xml文件:
<Appliaction android:persistent="true"
3 launcher
查看源码的流程:
1 adb shell
ps
2 system\core\init\init.c
3 frameworks\base\cmds\runtime\ServiceManager.cpp
#ifndef HAVE_ANDROID_OS
QuickRuntime* runt = new QuickRuntime();
runt->start("com/android/server/SystemServer",
false /* spontaneously fork system server from zygote */);
#endif
4 frameworks\base\services\java\com\android\server\SystemServer.java
native init1()
5 frameworks\base\services\jni\com_android_server_SystemServer.cpp
system_init();
6 frameworks\base\cmds\system_server\library\system_init.cpp
SensorService::instantiate();
CameraService::instantiate();
AndroidRuntime* runtime = AndroidRuntime::getRuntime();
runtime->callStatic("com/android/server/SystemServer", "init2");
7 frameworks\base\services\java\com\android\server\SystemServer.java
init2();
((ActivityManagerService)ActivityManagerNative.getDefault())
.systemReady(new Runnable() {}
qb.setTables("sms, (SELECT thread_id AS group_thread_id, MAX(date)AS group_date,"
+ "COUNT(*) AS msg_count FROM sms GROUP BY thread_id) AS groups");
qb.appendWhere("sms.thread_id = groups.group_thread_id AND sms.date ="
+ "groups.group_date");
qb.setProjectionMap(sConversationProjectionMap);
SELECT thread_id AS group_thread_id, MAX(date)AS group_date,COUNT(*) AS msg_count FROM sms GROUP BY thread_id AS groups
sConversationProjectionMap.put(Sms.Conversations.SNIPPET,sinppet
"sms.body AS snippet");
sConversationProjectionMap.put(Sms.Conversations.THREAD_ID,thread_id
"sms.thread_id AS thread_id");
sConversationProjectionMap.put(Sms.Conversations.MESSAGE_COUNT,msg_count
"groups.msg_count AS msg_count");
select
sms.body AS snippet,sms.thread_id AS thread_id,groups.msg_count AS msg_count
from
sms,(SELECT thread_id AS group_thread_id, MAX(date)AS group_date,COUNT(*) AS msg_count FROM sms GROUP BY thread_id) AS groups
where
sms.thread_id = groups.group_thread_id AND sms.date = groups.group_date
1 projectionIn != null
1.1 mProjectionMap != null
1.2 mProjectionMap == null projectionIn
2 projectionIn = = null && mProjectionMap != null mProjectionMap.getValue()
select thread_id,name
select sms.thread_id AS thread_id address as
=====
====
过滤原理 过滤的实现
handler 原理
【2012黑马程序员】短信智能管理器day01
=======