当前位置:网站首页>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
边栏推荐
- P1347 排序(拓扑 + spfa判断环 or 拓扑[内判断环])
- Runhe hi3516 development board openharmony small system and standard system burning
- Performance optimization of memory function
- Why is the default of switch followed by break?
- Use bloc to build a page instance of shutter
- ensp简单入门
- 石子合并板子【区间DP】(普通石子合并 & 环形石子合并)
- selenium,元素操作以及浏览器操作方法
- Partner cloud form strong upgrade! Pro version, more extraordinary!
- Use of UIC in QT
猜你喜欢
【虹科技术分享】如何测试 DNS 服务器:DNS 性能和响应时间测试
Use bloc to build a page instance of shutter
题解:《你的飞碟在这儿》、《哥德巴赫猜想》
Node.js通过ODBC访问PostgreSQL数据库
The global special paper revenue in 2021 was about $27 million, and it is expected to reach $35 million in 2028. From 2022 to 2028, the CAGR was 3.8%
自定义事件,全局事件总线,消息订阅与发布,$nextTick
Qt新项目_MyNotepad++
When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview
Error function ERF
Qt-制作一个简单的计算器-实现四则运算-将结果以对话框的形式弹出来
随机推荐
selenium的特点
石子合并板子【区间DP】(普通石子合并 & 环形石子合并)
Halcon extract orange (Orange)
I did it with two lines of code. As a result, my sister had a more ingenious way
Integral link, inertia link and proportion link in Simulink
Download files and preview pictures
Android kotlin broadcast technology point
不会看器件手册的工程师不是个好厨子
(POJ - 1984) navigation nightare (weighted and search set)
代码实现MNLM
[Unity]使用GB2312,打包后程序不正常解决方案
当贝投影4K激光投影X3 Pro获得一致好评:万元投影仪首选
Mysql5.7 installation super easy tutorial
Selenium element positioning method
When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview
[technology development-22]: rapid overview of the application and development of network and communication technology-2-communication Technology
mysql ---- Oracle中的rownum转换成MySQL
Unity skframework framework (XII), score scoring module
c# 水晶报表打印
Just 1000 fans, record it