SystemUI之快捷面板的修改

SystemUI简介

作为系统应用,SystemUI 包含的内容较多,比如状态栏、通知栏、下拉菜单、导航栏、锁屏、最近任务、低电提示等系统页面。在源码目录中位于: framework/base/packages 目录下, 可见 SystemUI 和 framework 是关联的, SystemUI 依赖了很多内部 API , 系统资源, SystemUI 编译是要依赖系统源码的。
本文介绍的版本为Android11。

编译和调试

由于编译环境较为苛刻,所以我直接使用了系统工程师在Linux服务器上搭建的源码编译环境,应用单独编译只需要四五分钟,还是比较块。编译之后的目录位于/system_ext/priv-app/SystemUI/SystemUI.apk,这个目录和安卓系统里放置系统应用的目录一模一样。编译完从服务器上把这个应用文件拉下来,adb获取系统root权限和系统文件读写权限后直接push到对应的目录即可。

快捷面板布局框架

所有和快捷面板相关的布局都是在StatusBar这个类里面加载的,路径src\com\android\systemui\statusbar\phone\StatusBar.java
onStart()方法是入口,里面有个createAndAddWindows(result)方法用来加载布局,继续追踪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(),对应的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来管理,忘问而知这个是处理音视频相关的通知。
2.ScrimView 状态栏下拉后的背景,半透明灰色。这个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>

此页面就是快捷面板里的内容了,包含的主要布局如下:
1.qs_panel 快捷面板 对应的view就是QSFragment。
2.NotificationStackScrollLayout 通知栏
3.NotificationStackScrollLayout
4.其他和锁屏相关的就不介绍了
因此最终要修改快捷面板改动QSFragment就行了。

QSContainerImpl

QSContainerImpl即快捷面板页面,对应的布局为qs_panel.xml,详细的加载在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主要用来显示系统状态、通知等,主要包括 notification icons 和 status bar icons。mPhoneStatusBarWindow = mSuperStatusBarViewFactory.getStatusBarWindowView(),对应的layout是super_status_bar.xml,里面包含了一个frameLayout,最终指向了CollapsedStatusBarFragment,对应的布局是status_bar.xml。
下面是PhoneStatusBarView的view 树形图:


image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,569评论 4 363
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,499评论 1 294
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,271评论 0 244
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,087评论 0 209
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,474评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,670评论 1 222
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,911评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,636评论 0 202
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,397评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,607评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,093评论 1 261
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,418评论 2 254
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,074评论 3 237
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,092评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,865评论 0 196
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,726评论 2 276
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,627评论 2 270

推荐阅读更多精彩内容