windows server服务器 启动remote servers
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:(对应代码中的序列号)
针对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:从上面我们也可以看出来在这个函数里边,创建了许多的服务,例如ServiceManager,ActivityManagerService,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、服务对象都有自己的异步消息对象,并运行在单独的线程中;
Windows Server 2012 RemoteApp体验-发布RemoteApp程序win2012怎么发布remoteapp
windows server 部署remote app windows server服务器部署
windows2012开启remoteapp功能 remote control windows
Fix Git Remote Write Access to Repository Not Granted: Troubleshooting Guide for Developers
windows服务器redis服务做成开机启动 windows启动redis客户端
windows 10 remote desktopmicrosoft remote desktop
WIN 2012 remoteapp 管理器 windows remote desktop app
Windows Server服务器 SQL Server error 40 windows server服务器能做什么
windows server 2012 usb redirection with remoteFXWINDOWS server 2012