if (displayContent == null) { ProtoLog.w(WM_ERROR, "Attempted to add window to a display that does " + "not exist: %d. Aborting.", displayId); return WindowManagerGlobal.ADD_INVALID_DISPLAY; } ... if (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW) { // 3 parentWindow = windowForClientLocked(null, attrs.token, false); // 4 if (parentWindow == null) { ProtoLog.w(WM_ERROR, "Attempted to add window with token that is not a window: " + "%s. Aborting.", attrs.token); return WindowManagerGlobal.ADD_BAD_SUBWINDOW_TOKEN; } if (parentWindow.mAttrs.type >= FIRST_SUB_WINDOW && parentWindow.mAttrs.type <= LAST_SUB_WINDOW) { ProtoLog.w(WM_ERROR, "Attempted to add window with token that is a sub-window: " + "%s. Aborting.", attrs.token); return WindowManagerGlobal.ADD_BAD_SUBWINDOW_TOKEN; } }
frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java publicintaddWindow(Session session, IWindow client, LayoutParams attrs, int viewVisibility, int displayId, int requestUserId, @InsetsTypeint requestedVisibleTypes, InputChannel outInputChannel, InsetsState outInsetsState, InsetsSourceControl.Array outActiveControls, Rect outAttachedFrame, float[] outSizeCompatScale) { ... synchronized (mGlobalLock) { ... finalbooleanhasParent= parentWindow != null; // Use existing parent window token for child windows since they go in the same token // as there parent window so we can apply the same policy on them. WindowTokentoken= displayContent.getWindowToken( hasParent ? parentWindow.mAttrs.token : attrs.token); // 1 // If this is a child window, we want to apply the same type checking rules as the // parent window type. finalintrootType= hasParent ? parentWindow.mAttrs.type : type; // 2
frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java publicintaddWindow(Session session, IWindow client, LayoutParams attrs, int viewVisibility, int displayId, int requestUserId, @InsetsTypeint requestedVisibleTypes, InputChannel outInputChannel, InsetsState outInsetsState, InsetsSourceControl.Array outActiveControls, Rect outAttachedFrame, float[] outSizeCompatScale) { ... synchronized (mGlobalLock) { ... finalWindowStatewin=newWindowState(this, session, client, token, parentWindow, appOp[0], attrs, viewVisibility, session.mUid, userId, session.mCanAddInternalSystemWindow); // 1 if (win.mDeathRecipient == null) { // 2 // Client has apparently died, so there is no reason to // continue. ProtoLog.w(WM_ERROR, "Adding window client %s" + " that is dead, aborting.", client.asBinder()); return WindowManagerGlobal.ADD_APP_EXITING; }
if (win.getDisplayContent() == null) { // 3 ProtoLog.w(WM_ERROR, "Adding window to Display that has been removed."); return WindowManagerGlobal.ADD_INVALID_DISPLAY; }