AndroidR WindowToken(1)
class WindowContainer extends ConfigurationContainer
implements Comparable
class RootWindowContainer extends WindowContainer
class DisplayContent extends WindowContainer
class WindowState extends WindowContainer
class WindowToken extends WindowContainer
final class ActivityRecord extends WindowToken
class Task extends WindowContainer
class ActivityStack extends Task
参考:https://www.kancloud.cn/alex_wsc/android-deep3/416391
final class ActivityRecord extends WindowToken
在ActivityRecord的构造方法中,先调用父类WindowToken的构造函数,得到其WindowToken
因此,ActivityRecord的apptoken(IApplicationToken.Stub)是等价于WindowToken的(强制类型转换)
super(_service.mWindowManager, new Token(_intent).asBinder(), TYPE_APPLICATION, true,
null /* displayContent */, false /* ownerCanManageAppTokens */);
mAtmService = _service;
appToken = (Token) token;
info = aInfo;
mUserId = UserHandle.getUserId(info.applicationInfo.uid);
packageName = info.applicationInfo.packageName;
对于显示组件(客户端)而言的Token,是任意一个Binder的实例,对显示组件(客户端)来说仅仅是一个创建窗口的令牌,没有其他的含义。
Token(Intent intent) {
name = intent.getComponent().flattenToShortString();
tokenString = "Token{" + Integer.toHexString(System.identityHashCode(this)) + "}";
}
WindowToken由token和WindowType来区分,已没有AppWindowToken这个类。添加 WindowToken,也是根据WindowType来添加
class WindowToken extends WindowContainer {
// The actual token.
final IBinder token;
// The type of window this token is for, as per WindowManager.LayoutParams.
final int windowType;
WindowState是WMS中的窗口实例,其mToken保存了窗口令牌,其ActivityRecord保存了对应的Activity(如果是应用窗口的话,不是应用窗口,则为null)
class WindowState extends WindowContainer
WindowToken mToken;
// The same object as mToken if this is an app window and null for non-app windows.
ActivityRecord mActivityRecord;
WindowToken的构造方法
WindowToken(WindowManagerService service, IBinder _token, int type, boolean persistOnEmpty,
DisplayContent dc, boolean ownerCanManageAppTokens, int ownerUid,
boolean roundedCornerOverlay, boolean fromClientToken) {
super(service);
token = _token;
windowType = type;
mPersistOnEmpty = persistOnEmpty;
mOwnerCanManageAppTokens = ownerCanManageAppTokens;
mOwnerUid = ownerUid;
mRoundedCornerOverlay = roundedCornerOverlay;
mFromClientToken = fromClientToken;
if (dc != null) {
dc.addWindowToken(token, this);
}
最后,是在DisplayContent中添加WindowToken
//DisplayContent.java
void addWindowToken(IBinder binder, WindowToken token) {
mTokenMap.put(binder, token);
//如果调用ActivityRecord#asActivityRecord为空,说明其不是Activity的Token
if (token.asActivityRecord() == null) {
总结:ActivityRecord----->apptoken----->WindowToken----->WindowState
可以由WindowState来处理ActivityRecord的可见性等问题