AndroidR 學(xué)習(xí)與整理

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的構(gòu)造方法中,先調(diào)用父類WindowToken的構(gòu)造函數(shù),得到其WindowToken

因此,ActivityRecord的apptoken(IApplicationToken.Stub)是等價(jià)于WindowToken的(強(qiáng)制類型轉(zhuǎn)換)

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;

對(duì)于顯示組件(客戶端)而言的Token,是任意一個(gè)Binder的實(shí)例,對(duì)顯示組件(客戶端)來(lái)說(shuō)僅僅是一個(gè)創(chuàng)建窗口的令牌,沒(méi)有其他的含義。

Token(Intent intent) {
        name = intent.getComponent().flattenToShortString();
        tokenString = "Token{" + Integer.toHexString(System.identityHashCode(this)) + "}";
        }

WindowToken由token和WindowType來(lái)區(qū)分,已沒(méi)有AppWindowToken這個(gè)類。添加 WindowToken,也是根據(jù)WindowType來(lái)添加

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中的窗口實(shí)例,其mToken保存了窗口令牌,其ActivityRecord保存了對(duì)應(yīng)的Activity(如果是應(yīng)用窗口的話,不是應(yīng)用窗口,則為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的構(gòu)造方法

    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);
        //如果調(diào)用ActivityRecord#asActivityRecord為空,說(shuō)明其不是Activity的Token
        if (token.asActivityRecord() == null) {

總結(jié):ActivityRecord----->apptoken----->WindowToken----->WindowState

可以由WindowState來(lái)處理ActivityRecord的可見(jiàn)性等問(wèn)題

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容