本文主要是介绍[深入SystemUI]-了解statusbar的启动流程,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
本文流程基于Android 9.0
时序图
1.启动SystemUIService
在SystemServer
中有一个方法startSystemUi
,当系统启动后,会执行到SystemServer
的startSystemUi()
方法,正是在这个方法中启动了SystemUIService
。
static final void startSystemUi(Context context, WindowManagerService windowManager) {Intent intent = new Intent();// 指定了systemui的包名"com.android.systemui",指定了ServiceUIService的类名"com.android.systemui.SystemUIService"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();
}
2.在SystemUIService中启动SystemUI中的服务
SystemUIService.java
@Override
public void onCreate() {super.onCreate();//在oncreate方法中调用SystemUIApplication的startServicesIfNeeded来启动相关服务((SystemUIApplication) getApplication()).startServicesIfNeeded();// code...
}
SystemUIApplication
/*** Makes sure that all the SystemUI services are running. If they are already running, this is a* no-op. This is needed to conditinally start all the services, as we only need to have it in* the main process.* <p>This method must only be called from the main thread.</p>*/public void startServicesIfNeeded() {String[] names = getResources().getStringArray(R.array.config_systemUIServiceComponents);startServicesIfNeeded(names);
}
注意,这里的service
的names
是从config
文件中读取出来的,具体内容如下,其中就包含了SystemBars
的路径:
<!-- SystemUI Services: The classes of the stuff to start. -->
<string-array name="config_systemUIServiceComponents" translatable="false"><item>com.android.systemui.Dependency</item>
这篇关于[深入SystemUI]-了解statusbar的启动流程的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!