Android-FrameWork架构C 源码剖析

Android-FrameWork架构C++源码剖析

Android 系统整体架构

+-------------------------------------------+
| APP: home, Tel, Media, Camera ...         |
+-------------------------------------------+
| FrameWork(Java): Activity, Window ...     |
+-------------------------------------------+
+----------------------+--------------------+
| ThirdParty Library   |                    |
| FrameWork(C++)       | Dalvik             |
+----------------------+--------------------+
+-------------------------------------------+
| HAL: Audio, sensor, WIFI, Camera ...      |
+===========================================+
+==============================================+
| Linux kernel: Memory, VFS, Driver, Binder ...|
+==============================================+

虚拟机创建和第一个java程序引导
启动脚本中定义
system/core/rootdir/init.zygote32.rc:
service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server
system/core/rootdir/init.zygote64.rc:
service zygote /system/bin/app_process64 -Xzygote /system/bin --zygote --start-system-server

/system/bin/app_process -Xzygote
/system/bin --zygote --start-system-server

app_process
AndroidRuntime.start()

app_process 程序入口
frameworks\base\cmds\app_process\app_main.cpp
其中部分 AndroidRuntime 方法实现在这里
frameworks\base\core\jni\AndroidRuntime.cpp
runtime.start("com.android.internal.os.ZygoteInit", startSystemServer)
{
-> startVm() -> JNI_CreateJavaVM() -> dvmCreateJNIEnv()
-> startReg() -> register_jni_procs();
-> start zygote service()
    {
    startClass = env->FindClass(slashClassName);
    startMeth = env->GetStaticMethodID(startClass, "main", "([Ljava/lang/String;)V");
    env->CallStaticVoidMethod(startClass, startMeth, strArray);
    }
}

app 启动过程

Launcher process::ActivityManagerProxy --> system_server::ActivityManagerService: startActivity

system_server::ActivityManagerService --> Zygote: create process req
Zygote --> Zygote: fork for app
APP::ActivityManagerProxy --> system_server::ActivityManagerService: attach_application
system_server::ActivityManagerService --> system_server::ApplicationThreadProxy: realStartActivityLocked
system_server::ApplicationThreadProxy --> APP:ApplicationThread: scheduledLaunchActivity
APP::ApplicationThread -> APP::ActivityThread: H.LAUNCH_ACTIVITY
APP::ActivityThread -> APP::ActivityThread: handleLaunchActivity
APP::ActivityThread -> APP::Activity.onCreate

plantuml 图代码如下
@startuml
box LauncherProcess
boundary LauncherProcess_ActivityManagerProxy
end box

box system_server
boundary ActivityManagerService
boundary ApplicationThreadProxy
end box

box APP
boundary ActivityManagerProxy
boundary ApplicationThreadProxy
boundary ApplicationThread
boundary Activity
boundary ActivityThread
end box


LauncherProcess_ActivityManagerProxy --> ActivityManagerService: startActivity

ActivityManagerService --> Zygote: create process req
Zygote --> ActivityManagerProxy: fork app
ActivityManagerProxy --> ActivityManagerService: attach_application
ActivityManagerService --> ApplicationThreadProxy: realStartActivityLocked
ApplicationThreadProxy --> ApplicationThread: scheduledLaunchActivity
ApplicationThread --> ActivityThread: H.LAUNCH_ACTIVITY
ActivityThread -> ActivityThread: handleLaunchActivity
ActivityThread -> Activity: Activity.onCreate
@enduml


未完待续...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值