The System Server in Android
来源:互联网 发布:linux 怎么读 编辑:程序博客网 时间:2024/06/08 02:29
In this post I will add some more detail on the system server in Android. The system server is the core of the Android system and as described in the boot sequence post it is started as soon as Dalvik is initialized and running. The other system services will be running in the context of the System Server process. We will start by looking at the code that runs when the System Server starts. This code is found in the file frameworks/base/services/java/com/android/server/SystemServer.java (in the open source project tree) and we will start this discussion from the main entry point.
/**
* 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) {
// 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);
}
public static final void init2() {
Log.i(TAG, "Entered the Android system server!");
Thread thr = new ServerThread();
thr.setName("android.server.ServerThread");
thr.start();
}
The first thing that happens is that the server will load a native library called android_servers that provides interfaces to native functionality. Source files for this lib are placed in frameworks/base/services/jni/. Then the native init method that will setup native services is called, init1(args), and executed. The name of the function that implements this is system_init() and the it resides in frameworks/base/cmds/system_server/library/system_init.cpp. After setting up the native services there is a callback:
runtime->callStatic("com/android/server/SystemServer", "init2");
to init2() above to create the server thread. This thread will start the remaining services in the system according to the necessary start order. A snippet of the initial sequence gives:
// Critical services...
try {
Log.i(TAG, "Starting Power Manager.");
power = new PowerManagerService();
ServiceManager.addService(Context.POWER_SERVICE, power);
Log.i(TAG, "Starting Activity Manager.");
context = ActivityManagerService.main(factoryTest);
Log.i(TAG, "Starting telephony registry");
ServiceManager.addService("telephony.registry", new TelephonyRegistry(context));
AttributeCache.init(context);
Log.i(TAG, "Starting Package Manager.");
pm = PackageManagerService.main(context,
factoryTest != SystemServer.FACTORY_TEST_OFF);
ActivityManagerService.setSystemProcess();
mContentResolver = context.getContentResolver();
Log.i(TAG, "Starting Content Manager.");
ContentService.main(context,
factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL);
Log.i(TAG, "Starting System Content Providers.");
ActivityManagerService.installSystemProviders();
Log.i(TAG, "Starting Battery Service.");
BatteryService battery = new BatteryService(context);
ServiceManager.addService("battery", battery);
Log.i(TAG, "Starting Hardware Service.");
hardware = new HardwareService(context);
ServiceManager.addService("hardware", hardware);
// only initialize the power service after we have started the
// hardware service, content providers and the battery service.
power.init(context, hardware, ActivityManagerService.getDefault(), battery);
Log.i(TAG, "Starting Alarm Manager.");
AlarmManagerService alarm = new AlarmManagerService(context);
ServiceManager.addService(Context.ALARM_SERVICE, alarm);
...
We see that the power manager is started first, followed by the activity manager and the other services. There are a lot more services started after these initial and if you are interested take look in the SystemServer.java file. Each service is running in a separate Dalvik thread in the SystemServer process. To give some info on the components making up the system server we may have look at it using the DDMS tool:
We see that the main Android services such as the activity manager, package manager, alarm manager etc. are running in their separate threads but as parts of the system server process.
- The System Server in Android
- The System Server in Android
- 转: The System Server in Android
- The Display system related to SurfaceFlinger in Android
- Operating System in the future
- The File System in JOS
- Android system server
- Android的System Server
- android System Server 分析
- Android的System Server
- Building the Android System
- 安装Android Studio结束时提示VT is not enabled in the system
- Calling a method in the system process without a qualified user: android解决方案
- Delivery types in the standard system
- the implementation of system call in linux
- look the files size in linux system
- Workflow in the 2007 Microsoft Office System
- Enumerate the network adaptor in system
- JavaScript—代码优化(一).
- 新的开始
- 为什么C++编译器不能支持对模板的分离式编译_刘未鹏
- VC下遍历文件夹查找文件
- 读高质量C++编程指南
- The System Server in Android
- Servlet生命周期
- The init process and init.rc
- 利用strace诊断程序错误
- My first research experience...and tips
- NTKO Word在线编辑器
- NSString 转换 NSdate
- A closer look at the Android project build system part I
- 对话框中WaitForSingleObject等待线程退出导致程序阻塞的原因及解决