AndroidR 学习与整理

AndroidR WindowToken(1)

class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<E>
        implements Comparable<WindowContainer>
class RootWindowContainer extends WindowContainer<DisplayContent>
class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer>
class WindowState extends WindowContainer<WindowState> 
class WindowToken extends WindowContainer<WindowState>
final class ActivityRecord extends WindowToken
class Task extends WindowContainer<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<WindowState> {

    // 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<WindowState>
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的可见性等问题

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容