WindowManagerService主要是负责管理WindowState和窗口动画的
1:WMS有关Window相关的数据结构
WMS数据结构.png
2:RootWindowContainer
RootWindowContainer的初始化是在WMS中完成的,其主要是用来管理显示屏幕的,其关联着一组DisplayContent,设备上的所有显示 屏幕都是其来管理
WindowList mChildren,E代表的是DisplayContent
protected final SurfaceAnimator mSurfaceAnimator;//窗口动画
3:DisplayContent
DisplayContent代表的是一块显示屏幕,其被RootWindowContainer所管理,该显示屏上的窗口以栈的形式管理,DisplayContent有四种类型的container,分别用来存储不同类型的窗口:应用程序窗口,系统类型的窗口,输入法窗口和壁纸窗口,在addWindowToken中来决定需要加入到哪个Container中
/** Unique identifier of this stack. */
private final int mDisplayId;
/** The containers below are the only child containers the display can have. */
// Contains all window containers that are related to apps (Activities)
private final TaskStackContainers mTaskStackContainers = new TaskStackContainers(mService);
// Contains all non-app window containers that should be displayed above the app containers
// (e.g. Status bar)
private final AboveAppWindowContainers mAboveAppWindowsContainers =
new AboveAppWindowContainers("mAboveAppWindowsContainers", mService);
// Contains all non-app window containers that should be displayed below the app containers
// (e.g. Wallpaper).
private final NonAppWindowContainers mBelowAppWindowsContainers =
new NonAppWindowContainers("mBelowAppWindowsContainers", mService);
// Contains all IME window containers. Note that the z-ordering of the IME windows will depend
// on the IME target. We mainly have this container grouping so we can keep track of all the IME
// window containers together and move them in-sync if/when needed. We use a subclass of
// WindowContainer which is omitted from screen magnification, as the IME is never magnified.
private final NonMagnifiableWindowContainers mImeWindowsContainers =
new NonMagnifiableWindowContainers("mImeWindowsContainers", mService);
// Mapping from a token IBinder to a WindowToken object on this display.
private final HashMap mTokenMap = new HashMap();
4:TaskStack
用来管理Window的,形式就是栈的形式,对应AMS端的ActivityStack
/** Unique identifier */
final int mStackId;
/** The display this stack sits under. */
// TODO: Track parent marks like this in WindowContainer.
private DisplayContent mDisplayContent;
/** Application tokens that are exiting, but still on screen for animations. */
final AppTokenList mExitingAppTokens = new AppTokenList();
final AppTokenList mTmpAppTokens = new AppTokenList();
5:Task
Task可以理解成一个任务栈,用来管理AppWindowToken的,对应AMS端的TaskRecord
TaskStack mStack;
final int mTaskId;
final int mUserId;
//表明Task关联着一组AppWindowToken,WindowList mChildren表示的是WindowList mChildRen
class Task extends WindowContainer
6:AppWindowToken
AppWindowToken关联着一组有相同Token值的WindowState,WindowState并不是和Activity一一对应的,因为窗口有子窗口,系统窗口,应用程序窗口三种,子窗口和应用程序窗口共用相同的token值
// Non-null only for application tokens.
final IApplicationToken appToken;
WindowList mChildren;存储的所有的WindowState
7:WindowState
WindowState代表是WMS端的窗口对象,WindowState是应用程序通过WindowManager.addView创建的,WindowState是有层级的,其层级是有layer来决定,最终是由窗口类型来决定的
final Session mSession;
final IWindow mClient;
final WindowId mWindowId;
WindowToken mToken;
// The same object as mToken if this is an app window and null for non-app windows.
AppWindowToken mAppToken;
final int mBaseLayer;//baselayer
final int mSubLayer;//sublayer
final boolean mLayoutAttached;
final boolean mIsImWindow;//输入法窗口
final boolean mIsWallpaper;//壁纸窗口
final WindowManager.LayoutParams mAttrs//窗口属性