SystemUI簡介
作為系統(tǒng)應(yīng)用耸弄,SystemUI 包含的內(nèi)容較多,比如狀態(tài)欄卓缰、通知欄计呈、下拉菜單、導(dǎo)航欄征唬、鎖屏捌显、最近任務(wù)、低電提示等系統(tǒng)頁面总寒。在源碼目錄中位于: framework/base/packages 目錄下扶歪, 可見 SystemUI 和 framework 是關(guān)聯(lián)的, SystemUI 依賴了很多內(nèi)部 API 摄闸, 系統(tǒng)資源善镰, SystemUI 編譯是要依賴系統(tǒng)源碼的。
本文介紹的版本為Android11年枕。
編譯和調(diào)試
由于編譯環(huán)境較為苛刻炫欺,所以我直接使用了系統(tǒng)工程師在Linux服務(wù)器上搭建的源碼編譯環(huán)境,應(yīng)用單獨編譯只需要四五分鐘画切,還是比較塊竣稽。編譯之后的目錄位于/system_ext/priv-app/SystemUI/SystemUI.apk,這個目錄和安卓系統(tǒng)里放置系統(tǒng)應(yīng)用的目錄一模一樣霍弹。編譯完從服務(wù)器上把這個應(yīng)用文件拉下來毫别,adb獲取系統(tǒng)root權(quán)限和系統(tǒng)文件讀寫權(quán)限后直接push到對應(yīng)的目錄即可。
快捷面板布局框架
所有和快捷面板相關(guān)的布局都是在StatusBar這個類里面加載的典格,路徑src\com\android\systemui\statusbar\phone\StatusBar.java
onStart()方法是入口岛宦,里面有個createAndAddWindows(result)方法用來加載布局,繼續(xù)追蹤createAndAddWindows(result)->makeStatusBarView()->inflateStatusBarWindow():
private void inflateStatusBarWindow() {
mNotificationShadeWindowView = mSuperStatusBarViewFactory.getNotificationShadeWindowView();
StatusBarComponent statusBarComponent = mStatusBarComponentBuilder.get()
.statusBarWindowView(mNotificationShadeWindowView).build();
mNotificationShadeWindowViewController = statusBarComponent
.getNotificationShadeWindowViewController();
mNotificationShadeWindowController.setNotificationShadeView(mNotificationShadeWindowView);
mNotificationShadeWindowViewController.setupExpandedStatusBar();
mStatusBarWindowController = statusBarComponent.getStatusBarWindowController();
mPhoneStatusBarWindow = mSuperStatusBarViewFactory.getStatusBarWindowView();
mNotificationPanelViewController = statusBarComponent.getNotificationPanelViewController();
}
這里加載了兩個外層布局耍缴,一個是NotificationShadeWindowView砾肺,另一個是PhoneStatusBarWindow。
NotificationShadeWindowView
NotificationShadeWindowView是根布局防嗡,mNotificationShadeWindowView = mSuperStatusBarViewFactory.getNotificationShadeWindowView()变汪,對應(yīng)的layout是super_notification_shade.xml
如下:
<!-- This is the notification shade window. -->
<com.android.systemui.statusbar.phone.NotificationShadeWindowView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:sysui="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<com.android.systemui.statusbar.BackDropView
android:id="@+id/backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
sysui:ignoreRightInset="true">
<ImageView android:id="@+id/backdrop_back"
android:layout_width="match_parent"
android:scaleType="centerCrop"
android:layout_height="match_parent" />
<ImageView android:id="@+id/backdrop_front"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:visibility="invisible" />
</com.android.systemui.statusbar.BackDropView>
<com.android.systemui.statusbar.ScrimView
android:id="@+id/scrim_behind"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:importantForAccessibility="no"
sysui:ignoreRightInset="true"
/>
<include layout="@layout/status_bar_expanded"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible" />
<include layout="@layout/brightness_mirror" />
<com.android.systemui.statusbar.ScrimView
android:id="@+id/scrim_in_front"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:importantForAccessibility="no"
sysui:ignoreRightInset="true"
/>
<LinearLayout
android:id="@+id/lock_icon_container"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/status_bar_height"
android:layout_gravity="top|center_horizontal">
<com.android.systemui.statusbar.phone.LockIcon
android:id="@+id/lock_icon"
android:layout_width="@dimen/keyguard_lock_width"
android:layout_height="@dimen/keyguard_lock_height"
android:layout_gravity="center_horizontal"
android:layout_marginTop="@dimen/keyguard_lock_padding"
android:contentDescription="@string/accessibility_unlock_button"
android:src="@*android:drawable/ic_lock"
android:scaleType="center" />
<com.android.keyguard.KeyguardMessageArea
android:id="@+id/keyguard_message_area"
style="@style/Keyguard.TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/keyguard_lock_padding"
android:gravity="center"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true" />
</LinearLayout>
</com.android.systemui.statusbar.phone.NotificationShadeWindowView>
主要的layout包括:
1.BackDropView
BackDropView backdrop = mNotificationShadeWindowView.findViewById(R.id.backdrop);
mMediaManager.setup(backdrop, backdrop.findViewById(R.id.backdrop_front),
backdrop.findViewById(R.id.backdrop_back), mScrimController, mLockscreenWallpaper);
由NotificationMediaManager來管理,忘問而知這個是處理音視頻相關(guān)的通知蚁趁。
2.ScrimView 狀態(tài)欄下拉后的背景裙盾,半透明灰色。這個view有兩個,一個是背景番官,一個是前景庐完。
3.include進去的brightness_mirror.xml,亮度進度條徘熔。
4.include進去的status_bar_expanded门躯,快捷面板。
5.lock_icon_container 鎖屏布局酷师。
NotificationPanelView
因此主要頁面就集中在status_bar_expanded.xml讶凉,它的代碼如下:
<com.android.systemui.statusbar.phone.NotificationPanelView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:systemui="http://schemas.android.com/apk/res-auto"
android:id="@+id/notification_panel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">
<FrameLayout
android:id="@+id/big_clock_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
<include
layout="@layout/keyguard_status_view"
android:visibility="gone" />
<com.android.systemui.statusbar.phone.NotificationsQuickSettingsContainer
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="@integer/notification_panel_layout_gravity"
android:id="@+id/notification_container_parent"
android:clipToPadding="false"
android:clipChildren="false">
<include layout="@layout/dock_info_overlay" />
<FrameLayout
android:id="@+id/qs_frame"
android:layout="@layout/qs_panel"
android:layout_width="@dimen/qs_panel_width"
android:layout_height="match_parent"
android:layout_gravity="@integer/notification_panel_layout_gravity"
android:clipToPadding="false"
android:clipChildren="false"
systemui:viewType="com.android.systemui.plugins.qs.QS" />
<com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout
android:id="@+id/notification_stack_scroller"
android:layout_marginTop="@dimen/notification_panel_margin_top"
android:layout_width="@dimen/notification_panel_width"
android:layout_height="match_parent"
android:layout_gravity="@integer/notification_panel_layout_gravity"
android:layout_marginBottom="@dimen/close_handle_underlap" />
<include layout="@layout/ambient_indication"
android:id="@+id/ambient_indication_container" />
<include layout="@layout/photo_preview_overlay" />
<ViewStub
android:id="@+id/keyguard_user_switcher"
android:layout="@layout/keyguard_user_switcher"
android:layout_height="match_parent"
android:layout_width="match_parent" />
<include
layout="@layout/keyguard_status_bar"
android:visibility="invisible" />
<Button
android:id="@+id/report_rejected_touch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/status_bar_header_height_keyguard"
android:text="@string/report_rejected_touch"
android:visibility="gone" />
</com.android.systemui.statusbar.phone.NotificationsQuickSettingsContainer>
<include
layout="@layout/keyguard_bottom_area"
android:visibility="gone" />
<com.android.systemui.statusbar.AlphaOptimizedView
android:id="@+id/qs_navbar_scrim"
android:layout_height="96dp"
android:layout_width="match_parent"
android:layout_gravity="bottom"
android:visibility="invisible"
android:background="@drawable/qs_navbar_scrim" />
<include layout="@layout/status_bar_expanded_plugin_frame"/>
</com.android.systemui.statusbar.phone.NotificationPanelView>
此頁面就是快捷面板里的內(nèi)容了,包含的主要布局如下:
1.qs_panel 快捷面板 對應(yīng)的view就是QSFragment山孔。
2.NotificationStackScrollLayout 通知欄
3.NotificationStackScrollLayout
4.其他和鎖屏相關(guān)的就不介紹了
因此最終要修改快捷面板改動QSFragment就行了缀遍。
QSContainerImpl
QSContainerImpl即快捷面板頁面,對應(yīng)的布局為qs_panel.xml饱须,詳細(xì)的加載在QSFragment里面。
qs_panel.xml
<com.android.systemui.qs.QSContainerImpl
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/quick_settings_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:clipChildren="false" >
<!-- Main QS background -->
<View
android:id="@+id/quick_settings_background"
android:layout_width="match_parent"
android:layout_height="0dp"
android:elevation="4dp"
android:background="@drawable/qs_background_primary" />
<!-- Black part behind the status bar -->
<View
android:id="@+id/quick_settings_status_bar_background"
android:layout_width="match_parent"
android:layout_height="@*android:dimen/quick_qs_offset_height"
android:clipToPadding="false"
android:clipChildren="false"
android:background="#ff000000" />
<!-- Gradient view behind QS -->
<View
android:id="@+id/quick_settings_gradient_view"
android:layout_width="match_parent"
android:layout_height="126dp"
android:layout_marginTop="@*android:dimen/quick_qs_offset_height"
android:clipToPadding="false"
android:clipChildren="false"
android:background="@drawable/qs_bg_gradient" />
//快捷面板展開之后的布局
<com.android.systemui.qs.NonInterceptingScrollView
android:id="@+id/expanded_qs_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp"
android:importantForAccessibility="no"
android:layout_weight="1">
<com.android.systemui.qs.QSPanel
android:id="@+id/quick_settings_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:focusable="true"
android:accessibilityTraversalBefore="@android:id/edit">
<include layout="@layout/qs_footer_impl" />
<include layout="@layout/qs_media_divider"
android:id="@+id/divider"/>
</com.android.systemui.qs.QSPanel>
</com.android.systemui.qs.NonInterceptingScrollView>
//快界面版展開之前的布局
<include layout="@layout/quick_status_bar_expanded_header" />
//點擊WiFi或者藍牙彈出的列表詳情
<include android:id="@+id/qs_detail" layout="@layout/qs_detail" />
<include android:id="@+id/qs_customize" layout="@layout/qs_customize_panel"
android:visibility="gone" />
<FrameLayout
android:id="@+id/qs_drag_handle_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:elevation="4dp"
android:paddingBottom="5dp">
<View
android:layout_width="46dp"
android:layout_height="3dp"
android:background="@drawable/qs_footer_drag_handle" />
</FrameLayout>
</com.android.systemui.qs.QSContainerImpl>
PhoneStatusBarWindow
PhoneStatusBarView主要用來顯示系統(tǒng)狀態(tài)台谊、通知等,主要包括 notification icons 和 status bar icons蓉媳。mPhoneStatusBarWindow = mSuperStatusBarViewFactory.getStatusBarWindowView(),對應(yīng)的layout是super_status_bar.xml锅铅,里面包含了一個frameLayout酪呻,最終指向了CollapsedStatusBarFragment,對應(yīng)的布局是status_bar.xml盐须。
下面是PhoneStatusBarView的view 樹形圖: