android 启动 ZygoteInit.java分析
2012-12-03 17:42
453 查看
关于android启动分析的文章 是拜读柯元旦老师的android内核剖析 与 邓凡平老师的深入理解android 自己读源码按图索骥的成果。
在这里感谢 两位老师的不辞辛劳把知识奉献出来与大家分享!
ZygoteInit.java 受精卵初始化
主要做的工作有
1.主要功能为 注册一个 服务端接口 端口号为666 在init.rc中定义的
这个socketserver 接收来自客户端分裂子他进程的请求
2.加载class文件
3.加载系统资源文件 包括preloaded_drawables 与preloaded_color_state_lists
4.启动:SystemServer进程 并且入口地址为com.android.server.SystemServer.main
5.如果启动成功了 关闭子进程 即第4部中的socketserer监听
6.监听socket请求
System_server进程 是android frameWork 各模块的存在进程
System_server路径为 /frameworks/base/services/java/com/android/server/SystemServer.java
/**
* This method is called from Zygote to initialize the system. This will cause the native
* services (SurfaceFlinger, AudioFlinger, etc..) to be started. After that it will call back
* up into init2() to start the Android services.
*/
native public static void init1(String[] args);
public static void main(String[] args) {
if (SamplingProfilerIntegration.isEnabled()) {
SamplingProfilerIntegration.start();
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
SamplingProfilerIntegration.writeSnapshot("system_server");
}
}, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
}
// The system server has to run all of the time, so it needs to be
// as efficient as possible with its memory usage.
VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
System.loadLibrary("android_servers");
init1(args);
}
这里注释写的也很清楚 这个方法是由Zygote 即 ZygoteInit.java来调用初始化系统的,这里会通过native方法启动服务(显示,多媒体 等服务)然后调用init2()来开启
android服务
native方法是在 /frameworks/base/services/jni/com_android_server_SystemServer.cpp实现的。
static void android_server_SystemServer_init1(JNIEnv* env, jobject clazz)
{
system_init();
}
又调用了system_init();方法
通过搜索 发现这个方法在frameworks\base\cmds\system_server\library\system_init.cpp文件中
这里启动的服务并不多 包括 SurfaceFlinger AudioFlinger MediaPlayerService CameraService AudioPolicyService
然后调用了init2();
来看下init2()吧
init2 启动了一个线程来加载各种服务
加载的服务有:
new EntropyService()
new PowerManagerService()
new TelephonyRegistry(context)
TelephonyRegistry
PackageManagerService
ActivityManagerService
AccountManagerService
ContentService
BatteryService
HardwareService
AlarmManagerService
SensorService
WindowManagerService
InputMethodManagerService
WallpaperManagerService
等
在这里感谢 两位老师的不辞辛劳把知识奉献出来与大家分享!
ZygoteInit.java 受精卵初始化
主要做的工作有
1.主要功能为 注册一个 服务端接口 端口号为666 在init.rc中定义的
这个socketserver 接收来自客户端分裂子他进程的请求
2.加载class文件
3.加载系统资源文件 包括preloaded_drawables 与preloaded_color_state_lists
4.启动:SystemServer进程 并且入口地址为com.android.server.SystemServer.main
5.如果启动成功了 关闭子进程 即第4部中的socketserer监听
6.监听socket请求
System_server进程 是android frameWork 各模块的存在进程
System_server路径为 /frameworks/base/services/java/com/android/server/SystemServer.java
/**
* This method is called from Zygote to initialize the system. This will cause the native
* services (SurfaceFlinger, AudioFlinger, etc..) to be started. After that it will call back
* up into init2() to start the Android services.
*/
native public static void init1(String[] args);
public static void main(String[] args) {
if (SamplingProfilerIntegration.isEnabled()) {
SamplingProfilerIntegration.start();
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
SamplingProfilerIntegration.writeSnapshot("system_server");
}
}, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
}
// The system server has to run all of the time, so it needs to be
// as efficient as possible with its memory usage.
VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
System.loadLibrary("android_servers");
init1(args);
}
这里注释写的也很清楚 这个方法是由Zygote 即 ZygoteInit.java来调用初始化系统的,这里会通过native方法启动服务(显示,多媒体 等服务)然后调用init2()来开启
android服务
native方法是在 /frameworks/base/services/jni/com_android_server_SystemServer.cpp实现的。
static void android_server_SystemServer_init1(JNIEnv* env, jobject clazz)
{
system_init();
}
又调用了system_init();方法
通过搜索 发现这个方法在frameworks\base\cmds\system_server\library\system_init.cpp文件中
这里启动的服务并不多 包括 SurfaceFlinger AudioFlinger MediaPlayerService CameraService AudioPolicyService
然后调用了init2();
来看下init2()吧
init2 启动了一个线程来加载各种服务
加载的服务有:
new EntropyService()
new PowerManagerService()
new TelephonyRegistry(context)
TelephonyRegistry
PackageManagerService
ActivityManagerService
AccountManagerService
ContentService
BatteryService
HardwareService
AlarmManagerService
SensorService
WindowManagerService
InputMethodManagerService
WallpaperManagerService
等
相关文章推荐
- 为什么Android每当启动一个新的应用程序时会通过“throw new ZygoteInit.MethodAndArgsCaller(m, argv)”进入ActivityThread的main函数
- Android 应用的真正入口 - ZygoteInit.java
- 深入理解Android(06)——Java世界的入口ZygoteInit
- Android启动过程分析——init.c(二)
- Android启动过程分析——init.c(一)
- ZygoteInit中启动的SystemServer分析
- (OK) Android x86如何启动到图形界面&init.sh分析.md
- ZygoteInit to java world
- 图解Android - Zygote, System Server 启动分析
- (OK) 图解Android - Zygote, System Server 启动分析
- Android系统进程Zygote启动过程的源代码分析
- Android系统进程Zygote启动过程的源代码分析(2)
- Android系统进程Zygote启动过程的源代码分析
- Android研究-Android的init启动到launcher启动-主要分析zygote服务
- 4.1Android进程启动原理分析----Zygote
- Android系统进程Zygote启动过程的源代码分析(3)
- Android情景分析之详解init进程(以启动zygote为例)
- Android系统进程Zygote启动过程的源代码分析(老罗的作品)
- Android --- Zygote和System进程启动过程简要分析
- Android系统进程Zygote启动过程的源代码分析