android10 SystemUI源码梳理-1

SystemUI是以应用的形式运行是一个持久进程,它为系统提供 UI,包括状态栏、通知栏、
音量、快捷设置、锁屏界面等。但位于 system_server 进程之外(frameworks/base/packages/SystemUI)

SystemUI 启动

frameworks/base/services/core/java/com/android/server/SystemServer.java

SystemUI是在 ActivityManagerService 回调后启动

mActivityManagerService.systemReady(() -> {
....
  ​​​​​​try {
    startSystemUi(context, windowManagerF);
} catch (Throwable e) {
    reportWtf("starting System UI", e);
}
})
static final void startSystemUi(Context context, WindowManagerService windowManager) {
    Intent intent = new Intent();
    //启动标记
    intent.setComponent(new ComponentName("com.android.systemui",
                "com.android.systemui.SystemUIService"));
    intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING);
  //以系统身份启动服务
    context.startServiceAsUser(intent, UserHandle.SYSTEM);
//通知 windowManager
    windowManager.onSystemUiStarted();
}

SystemUIService.java
public class SystemUIService extends Service {

    @Override
    public void onCreate() {
        super.onCreate();
       //启动其他配套的service
        ((SystemUIApplication) getApplication()).startServicesIfNeeded();

SystemUIApplication.java

启动所有子系统ui->SystemUI

public void startServicesIfNeeded() {

        String[] names =                             getResources().getStringArray(R.array.config_systemUIServiceComponents);         startServicesIfNeeded(names);

}

config.xml

//SystemUI Services
<string-array name="config_systemUIServiceComponents" translatable="false"> <item>com.android.systemui.Dependency$DependencyCreator</item> <item>com.android.systemui.util.NotificationChannels</item> <item>com.android.systemui.statusbar.CommandQueue$CommandQueueStart</item> <item>com.android.systemui.keyguard.KeyguardViewMediator</item> <item>com.android.systemui.recents.Recents</item> <item>com.android.systemui.volume.VolumeUI</item> <item>com.android.systemui.stackdivider.Divider</item> <item>com.android.systemui.SystemBars</item> <item>com.android.systemui.usb.StorageNotification</item> <item>com.android.systemui.power.PowerUI</item>
        ......

SystemUIApplication.java
private void startServicesIfNeeded(String[] services) {

    mServices = new SystemUI[services.length];

    final int N = services.length;
    for (int i = 0; i < N; i++) {
        String clsName = services[i];
        Class cls;
        //实例化对象
        try {
            cls = Class.forName(clsName);
            Object o = cls.newInstance();
            if (o instanceof SystemUI.Injector) {
                o = ((SystemUI.Injector) o).apply(this);
            }
            mServices[i] = (SystemUI) o;

        mServices[i].mContext = this;
        mServices[i].mComponents = mComponents;
        //开始调用
        mServices[i].start();
    }
        .......

以SystemBars为例

SystemBars.java

public class SystemBars extends SystemUI {

    @Override
    public void start() {
        createStatusBarFromConfig();
    }
private void createStatusBarFromConfig() {

//指向另一个实体类_com.android.systemui.statusbar.phone.StatusBar
    final String clsName = mContext.getString(R.string.config_statusBarComponent);
    Class<?> cls = null;
//获取实例
    try {
        cls = mContext.getClassLoader().loadClass(clsName);
    }
    try {
        mStatusBar = (SystemUI) cls.newInstance();
    }
    mStatusBar.mContext = mContext;
    mStatusBar.mComponents = mComponents;
    if (mStatusBar instanceof StatusBar) {
        SystemUIFactory.getInstance().getRootComponent()
                .getStatusBarInjector()
                .createStatusBar((StatusBar) mStatusBar);
    }
    //开始启动
    mStatusBar.start();
    if (DEBUG) Log.d(TAG, "started " + mStatusBar.getClass().getSimpleName());
}
        ........
StatusBar.java
@Override
public void start() {
    mGroupManager = Dependency.get(NotificationGroupManager.class);
    mGroupAlertTransferHelper = Dependency.get(NotificationGroupAlertTransferHelper.class);
    mVisualStabilityManager = Dependency.get(VisualStabilityManager.class);
    mNotificationLogger = Dependency.get(NotificationLogger.class);
        ....内容很多只看视图相关的
//获取屏幕大小
updateDisplaySize();
.......
RegisterStatusBarResult result = null;
//mBarService 是一个接口文件aidl 
//注册这个接口文件
try {
    result = mBarService.registerStatusBar(mCommandQueue);
} catch (RemoteException ex) {
    ex.rethrowFromSystemServer();
}
//创建视图
createAndAddWindows(result);
.....

createAndAddWindows

public void createAndAddWindows(@Nullable RegisterStatusBarResult result) {
    //开始构建状态栏视图
    makeStatusBarView(result);
//获取状态栏的处理类
    mStatusBarWindowController = Dependency.get(StatusBarWindowController.class);

//getStatusBarHeight()添加状态栏高度 默认24
//<dimen name="status_bar_height">@dimen/status_bar_height_portrait</dimen>
//<dimen name="status_bar_height_portrait">24dp</dimen>

    mStatusBarWindowController.add(mStatusBarWindow, getStatusBarHeight());
}

mStatusBarWindowController.add

public void add(ViewGroup statusBarView, int barHeight) {
.......
//状态栏添加到window
    mWindowManager.addView(mStatusBarView, mLp);
}
makeStatusBarView
protected void makeStatusBarView(@Nullable RegisterStatusBarResult result) {
    final Context context = mContext;
 //再次更新屏幕尺寸
    updateDisplaySize(); // populates mDisplayMetrics
//再次更新资源
    updateResources();
//主题明暗更新
    updateTheme();
//创建通知状态栏视图
    inflateStatusBarWindow(context);
//当前对象传递,同时创建一个DragDownHelper
//DragDownHelper->是一个用于处理用户向下拖动手势的辅助类。它通常被用在需要对用户的向下拖动手势进行检测和处理的场景,比如通知栏的下拉、锁屏界面的下拉动作等
    mStatusBarWindow.setService(this);
.....
//获取通知栏视图
inflateShelf();
....
//创建导航栏
createNavigationBar(result);
.....

updateResources

void updateResources() {
    // Update the quick setting tiles
    if (mQSPanel != null) {
        //快速设置更新
        mQSPanel.updateResources();
    }
     //statusBar高度更新
    loadDimens();

    if (mStatusBarView != null) {
        //phoneStatusbarVIew更新
        mStatusBarView.updateResources();
    }
    if (mNotificationPanel != null) {
//通知栏更新
        mNotificationPanel.updateResources();
    }
    if (mBrightnessMirrorController != null) {
//屏幕亮度更新
        mBrightnessMirrorController.updateResources();
    }
}

inflateStatusBarWindow

protected void inflateStatusBarWindow(Context context) {
//通过dagger动态注入视图
    mStatusBarWindow = (StatusBarWindowView) mInjectionInflater.injectable(
    LayoutInflater.from(context)).inflate(R.layout.super_status_bar, null);
}
inflateShelf
private void inflateShelf() {
//获取通知栏视图
    mNotificationShelf =
            (NotificationShelf) LayoutInflater.from(mContext).inflate(
                    R.layout.status_bar_notification_shelf, mStackScroller, false);
    mNotificationShelf.setOnClickListener(mGoToLockedShadeListener);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值