SystemUI 启动分析

参考:

1、Android 9.0系统源码_SystemUI(一)SystemUI的启动流程

(1)启动SystemUiService SystemServer.startOtherservice() --- startSystemUI()

(2)在 SystemUIService 中启动 SystemUI 所需的各种组件

public class SystemUIService extends Service {

    @Override
    public void onCreate() {
        super.onCreate();    
     ((SystemUIApplication)getApplication()).startServicesIfNeeded();
    }
  }

 

2、Android 9.0系统源码_SystemUI(二)StatusBar系统状态栏的创建流程

(1)SystemBars创建

在SystemUI启动过程中会创建SystemBars <item>com.android.systemui.SystemBars</item

com.android.systemui.SystemBars创建整个SystemUI视图的入口类,它被启动时会调用 start() 方法,先看下该类的 start() 方法:

public class SystemBars extends SystemUI {
     ...
    @Override
    public void start() {
        createStatusBarFromConfig();//通过配置创建系统状态栏
    }
    ...
   private void createStatusBarFromConfig() {
      final String clsName = mContext.getString(R.string.config_statusBarComponent);//获取系统状态栏对应类的全路径
      Class<?> cls =  mContext.getClassLoader().loadClass(clsName);//加载对应的类对象
      mStatusBar = (SystemUI) cls.newInstance();//通过反射创建实例对象
      mStatusBar.mContext = mContext;
      mStatusBar.mComponents = mComponents;
      mStatusBar.start();//调用系统状态栏的start方法
  }

(2)StatusBar创建

通过SystemBars.start()方法,反射创建出具体的StatusBar对象实例,最后调用StatusBar的start()方法。

public class StatusBar extends SystemUI implements DemoMode,
        DragDownHelper.DragDownCallback, ActivityStarter, OnUnlockMethodChangedListener,
        OnHeadsUpChangedListener, CommandQueue.Callbacks, ZenModeController.Callback,
        ColorExtractor.OnColorsChangedListener, ConfigurationListener, NotificationPresenter {
     ...
    @Override
    public void start() {
        ...
        createAndAddWindows(); //创建整个SystemUI视图并添加到WindowManager中
        ...
    }
    ...
    public void createAndAddWindows() {
        addStatusBarWindow();
    }
    private void addStatusBarWindow() {
        makeStatusBarView(); //创建整个SystemUI视图
           ...
    }
     ...
}

 通过FragmentHostManager.getFragmentManager().replace(R.id.layout,new CollapsedStatusBarFragment()) 更新状态栏

protected void makeStatusBarView(@Nullable RegisterStatusBarResult result) {
        final Context context = mContext;
        updateDisplaySize(); // populates mDisplayMetrics//更新显示尺寸
        updateResources();//更新变化了的配置内容(进行重新加载)
        updateTheme();//切换主题颜色

      
        FragmentHostManager.get(mPhoneStatusBarWindow)
                .addTagListener(CollapsedStatusBarFragment.TAG, (tag, fragment) -> {
                    CollapsedStatusBarFragment statusBarFragment =
                            (CollapsedStatusBarFragment) fragment;

                    PhoneStatusBarView oldStatusBarView = mStatusBarView;
                    mStatusBarView = (PhoneStatusBarView) statusBarFragment.getView();
                    mStatusBarView.setBar(this);
                    mStatusBarView.setPanel(mNotificationPanelViewController);
                    mStatusBarView.setScrimController(mScrimController);

                    statusBarFragment.initNotificationIconArea(mNotificationIconAreaController);
                  
                    if (mHeadsUpManager.hasPinnedHeadsUp()) {
                        mNotificationPanelViewController.notifyBarPanelExpansionChanged();
                    }
                    mStatusBarView.setBouncerShowing(mBouncerShowing);
                    if (oldStatusBarView != null) {
                        float fraction = oldStatusBarView.getExpansionFraction();
                        boolean expanded = oldStatusBarView.isExpanded();
                        mStatusBarView.panelExpansionChanged(fraction, expanded);
                    }

                    HeadsUpAppearanceController oldController = mHeadsUpAppearanceController;
                    if (mHeadsUpAppearanceController != null) {
                        // This view is being recreated, let's destroy the old one
                        mHeadsUpAppearanceController.destroy();
                    }
                    // TODO: this should probably be scoped to the StatusBarComponent
                    // TODO (b/136993073) Separate notification shade and status bar
                    mHeadsUpAppearanceController = new HeadsUpAppearanceController(
                            mNotificationIconAreaController, mHeadsUpManager,
                            mNotificationShadeWindowView,
                            mStatusBarStateController, mKeyguardBypassController,
                            mKeyguardStateController, mWakeUpCoordinator, mCommandQueue,
                            mNotificationPanelViewController, mStatusBarView);
                    mHeadsUpAppearanceController.readFrom(oldController);

                    mLightsOutNotifController.setLightsOutNotifView(
                            mStatusBarView.findViewById(R.id.notification_lights_out));
                    mNotificationShadeWindowViewController.setStatusBarView(mStatusBarView);
                    checkBarModes();
                }).getFragmentManager()
                .beginTransaction()
                .replace(R.id.status_bar_container, new CollapsedStatusBarFragment(),
                        CollapsedStatusBarFragment.TAG)
                .commit();

        .......

        //创建导航栏
        createNavigationBar(result);

        if (ENABLE_LOCKSCREEN_WALLPAPER && mWallpaperSupported) {
            mLockscreenWallpaper = mLockscreenWallpaperLazy.get();
        }

        mKeyguardIndicationController.setIndicationArea(
                mNotificationShadeWindowView.findViewById(R.id.keyguard_indication_area));
        mNotificationPanelViewController.setKeyguardIndicationController(
                mKeyguardIndicationController);
               
        ......

    }

 

posted @ 2023-03-09 18:32  随易来了  阅读(158)  评论(0编辑  收藏  举报