Android 5.0核心和原始碼學習(3)——SystemServer啟動了什麼服務?
阿新 • • 發佈:2019-02-05
/**入口 * The main entry point from zygote. */ public static void main(String[] args) { new SystemServer().run(); } /** * 幹雜事的執行緒 */ private void run() { // Prepare the main looper thread (this thread). 初始化looper,是不是沒想到looper會被用在此處? android.os.Process.setThreadPriority( android.os.Process.THREAD_PRIORITY_FOREGROUND); android.os.Process.setCanSelfBackground(false); Looper.prepareMainLooper(); // Initialize native services 載入本地服務. System.loadLibrary("android_servers"); nativeInit(); // Check whether we failed to shut down last time we tried.檢測上次關機是否失敗 // This call may not return. performPendingShutdown(); // Initialize the system context. 初始化系統環境 createSystemContext(); // Create the system service manager. 例項化 mSystemServiceManager = new SystemServiceManager(mSystemContext); LocalServices.addService(SystemServiceManager.class, mSystemServiceManager); // Start services. 呼叫下面三方法啟用各種服務 try { startBootstrapServices(); startCoreServices(); startOtherServices(); } catch (Throwable ex) { Slog.e("System", "******************************************"); Slog.e("System", "************ Failure starting system services", ex); throw ex; } } /* 啟動critical級別的服務,他們有複雜的依賴關係,順序不能亂,自己想加服務,去別地 Starts the small tangle of critical services that are needed to get * the system off the ground. These services have complex mutual dependencies * which is why we initialize them all in one place here. Unless your service * is also entwined in these dependencies, it should be initialized in one of * the other functions. */ private void startBootstrapServices(){ //啟動Installer //啟動ActivityManagerService //啟動PowerManagerService //啟動DisplayManagerService //啟動PackageManagerService //啟動UserManagerService } /* 啟動一些關鍵服務*/ private void startCoreServices() { //啟動LightsService //啟動BatteryService //啟動UsageStatsService //啟動WebViewUpdateService } /* 啟動各種各樣的“雜項”服務 有一個關鍵標誌變數 disableNonCoreServices 是否把非核心的服務禁用——————如果是,下面很多服務就不會啟動了 Starts a miscellaneous grab bag of stuff that has yet to be refactored * and organized. */ private void startOtherServices(){ //啟動AccountManagerService 帳號管理 //啟動ContentService 內容管理 //啟動SystemProviders //啟動VibratorService 震動 //啟動ConsumerIrService 遠端控制周邊裝置 //啟動AlarmManagerService 鬧鐘 //啟動Watchdog //啟動WindowManagerService 視窗管理 //啟動InputMethodManagerService 輸入法 //截獲使用者輸入,給一些額外反饋,view的點選、焦點事件分發 //啟動AccessibilityManagerService //啟動MountService 磁碟載入服務 //啟動LockSettingsService 鎖屏、手勢 //啟動PersistentDataBlockService //啟動DevicePolicyManagerService //保證和API8相容 //啟動StatusBarManagerService 狀態列 //啟動ClipboardService 剪下板 //啟動NetworkManagementService 網路管理 //啟動NetworkScoreService //啟動NetworkStatsService 網路統計 //啟動NetworkPolicyManagerService 維護網路使用策略 //啟動WifiService WIFI服務 //啟動ConnectivityService 網路連線狀態 //啟動網路發現服務 //啟動TextServicesManagerService 文字服務,如文字檢查 //啟動UpdateLockService //啟動LocationManagerService 位置 //啟動CountryDetectorService 國家檢測 //啟動SearchManagerService 搜尋 //啟動DropBoxManagerService //啟動WallpaperManagerService 牆紙 //啟動AudioService 音訊 //啟動USB服務 //WiredAccessoryManager 有線接入,耳機之類的 //啟動SerialService 不知道是啥 //啟動TwilightService 指明使用者當前位置是否為晚上,配合調整夜間模式 //啟動UiModeManagerService 介面模式 //啟動JobSchedulerService 任務排程 //啟動BackupManagerService 備份 //啟動APPWIDGET_SERVICE 視窗小部件管理 //啟動VOICE_RECOGNITION_MANAGER_SERVICE 聲音重置服務 //啟動DiskStatsService 硬碟統計服務 //啟動NetworkTimeUpdateService 網路時間更新服務 //啟動CommonTimeManagementService 時間管理服務 //啟動DreamManagerService 螢幕保護 //負責將預載入的bitmap組裝成紋理貼圖,生成的紋理貼圖可以被用來跨程序使用,以減少記憶體 //啟動AssetAtlasService //啟動列印服務 //RestrictionsManagerService ? //MediaSessionService ? //HdmiControlService HDMI服務 //TvInputManagerService TV輸入管理 //MediaRouterService ? //TrustManagerService 信任管理 //FingerprintService 指紋 //BackgroundDexOptService ? //LauncherAppsService //MediaProjectionManagerService //如果“安全” ,禁用JIT編譯模式,不安全則開啟JIT 何為安全???? // VMRuntime.getRuntime().disableJitCompilation() //MmsServiceBroker ? //接下來啟動各種APP,省略…… } static final void startSystemUi(Context context) {} //啟動系統UI