
文章目录
不管是通过启动Activity的方式来创建App类型的窗口,还是通过主动调用WindowManager.addView的方式来创建非App类型的窗口,流程都是一样,最终都是通过ViewRootImpl与WMS通信来创建一个窗口。
从App进程创建第一个窗口开始,分析App是如何与SurfaceFlinger服务建立起连接的。
1 ViewRootImpl.setView
/**
* We have one child
*/
public void setView(View view, WindowManager.LayoutParams attrs, View panelParentView,
int userId) {
synchronized (this) {
if (mView == null) {
// ......
try {
// ......
res = mWindowSession.addToDisplayAsUser(mWindow, mWindowAttributes,
getHostVisibility(), mDisplay.getDisplayId(), userId,
mInsetsController.getRequestedVisibility(), inputChannel, mTempInsets,
mTempControls);
// ......
}
这里调用mWindowSession.addToDisplayAsUser向WindowManager添加一个窗口。
ViewRootImpl的成员变量mWindowSession在ViewRootImpl创建的时候初始化,通过static类型的WindowManagerGlobal.getWindowSession方法得到:
@UnsupportedAppUsage
public static IWindowSession getWindowSession() {
synchronized (WindowManagerGlobal.class) {
if (sWindowSession == null) {
try {
// Emulate the legacy behavior. The global instance of InputMethodManager
// was instantiated here.
// TODO(b/116157766): Remove this hack after cleaning up @UnsupportedAppUsage
InputMethodManager.ensureDefaultInstanceForDefaultDisplayIfNecessary();
IWindowManager windowManager = getWindowManagerService();
sWindowSession = windowManager.openSession(
new IWindowSessionCallback.Stub(

文章详细阐述了Android应用创建窗口时的流程,从ViewRootImpl.setView开始,经过WindowManagerService和Session的交互,最终通过SurfaceSession与SurfaceFlinger建立连接,详细解析了SurfaceComposerClient如何在Native层建立与SurfaceFlinger的通信通道。
7043

被折叠的 条评论
为什么被折叠?



