本文介绍: Statusbar启动与显示流程:SystemServer在启动服务的时候启动SystemUIService//frameworks/base/services/java/com/android/server/SystemServer.java static final void startSystemUi(Context context, WindowManagerService windowManager) { Intent intent = new Intent();
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();
}
SystemBars中start()方法调用了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进行投诉反馈,一经查实,立即删除!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。