final WindowManagerPolicy mPolicy; final IActivityManager mActivityManager; final ActivityManagerInternal mAmInternal; final AppOpsManager mAppOps; final DisplaySettings mDisplaySettings; ... final ArraySet<Session> mSessions = new ArraySet<>(); final WindowHashMap mWindowMap = new WindowHashMap(); final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<>(); final ArrayList<AppWindowToken> mFinishedEarlyAnim = new ArrayList<>(); final ArrayList<AppWindowToken> mWindowReplacementTimeouts = new ArrayList<>(); final ArrayList<WindowState> mResizingWindows = new ArrayList<>(); final ArrayList<WindowState> mPendingRemove = new ArrayList<>(); WindowState[] mPendingRemoveTmp = new WindowState[20]; final ArrayList<WindowState> mDestroySurface = new ArrayList<>(); final ArrayList<WindowState> mDestroyPreservedSurface = new ArrayList<>(); ... final H mH = new H(); ... final WindowAnimator mAnimator; ... final InputManagerService mInputManager
publicintaddWindow(Session session, IWindow client, int seq, WindowManager.LayoutParams attrs, int viewVisibility, int displayId, Rect outContentInsets, Rect outStableInsets, Rect outOutsets, InputChannel outInputChannel){
int[] appOp = newint[1]; int res = mPolicy.checkAddPermission(attrs, appOp);//1 if (res != WindowManagerGlobal.ADD_OKAY) { return res; } ... synchronized(mWindowMap) { if (!mDisplayReady) { thrownew IllegalStateException("Display has not been initialialized"); } final DisplayContent displayContent = mRoot.getDisplayContentOrCreate(displayId);//2 if (displayContent == null) { Slog.w(TAG_WM, "Attempted to add window to a display that does not exist: " + displayId + ". Aborting."); 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) { Slog.w(TAG_WM, "Attempted to add window with token that is not a window: " + attrs.token + ". Aborting."); return WindowManagerGlobal.ADD_BAD_SUBWINDOW_TOKEN; } if (parentWindow.mAttrs.type >= FIRST_SUB_WINDOW && parentWindow.mAttrs.type <= LAST_SUB_WINDOW) { Slog.w(TAG_WM, "Attempted to add window with token that is a sub-window: " + attrs.token + ". Aborting."); return WindowManagerGlobal.ADD_BAD_SUBWINDOW_TOKEN; } } ... } ... }
... final WindowState win = new WindowState(this, session, client, token, parentWindow, appOp[0], seq, attrs, viewVisibility, session.mUid, session.mCanAddInternalSystemWindow);//1 if (win.mDeathRecipient == null) {//2 // Client has apparently died, so there is no reason to // continue. Slog.w(TAG_WM, "Adding window client " + client.asBinder() + " that is dead, aborting."); return WindowManagerGlobal.ADD_APP_EXITING; }
if (win.getDisplayContent() == null) {//3 Slog.w(TAG_WM, "Adding window to Display that has been removed."); return WindowManagerGlobal.ADD_INVALID_DISPLAY; }
mPolicy.adjustWindowParamsLw(win.mAttrs);//4 win.setShowToOwnerOnlyLocked(mPolicy.checkShowToOwnerOnly(attrs)); res = mPolicy.prepareAddWindowLw(win, attrs);//5 ... win.attach(); mWindowMap.put(client.asBinder(), win);//6 if (win.mAppOp != AppOpsManager.OP_NONE) { int startOpResult = mAppOps.startOpNoThrow(win.mAppOp, win.getOwningUid(), win.getOwningPackage()); if ((startOpResult != AppOpsManager.MODE_ALLOWED) && (startOpResult != AppOpsManager.MODE_DEFAULT)) { win.setAppOpVisibilityLw(false); } }