当前位置:网站首页>SystemServer进程
SystemServer进程
2022-07-02 10:18:00 【xhBruce】
SystemServer进程
android12-release
Android系统启动
Zygote进程
Zygote进程fork而来
init进程 -> Zygote进程 -> system_server进程
frameworks/base/core/java/com/android/internal/os/ZygoteInit.java
frameworks/base/core/java/com/android/internal/os/Zygote.java
frameworks/base/core/jni/com_android_internal_os_Zygote.cpp
art/runtime/native/dalvik_system_ZygoteHooks.cc
forkSystemServer().run() -> pid = Zygote.forkSystemServer() -> nativeForkSystemServer() -> com_android_internal_os_Zygote_nativeForkSystemServer -> pid = zygote::ForkCommon() -> pid = fork() -> SpecializeCommon()
/* Hardcoded command line to start the system server */
String[] args = {
"--setuid=1000",
"--setgid=1000",
"--setgroups=1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,1018,1021,1023,"
+ "1024,1032,1065,3001,3002,3003,3006,3007,3009,3010,3011",
"--capabilities=" + capabilities + "," + capabilities,
"--nice-name=system_server",
"--runtime-args",
"--target-sdk-version=" + VMRuntime.SDK_VERSION_CUR_DEVELOPMENT,
"com.android.server.SystemServer",
};
ZygoteArguments parsedArgs;
SystemServer进程参数信息为uid=1000,gid=1000,进程名为
sytem_serverZygote.forkSystemServer()fork出system_server进程
com_android_internal_os_Zygote_nativeForkSystemServerJNIzygote::ForkCommon()调用到fork()创建新进程,采用copy on write方式,这是linux创建进程的标准方法,会有两次return。 返回值有3种类型:父进程中,fork返回新创建的子进程的pid;子进程中,fork返回0;当出现错误时,fork返回负数。
当system_server进程死亡后,重启zygote进程。新创建system_server进程已完成,
pid == 0便进入handleSystemServerProcess()方法
handleSystemServerProcess
fork()到此system_server进程已完成了创建的所有工作,接下来开始了system_server进程的真正工作
handleSystemServerProcess(parsedArgs)完成system_server进程剩余工作,运行在system_server进程Process.setArgV0(parsedArgs.mNiceName)当前进程名"system_server"performSystemServerDexOpt()执行dex优化操作,由installd来完成- system_server执行
ZygoteInit.zygoteInit()
/** * Finish remaining work for the newly forked system server process. */
private static Runnable handleSystemServerProcess(ZygoteArguments parsedArgs) {
// set umask to 0077 so new files and directories will default to owner-only permissions.
Os.umask(S_IRWXG | S_IRWXO);
if (parsedArgs.mNiceName != null) {
Process.setArgV0(parsedArgs.mNiceName);
}
final String systemServerClasspath = Os.getenv("SYSTEMSERVERCLASSPATH");
if (systemServerClasspath != null) {
performSystemServerDexOpt(systemServerClasspath);
// Capturing profiles is only supported for debug or eng builds since selinux normally
// prevents it.
if (shouldProfileSystemServer() && (Build.IS_USERDEBUG || Build.IS_ENG)) {
try {
Log.d(TAG, "Preparing system server profile");
prepareSystemServerProfile(systemServerClasspath);
} catch (Exception e) {
Log.wtf(TAG, "Failed to set up system server profile", e);
}
}
}
if (parsedArgs.mInvokeWith != null) {
String[] args = parsedArgs.mRemainingArgs;
// If we have a non-null system server class path, we'll have to duplicate the
// existing arguments and append the classpath to it. ART will handle the classpath
// correctly when we exec a new process.
if (systemServerClasspath != null) {
String[] amendedArgs = new String[args.length + 2];
amendedArgs[0] = "-cp";
amendedArgs[1] = systemServerClasspath;
System.arraycopy(args, 0, amendedArgs, 2, args.length);
args = amendedArgs;
}
WrapperInit.execApplication(parsedArgs.mInvokeWith,
parsedArgs.mNiceName, parsedArgs.mTargetSdkVersion,
VMRuntime.getCurrentInstructionSet(), null, args);
throw new IllegalStateException("Unexpected return from WrapperInit.execApplication");
} else {
ClassLoader cl = getOrCreateSystemServerClassLoader();
if (cl != null) {
Thread.currentThread().setContextClassLoader(cl);
}
/* * Pass the remaining arguments to SystemServer. */
return ZygoteInit.zygoteInit(parsedArgs.mTargetSdkVersion,
parsedArgs.mDisabledCompatChanges,
parsedArgs.mRemainingArgs, cl);
}
/* should never reach here */
}
ZygoteInit.zygoteInit()
ZygoteInit.nativeZygoteInit()在AndroidRuntime.cpp中,进行了jni映射RuntimeInit.applicationInit()中内部类MethodAndArgsCaller.run运行mMethod.invoke()启动SystemServer.main()
SystemServer.main
4.2 系统服务:由SystemServer.java负责启动和管理整个Java framework中服务startBootstrapServices、startCoreServices、startOtherServices
时序图

边栏推荐
- Achievements in science and Technology (27)
- 基于ssm+jsp框架实现的学生选课信息管理系统【源码+数据库】
- Development skills of rxjs observable custom operator
- Clean up system cache and free memory under Linux
- Android kotlin material design technology points
- 你的 Sleep 服务会梦到服务网格外的 bookinfo 吗
- selenium,元素操作以及浏览器操作方法
- Unity skframework framework (XII), score scoring module
- Three methods of finding LCA of the nearest common ancestor
- How to explain binary search to my sister? This is really difficult, fan!
猜你喜欢

Operation tutorial: how does easydss convert MP4 on demand files into RTSP video streams?

Redis数据库持久化

Common options of tcpdump command: Three

Daily practice of C language --- monkeys divide peaches

运维必备——ELK日志分析系统

伙伴云表格强势升级!Pro版,更非凡!

Can automatically update the universal weekly report template, you can use it with your hand!

Qt-制作一个简单的计算器-实现四则运算

Web Foundation

Chaos engineering platform chaosblade box new heavy release
随机推荐
Drawing Nyquist diagram with MATLAB
Solve "sub number integer", "jump happily", "turn on the light"
Android kotlin broadcast technology point
When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview
uniapp小程序 subPackages分包配置
JS reverse massive creative signature
selenium 在pycharm中安装selenium
Numpy array calculation
JS reverse row query data decryption
Explanation: here is your UFO, Goldbach conjecture
混沌工程平台 ChaosBlade-Box 新版重磅发布
D language, possible 'string plug-ins'
2、 Frame mode MPLS operation
Common options of tcpdump command: Three
为什么switch 的default后面要跟break?
2022 zero code / low code development white paper [produced by partner cloud] with download
Answer: can the audio be set to on by default during easydss video on demand?
SSL证书的分类有哪些?如何选择合适的SSL证书?
[技术发展-22]:网络与通信技术的应用与发展快速概览-2- 通信技术
[OpenGL] notes 29. Advanced lighting (specular highlights)