当前位置:网站首页>Systemserver process
Systemserver process
2022-07-02 13:57:00 【xhBruce】
SystemServer process
android12-release
Android The system starts
Zygote process
Zygote process fork And come
init process -> Zygote process -> system_server process
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 The process parameter information is uid=1000,gid=1000, The process name is
sytem_server
Zygote.forkSystemServer()
fork Outsystem_server process
com_android_internal_os_Zygote_nativeForkSystemServer
JNIzygote::ForkCommon()
Call tofork()
Create a new process , use copy on write The way , This is a linux Standard method for creating processes , There will be two return. The return value is 3 Types : In parent process ,fork Returns the... Of the newly created child process pid; In subprocess ,fork return 0; When an error occurs ,fork Return negative .
When system_server After the process dies , restart zygote process .New creation system_server The process is complete ,
pid == 0
Then enterhandleSystemServerProcess() Method
handleSystemServerProcess
fork()
Here we are system_server The process has completed all the work created , Here we go system_server The real work of the process
handleSystemServerProcess(parsedArgs)
complete system_server Process remaining work , Running on thesystem_server process
Process.setArgV0(parsedArgs.mNiceName)
Current process name "system_server"performSystemServerDexOpt()
perform dex Optimize operation , frominstalld
To complete- system_server perform
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()
stay AndroidRuntime.cpp in , the jni mappingRuntimeInit.applicationInit()
Meso endomorph MethodAndArgsCaller.run functionmMethod.invoke()
start-up SystemServer.main()
SystemServer.main
4.2 system service : from SystemServer.java Be responsible for starting and managing the whole Java framework In the service startBootstrapServices、startCoreServices、startOtherServices
Sequence diagram
边栏推荐
- Origin绘制热重TG和微分热重DTG曲线
- [youcans' image processing learning course] general contents
- Qt新项目_MyNotepad++
- On flow delivery between microservices
- Android kotlin broadcast technology point
- [usaco05jan]watchcow s (Euler loop)
- D为何链接不了dll
- What are eNB, EPC and PGW?
- ArrayList and LinkedList
- When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview
猜你喜欢
When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview
uniapp小程序 subPackages分包配置
错误:EACCES:权限被拒绝,访问“/usr/lib/node_modules”
Sum of the first n terms of Fibonacci (fast power of matrix)
Codeforces Round #803 (Div. 2)(A~D)
(POJ - 1984) navigation nightare (weighted and search set)
2022 Heilongjiang provincial examination on the writing skills of Application Essays
题解:《你的飞碟在这儿》、《哥德巴赫猜想》
无主灯设计:如何让智能照明更加「智能」?
Tupang multi-target tracking! BOT sort: robust correlated multi pedestrian tracking
随机推荐
刚好1000粉丝,记录一下
Find love for speed in F1 delta time Grand Prix
Selenium element positioning method
使用BLoC 构建 Flutter的页面实例
Slashgear shares 2021 life changing technology products, which are somewhat unexpected
Codeforces Round #803 (Div. 2)(A~D)
路由(二)
Explanation: here is your UFO, Goldbach conjecture
How to set QT manual layout
题解:《你的飞碟在这儿》、《哥德巴赫猜想》
Performance optimization of memory function
MySQL45讲——学习极客时间MySQL实战45讲笔记—— 05 | 深入浅出索引(下)
浏览器驱动的下载
On flow delivery between microservices
I did it with two lines of code. As a result, my sister had a more ingenious way
Node.js通过ODBC访问PostgreSQL数据库
Selenium, element operation and browser operation methods
默认插槽,具名插槽,作用域插槽
Qt入门-制作一个简易的计算器
selenium 元素定位方法