Statusbar启动显示流程

SystemServer在启动服务的时候启动SystemUIService

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

    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);
        //Slog.d(TAG, "Starting service: " + intent);
        context.startServiceAsUser(intent, UserHandle.SYSTEM);
        windowManager.onSystemUiStarted();
    }

SystemUIService调用SystemUIApplication.startServicesIfNeeded()启动必要的服务

//frameworks/base/packages/SystemUI/src/com/android/systemui/SystemUIService.java

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

SystemUIApplication中的startServicesIfNeeded()方法启动状态栏导航组件SystemBars

//frameworks/base/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java

    public void startServicesIfNeeded() {
        //config_systemUIServiceComponents包含com.android.systemui.SystemBars
        String[] names = getResources().getStringArray(R.array.config_systemUIServiceComponents);
        startServicesIfNeeded(names);
    }

	public void startServicesIfNeeded(names){
	***
	    mServices[i].mContext = this;
        mServices[i].mComponents = mComponents;
        if (DEBUG) Log.d(TAG, "running: " + mServices[i]);
        //启动状态栏导航组件SystemBars
        mServices[i].start();
	}

SystemBarsstart()方法调用了createStatusBarFromConfig(),通过反射加载启动了StatusBar

//frameworks/base/packages/SystemUI/src/com/android/systemui/SystemBars.java

    @Override
    public void start() {
        if (DEBUG) Log.d(TAG, "start");
        createStatusBarFromConfig();
    }

    private void createStatusBarFromConfig() {
        if (DEBUG) Log.d(TAG, "createStatusBarFromConfig");
        // config_statusBarComponent:com.android.systemui.statusbar.phone.StatusBar
        final String clsName = mContext.getString(R.string.config_statusBarComponent);
        if (clsName == null || clsName.length() == 0) {
            throw andLog("No status bar component configured", null);
        }
        Class<?> cls = null;
        try {
            cls = mContext.getClassLoader().loadClass(clsName);
        } catch (Throwable t) {
            throw andLog("Error loading status bar component: " + clsName, t);
        }
        try {
            mStatusBar = (SystemUI) cls.newInstance();
        } catch (Throwable t) {
            throw andLog("Error creating status bar component: " + clsName, t);
        }
        mStatusBar.mContext = mContext;
        mStatusBar.mComponents = mComponents;
        //启动StatusBar
        mStatusBar.start();
        if (DEBUG) Log.d(TAG, "started " + mStatusBar.getClass().getSimpleName());
    }

StatusBar创建状态栏View的流程:调用inflateStatusBarWindow(),其中super_status_bar为状态栏布局,调用createAndAddWindows(),调用addStatusBarWindow()将布局加入WindowManager

//frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java

    protected void inflateStatusBarWindow(Context context) {
        //super_status_bar为状态栏布局
        //replace(R.id.status_bar_container, new CollapsedStatusBarFragment().commit状态栏fragment放入super_status_bar布局的R.id.status_bar_container
        mStatusBarWindow = (StatusBarWindowView) View.inflate(context,R.layout.super_status_bar, null);
    }
    
    public void createAndAddWindows() {
        addStatusBarWindow();
    }

    private void addStatusBarWindow() {
        makeStatusBarView();
        mStatusBarWindowManager = Dependency.get(StatusBarWindowManager.class);
        mRemoteInputManager.setUpWithPresenter(this, mEntryManager, this,
                new RemoteInputController.Delegate() {
                    public void setRemoteInputActive(NotificationData.Entry entry,
                            boolean remoteInputActive) {
                        mHeadsUpManager.setRemoteInputActive(entry, remoteInputActive);
                        entry.row.notifyHeightChanged(true /* needsAnimation */);
                        updateFooter();
                    }
                    public void lockScrollTo(NotificationData.Entry entry) {
                        mStackScroller.lockScrollTo(entry.row);
                    }
                    public void requestDisallowLongPressAndDismiss() {
                        mStackScroller.requestDisallowLongPress();
                        mStackScroller.requestDisallowDismiss();
                    }
                });
        mRemoteInputManager.getController().addCallback(mStatusBarWindowManager);
        //将布局加载到WindowManager中
        mStatusBarWindowManager.add(mStatusBarWindow, getStatusBarHeight());
    }

StatusBar创建导航栏View的流程:调用createNavigationBar()方法

    protected void createNavigationBar() {
    	/*
		 *NavigationBarFragment.create方法包括:
		 *   View navigationBarView = LayoutInflater.from(context).inflate(R.layout.navigation_bar_window, null);
		 *   context.getSystemService(WindowManager.class).addView(navigationBarView, lp);
		 *   fragmentHost.getFragmentManager().beginTransaction().replace(R.id.navigation_bar_frame, fragment, TAG).commit();
		 *将导航fragment放入navigation_bar_window布局的R.id.navigation_bar_frame中
		 */
        mNavigationBarView = NavigationBarFragment.create(mContext, (tag, fragment) -> {
            mNavigationBar = (NavigationBarFragment) fragment;
            if (mLightBarController != null) {
                mNavigationBar.setLightBarController(mLightBarController);
            }
            mNavigationBar.setCurrentSysuiVisibility(mSystemUiVisibility);
        });
    }

原文地址:https://blog.csdn.net/jessecode/article/details/122879880

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_15879.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注