博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
The System Server in Android
阅读量:2342 次
发布时间:2019-05-10

本文共 4642 字,大约阅读时间需要 15 分钟。

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.

转载地址:http://yhfvb.baihongyu.com/

你可能感兴趣的文章
使用开源工具SeleniumRC进行功能测试
查看>>
Selenium实战:.Net下的自动化测试搭建(WebDriver)
查看>>
Selenium 中文API
查看>>
IOS介绍及开发准备工作
查看>>
iPhone开发环境介绍
查看>>
IOS开发环境配置指南
查看>>
基于PhoneGap的iOS平台入门教程
查看>>
移动开发的未来将是PhoneGap的
查看>>
跨平台开发:初探PhoneGap移动开发框架
查看>>
基于PhoneGap的Windows Phone平台环境搭建教程
查看>>
在Eclipse下搭建Android开发环境教程
查看>>
关于搭建基于Android和PhoneGap开发环境图文详解
查看>>
基于PhoneGap的Android应用开发:Get started
查看>>
Dreamweaver 5.5、jQuery和PhoneGap开发移动应用
查看>>
详解关于PhoneGap框架学习教程
查看>>
基于PhoneGap与Java开发的Android应用的性能对比
查看>>
VS2010中使用ankhSVN
查看>>
C#使用 Salt + Hash 来为密码加密
查看>>
Visual Studio.net 配套开发工具
查看>>
WCF4 Rest Service及Entity Framework with POCO之旅
查看>>