“Everything you see in Android that's not an app”
SystemUI
“那些你在Android中看到的,但不是一個應用的東西”
SystemUI是一個持續運行的進程,它為系統提供UI但不屬于系統服務進程。
大多數SystemUI代碼的起點都是繼承了SystemUI 的一系列服務,這些服務被SystemUIApplication啟動。這些服務隨后由Dependency來提供一些自定義的依賴注入。
與通常的監聽器不同,針對SystemUI的輸入通常來自于IStatusBar。來自SystemUI的輸出則通過一系列的私有API發送到Android平臺的各個角落。
SystemUIApplication
SystemUIApplication啟動時,會啟動配置文件config_systemUIServiceComponents和config_systemUIServiceComponentsPerUser中列出的服務。
這些服務中的每一個都繼承了SystemUI。SystemUI為它們提供了一個上下文對象Context,也提供了配置改變時的回調(由于歷史原因,這是onConfigurationChanged的主路徑,現在也會發生在ConfigurationController中)。由于這些服務可能在系統啟動完成前啟動,所以它們也會接收到系統啟動完成的回調。
SystemUI和SystemUIApplication也提供了方法來設置組件putComponent和獲取組件getComponent, 這樣現有的系統在依賴產生前就可以持有其他SystemUI組件。通常新的組件不應該被添加到putComponent中,相反地,推薦的方式是Dependency或其他的重構,這樣可以保持SystemUI架構的簡潔。
每一個SystemUI的服務都是SystemUI的主要部分,目標是最小化服務之間的交互。所以,通常服務要相對地職責單一。
Dependencies
起一個被啟動的SystemUI服務,應該是一個依賴項Dependency。Dependency提供了一個靜態方法來獲取跨越SystemUI生命周期的依賴項。Dependency提供了代碼,用于創建所有手動添加的依賴項。SystemUIFactory也能夠添加和替換這些依賴項。
依賴項是懶加載的,所以如果一個依賴項從未在運行時被引用,它永遠不會被創建。
如果一個實例化的依賴實現了Dumpable接口,它會被加入到SystemUI(和bug報告)的轉儲中,允許它使用當前的狀態信息。這就是控制器轉存信息到bug報告中的方式。
如果一個實例化的依賴項實現了配置更改接收器ConfigurationChangeReceiver接口,它會在配置信息更改時接收到配置信息更改onConfigurationChange的回調。
IStatusBar
命令隊列是接收所有來自系統服務輸入事件的對象。它繼承了IStatusBar,并且把這些回調信息分發回任意數量的監聽器。當StatusBar調用注冊方法IStatusBarService#registerStatusBar時,系統服務system_server會持有對應的IStatusBar,所以如果StatusBar沒有被引入到XML服務列表中,它將不會被系統注冊。
命令隊列把所有輸入回調發送到一個處理器中,然后分發這些信息到每一個當前已經注冊的回調中。命令隊列也會追蹤關閉標簽的當前值,對于任何添加的回調,都會立刻調用關閉#disable方法。
有一些地方命令隊列被用做一個總線,來負責跨SystemUI的交互。比如當StatusBar調用命令隊列的重算關閉標簽方法CommandQueue#recomputeDisableFlags.通常,這通常是一種觸發命令隊列CommandQueue的快捷方式,而不是調用StatusManager然后等待調用回到IStatusBar。
Default SystemUI services list
com.android.systemui.Dependency
提供自定義的依賴注入。
com.android.systemui.util.NotificationChannels
創建或初始化SystemUI頻道,用于發送通知。
com.android.systemui.statusbar.CommandQueue$CommandQueueStart
Creates CommandQueue and calls putComponent because its always been there and sysui expects it to be there :/
com.android.systemui.keyguard.KeyguardViewMediator
Manages keyguard view state.
com.android.systemui.recents.Recents
Recents tracks all the data needed for recents and starts/stops the recents activity. It provides this cached data to RecentsActivity when it is started.
com.android.systemui.volume.VolumeUI
Registers all the callbacks/listeners required to show the Volume dialog when it should be shown.
com.android.systemui.stackdivider.Divider
Shows the drag handle for the divider between two apps when in split screen mode.
com.android.systemui.SystemBars
This is a proxy to the actual SystemUI for the status bar. This loads from config_statusBarComponent which defaults to StatusBar. (maybe this should be removed and copy how config_systemUiVendorServiceComponent works)
com.android.systemui.status.phone.StatusBar
This shows the UI for the status bar and the notification shade it contains. It also contains a significant amount of other UI that interacts with these surfaces (keyguard, AOD, etc.). StatusBar also contains a notification listener to receive notification callbacks.
com.android.systemui.usb.StorageNotification
Tracks USB status and sends notifications for it.
com.android.systemui.power.PowerUI
Tracks power status and sends notifications for low battery/power saver.
com.android.systemui.media.RingtonePlayer
Plays ringtones.
com.android.systemui.keyboard.KeyboardUI
Shows UI for keyboard shortcuts (triggered by keyboard shortcut).
com.android.systemui.pip.PipUI
Shows the overlay controls when Pip is showing.
com.android.systemui.shortcut.ShortcutKeyDispatcher
Dispatches shortcut to System UI components.
@string/config_systemUIVendorServiceComponent
Component allowing the vendor/OEM to inject a custom component.
com.android.systemui.util.leak.GarbageMonitor$Service
Tracks large objects in sysui to see if there are leaks.
com.android.systemui.LatencyTester
Class that only runs on debuggable builds that listens to broadcasts that simulate actions in the system that are used for testing the latency.
com.android.systemui.globalactions.GlobalActionsComponent
Shows the global actions dialog (long-press power).
com.android.systemui.ScreenDecorations
Draws decorations about the screen in software (e.g. rounded corners, cutouts).
com.android.systemui.biometrics.BiometricDialogImpl
Biometric UI.