当前位置:首页 > CN2资讯 > 正文内容

windows server服务器 启动remote servers

9小时前CN2资讯



 

SystemServer启动服务


一、SystemServer.java/main()函数 2

二、run()函数 3

三、SystemServer进程启动的服务类型 6

3.1、startBootstrapServices() 6

3.2、startCoreServices() 8

3.3、startOtherServices() 9

总结: 10


在上一篇文档中,已经分析过了system_server进程是如何创建的。它是通过zygote进程通过fork()函数创建;由handleSystemProcess()去履行它的职责。主要通过以下四个方法: 

redirectLogStreams();   //重定向标准I/O操作

commonInit();         //初始化一些通用的设置

nativeZygoteInit();      //开启Binder通信applicationInit(targetSdkVersion, argv, classLoader); //虚拟机设置并转换参数

注意在zygoteinit函数里面它会抛出一个异常MethodAndArgsCaller;另外捕获这个异常是在main()函数中实现,并从此处开始进入java层(这个main函数会启动一系列服务)。

MethodAndArgsCaller比较特殊,它既是一个异常类也是一个线程;当捕获到这个异常之后,都会执行它的run()方法。

 

下面我们先来看看在它的main()方法中到底做了些什么工作?

先放上一张概括图吧~

 

                  图1.1.

一、SystemServer.java/main()函数

/** * The main entry point from zygote. */ public static void main(String[] args) { new SystemServer().run(); }

 

Note:从它的注释中也可以看出来,它是zygote进程的一个入口函数。main()函数也很简单,这里它只是简单的new出一个Systemserver的对象,并且调用run()方法。注意SystemServer类是final类型的,因此它不会被继承或者重写。

二、run()函数

private void run() { try { ........ //1、设置系统的的语言 if (!SystemProperties.get("persist.sys.language").isEmpty()) { final String languageTag = Locale.getDefault().toLanguageTag(); SystemProperties.set("persist.sys.locale", languageTag); SystemProperties.set("persist.sys.language", ""); SystemProperties.set("persist.sys.country", ""); SystemProperties.set("persist.sys.localevar", ""); } // Here we go! Slog.i(TAG, "Entered the Android system server!"); EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN, SystemClock.uptimeMillis()); SystemProperties.set("persist.sys.dalvik.vm.lib.2", VMRuntime.getRuntime().vmLibrary()); 2、Enable the sampling profiler.进程性能统计 if (SamplingProfilerIntegration.isEnabled()) { SamplingProfilerIntegration.start(); mProfilerSnapshotTimer = new Timer(); mProfilerSnapshotTimer.schedule(new TimerTask() { @Override public void run() { SamplingProfilerIntegration.writeSnapshot("system_server", null); } }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL); } //3、 Mmmmmm... more memory!设置虚拟机运行内存 VMRuntime.getRuntime().clearGrowthLimit(); VMRuntime.getRuntime().setTargetHeapUtilization(0.8f); Build.ensureFingerprintProperty(); Environment.setUserRequired(true); Bundle.setShouldDefuse(true); ............ // Initialize native services. System.loadLibrary("android_servers");//加载运行库 // 4、Create the system service manager. mSystemServiceManager = new SystemServiceManager(mSystemContext); LocalServices.addService(SystemServiceManager.class, mSystemServiceManager); } } // 5、Start services. 开启服务 try { Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartServices"); startBootstrapServices();//boot服务 startCoreServices(); //core服务 startOtherServices(); //其他服务 } ......... }

Note:(对应代码中的序列号)

  • 这里通过SystemProperties类去读取系统的属性。这个语句的逻辑也比较简单,主要是去设置系统语言的环境。这些属性最后都会被init进程在它们对应的动作列表或者是服务列表中检测到,并且调用相对应的函数去执行。
     
  • 系统中很多进程都需要通过SamplingProfilerIntegration去统计性能。
     
  • 通过VMRuntime去设置虚拟机的运行内存。
     
  • 创建SystemServerManager对象,它是管理SystemServer进程即将创建出来的服务的管理对象。
     
  • 开启服务,这也是此篇文档想要阐述的重点内容。SystemServer服务类型大致分成这三类:boot服务、core服务、其他服务。
     
    针对boot/core/其他服务,下面我们依次分析这三个方法        startBootstrapServices();//boot服务
    startCoreServices();  //core服务
    startOtherServices(); //其他服务
     
  • 三、SystemServer进程启动的服务类型

    3.1、startBootstrapServices()

    private void startBootstrapServices() { //Installer类,该类是系统安装apk时的一个服务类,该类是系统安装apk时的一个服务类 Installer installer = mSystemServiceManager.startService(Installer.class); /// M: ANR mechanism for Message Monitor Service @{ if (!IS_USER_BUILD) { try { MessageMonitorService msgMonitorService = null; msgMonitorService = new MessageMonitorService(); Slog.e(TAG, "Create message monitor service successfully ."); // Add this service to service manager ServiceManager.addService(Context.MESSAGE_MONITOR_SERVICE, msgMonitorService.asBinder()); } catch (Throwable e) {... } } // Activity manager runs the show. mActivityManagerService = mSystemServiceManager.startService( ActivityManagerService.Lifecycle.class).getService(); mActivityManagerService.setSystemServiceManager(mSystemServiceManager); mActivityManagerService.setInstaller(installer); 需要提前启动电源管理器,因为其他服务需要它。 mPowerManagerService = mSystemServiceManager.startService(PowerManagerService.class); // Now that the power manager has been started, let the activity manager // initialize power management features.初始化 mActivityManagerService.initPowerManagement(); Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); // 管理发光二极管和显示背光,我们需要它来显示显示器 mSystemServiceManager.startService(LightsService.class); // Display manager is needed to provide display metrics before package manager // starts up. mDisplayManagerService = mSystemServiceManager.startService(DisplayManagerService.class); ................ // Start the package manager. traceBeginAndSlog("StartPackageManagerService"); mPackageManagerService = PackageManagerService.main(mSystemContext, installer, mFactoryTestMode != FactoryTest.FACTORY_TEST_OFF, mOnlyCore); mFirstBoot = mPackageManagerService.isFirstBoot(); mPackageManager = mSystemContext.getPackageManager(); Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); mPackageManagerService.onAmsAddedtoServiceMgr(); startSensorService(); }

    Note:从上面我们也可以看出来在这个函数里边,创建了许多的服务,例如ServiceManagerActivityManagerService,PackageManagerService,DisplayManagerService,PowerManagerService,LightsService等。其中,

     

       ServiceManager是系统服务管理对象。

    ActivityManagerService是系统中一个非常重要的服务,它是Activity,service,Broadcast,contentProvider都需要通过其余系统交互。

    PowerManagerService主要用于计算系统中和Power相关的计算,然后决策系统应该如何反应。同时协调Power如何与系统其它模块的交互,比如没有用户活动时,屏幕变暗等等。

    LightsService服务主要是手机中关于闪光灯,LED等相关的服务;也是会调用LightsService的构造方法和onStart方法。

    DisplayManagerService服务主要是手机显示方面的服务。

    PackageManagerService服务是android系统中一个比较重要的服务,包括多apk文件的安装,解析,删除,卸载等操作。

    3.2、startCoreServices()

    * * Starts some essential services that are not tangled up in the bootstrap process. */ private void startCoreServices() { // Tracks the battery level. Requires LightService. BatteryService.class); // Tracks application usage stats. UsageStatsService.class); mActivityManagerService.setUsageStatsManager( LocalServices.getService(UsageStatsManagerInternal.class)); // Tracks whether the updatable WebView is in a ready state and watches for update installs. WebViewUpdateService.class); }

    Note:从开头的注释过程中可以看出来这个方法主要是启动一些不在引导过程中纠缠不清的基本服务。比如说:BatteryService、UsageStatsService、WebViewUpdateService。

     

    BatteryService:电池相关服务

    UsageStatsService:这是一个Android私有service,主要作用是收集用户使用每一个APP的频率、使用时常。

    WebViewUpdateService:这个服务主要用于更新webView

    3.3、startOtherServices()

    private void startOtherServices() { VibratorService vibrator = null; IMountService mountService = null; NetworkManagementService networkManagement = null; NetworkStatsService networkStats = null; NetworkPolicyManagerService networkPolicy = null; ConnectivityService connectivity = null; NetworkScoreService networkScore = null; NsdService serviceDiscovery= null; WindowManagerService wm = null; SerialService serial = null; NetworkTimeUpdateService networkTimeUpdater = null; CommonTimeManagementService commonTimeMgmtService = null; InputManagerService inputManager = null; TelephonyRegistry telephonyRegistry = null; ConsumerIrService consumerIr = null; MmsServiceBroker mmsService = null; HardwarePropertiesManagerService hardwarePropertiesService = null; MtkHdmiManagerService hdmiManager = null; RunningBoosterService runningbooster = null; ......... }

    Note:从上面的代码可以看出来,这个方法启动的服务不是一般的多。

    总结:

    1、SystemServer进程是android中一个很重要的进程由Zygote进程启动;

    2、SystemServer进程主要用于启动系统中的服务;

    3、SystemServer进程启动服务的启动函数为main函数;

    4、SystemServer在执行过程中首先会初始化一些系统变量,加载类库,创建Context对象,创建SystemServiceManager对象等之后才开始启动系统服务;

    5、SystemServer进程将系统服务分为三类:boot服务,core服务和other服务,并逐步启动;

    6、SertemServer进程在尝试启动服务之前会首先尝试与Zygote建立socket通讯,只有通讯成功之后才会开始尝试启动服务;

    7、创建的系统服务过程中主要通过SystemServiceManager对象来管理,通过调用服务对象的构造方法和onStart方法初始化服务的相关变量;

    8、服务对象都有自己的异步消息对象,并运行在单独的线程中;

     

     

     

      你可能想看:

      扫描二维码推送至手机访问。

      版权声明:本文由皇冠云发布,如需转载请注明出处。

      本文链接:https://www.idchg.com/info/30537.html

      分享给朋友:

      “windows server服务器 启动remote servers” 的相关文章

      如何高效购买服务器?全面指南助你轻松选择最佳配置

      在决定购买服务器之前,做好充分的准备是至关重要的。服务器的选择直接影响企业的运营效率和未来发展,因此我们需要从多个角度进行考量。 确定企业需求 企业的需求是选择服务器的核心依据。我们需要明确服务器的主要用途,比如是用于数据存储、网站托管,还是进行大规模计算。不同的应用场景对服务器的性能要求差异很大。...

      Linode云服务详解:高效、可靠的VPS解决方案

      在云计算领域,Linode无疑是一颗冉冉升起的星星。作为一家成立于2003年的美国VPS(虚拟专用服务器)提供商,Linode专注于打造高效、易用的云服务,涵盖虚拟专用服务器以及多种相关服务。其创始人Christopher S. Aker的愿景是让每个人都能通过简单、可靠的方式利用强大的计算能力。而...

      AWS注册教程:轻松创建你的AWS账户

      在当今数字化时代,云计算的广泛应用早已成为一种趋势。在这种背景下,AWS(亚马逊网络服务)以其强大的技术和丰富的服务,逐渐成为许多人选择的云平台。那么,AWS到底是什么呢?简单来说,它是一个全面的云服务平台,提供包括计算能力、存储选项、数据库、机器学习等各种服务。我一直认为,AWS之所以能够在众多云...

      DigitalOcean与Vultr的全面比较与选择建议

      DigitalOcean与Vultr概述 1.1 DigitalOcean简介 DigitalOcean成立于2012年,总部位于美国纽约,这家公司一开始就定位于为开发者提供高效的云计算服务。最初的目标是简化云计算,让更多人能够轻松使用这一新兴技术。随着时间的推移,DigitalOcean不断扩展其...

      深度解析韩国makemodel:传统与现代结合的时尚理念

      markdown格式的内容 韩国makemodel概念 谈到韩国makemodel,我首先感受到了它所传递的深厚文化底蕴。这一时尚理念融合了传统与现代,不仅仅是对衣物的设计,更是一种对韩国文化的致敬。它通过巧妙的配搭,将历史悠久的韩服元素与现代流行趋势相结合,创造出一种独特的美学风格。每一件作品都像...

      探索韩国VPS服务:选择高性能低延迟的虚拟专用服务器

      在数字化迅猛发展的今天,韩国的VPS(虚拟专用服务器)越来越受到用户的青睐。许多企业和个人用户都开始关注这个区域,特别是那些需要稳定网站和应用程序的人。这篇文章将为你深入探讨韩国VPS的市场需求和背景,以及它在不同场景中的适用性。 首先,韩国VPS市场的兴起与其优越的网络基础设施密不可分。韩国位于东...