DisplayContent.java revision b660b9d8cf6b951b85a35599d636c470795e9a1a
10c1bc742181ded4930842b46e9507372f0b1b963James Dong/*
278e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * Copyright (C) 2012 The Android Open Source Project
378e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar *
478e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * Licensed under the Apache License, Version 2.0 (the "License");
578e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * you may not use this file except in compliance with the License.
678e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * You may obtain a copy of the License at
778e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar *
878e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar *      http://www.apache.org/licenses/LICENSE-2.0
978e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar *
1078e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * Unless required by applicable law or agreed to in writing, software
1178e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * distributed under the License is distributed on an "AS IS" BASIS,
1278e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1378e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * See the License for the specific language governing permissions and
1478e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * limitations under the License.
1578e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar */
1678e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar
170c1bc742181ded4930842b46e9507372f0b1b963James Dongpackage com.android.server.wm;
180c1bc742181ded4930842b46e9507372f0b1b963James Dong
190c1bc742181ded4930842b46e9507372f0b1b963James Dongimport static com.android.server.am.ActivityStackSupervisor.HOME_STACK_ID;
200c1bc742181ded4930842b46e9507372f0b1b963James Dongimport static com.android.server.wm.WindowManagerService.DEBUG_VISIBILITY;
210c1bc742181ded4930842b46e9507372f0b1b963James Dongimport static com.android.server.wm.WindowManagerService.TAG;
220c1bc742181ded4930842b46e9507372f0b1b963James Dong
230c1bc742181ded4930842b46e9507372f0b1b963James Dongimport android.graphics.Rect;
240c1bc742181ded4930842b46e9507372f0b1b963James Dongimport android.graphics.Region;
250c1bc742181ded4930842b46e9507372f0b1b963James Dongimport android.util.Slog;
260c1bc742181ded4930842b46e9507372f0b1b963James Dongimport android.view.Display;
270c1bc742181ded4930842b46e9507372f0b1b963James Dongimport android.view.DisplayInfo;
280c1bc742181ded4930842b46e9507372f0b1b963James Dongimport android.view.Surface;
290c1bc742181ded4930842b46e9507372f0b1b963James Dong
300c1bc742181ded4930842b46e9507372f0b1b963James Dongimport java.io.PrintWriter;
310c1bc742181ded4930842b46e9507372f0b1b963James Dongimport java.util.ArrayList;
320c1bc742181ded4930842b46e9507372f0b1b963James Dong
330c1bc742181ded4930842b46e9507372f0b1b963James Dongclass DisplayContentList extends ArrayList<DisplayContent> {
340c1bc742181ded4930842b46e9507372f0b1b963James Dong}
350c1bc742181ded4930842b46e9507372f0b1b963James Dong
360c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
370c1bc742181ded4930842b46e9507372f0b1b963James Dong * Utility class for keeping track of the WindowStates and other pertinent contents of a
380c1bc742181ded4930842b46e9507372f0b1b963James Dong * particular Display.
390c1bc742181ded4930842b46e9507372f0b1b963James Dong *
400c1bc742181ded4930842b46e9507372f0b1b963James Dong * IMPORTANT: No method from this class should ever be used without holding
410c1bc742181ded4930842b46e9507372f0b1b963James Dong * WindowManagerService.mWindowMap.
420c1bc742181ded4930842b46e9507372f0b1b963James Dong */
430c1bc742181ded4930842b46e9507372f0b1b963James Dongclass DisplayContent {
440c1bc742181ded4930842b46e9507372f0b1b963James Dong
450c1bc742181ded4930842b46e9507372f0b1b963James Dong    /** Unique identifier of this stack. */
460c1bc742181ded4930842b46e9507372f0b1b963James Dong    private final int mDisplayId;
470c1bc742181ded4930842b46e9507372f0b1b963James Dong
480c1bc742181ded4930842b46e9507372f0b1b963James Dong    /** Z-ordered (bottom-most first) list of all Window objects. Assigned to an element
490c1bc742181ded4930842b46e9507372f0b1b963James Dong     * from mDisplayWindows; */
500c1bc742181ded4930842b46e9507372f0b1b963James Dong    private final WindowList mWindows = new WindowList();
510c1bc742181ded4930842b46e9507372f0b1b963James Dong
520c1bc742181ded4930842b46e9507372f0b1b963James Dong    // This protects the following display size properties, so that
530c1bc742181ded4930842b46e9507372f0b1b963James Dong    // getDisplaySize() doesn't need to acquire the global lock.  This is
540c1bc742181ded4930842b46e9507372f0b1b963James Dong    // needed because the window manager sometimes needs to use ActivityThread
550c1bc742181ded4930842b46e9507372f0b1b963James Dong    // while it has its global state locked (for example to load animation
560c1bc742181ded4930842b46e9507372f0b1b963James Dong    // resources), but the ActivityThread also needs get the current display
570c1bc742181ded4930842b46e9507372f0b1b963James Dong    // size sometimes when it has its package lock held.
580c1bc742181ded4930842b46e9507372f0b1b963James Dong    //
590c1bc742181ded4930842b46e9507372f0b1b963James Dong    // These will only be modified with both mWindowMap and mDisplaySizeLock
600c1bc742181ded4930842b46e9507372f0b1b963James Dong    // held (in that order) so the window manager doesn't need to acquire this
610c1bc742181ded4930842b46e9507372f0b1b963James Dong    // lock when needing these values in its normal operation.
620c1bc742181ded4930842b46e9507372f0b1b963James Dong    final Object mDisplaySizeLock = new Object();
630c1bc742181ded4930842b46e9507372f0b1b963James Dong    int mInitialDisplayWidth = 0;
640c1bc742181ded4930842b46e9507372f0b1b963James Dong    int mInitialDisplayHeight = 0;
650c1bc742181ded4930842b46e9507372f0b1b963James Dong    int mInitialDisplayDensity = 0;
660c1bc742181ded4930842b46e9507372f0b1b963James Dong    int mBaseDisplayWidth = 0;
670c1bc742181ded4930842b46e9507372f0b1b963James Dong    int mBaseDisplayHeight = 0;
680c1bc742181ded4930842b46e9507372f0b1b963James Dong    int mBaseDisplayDensity = 0;
690c1bc742181ded4930842b46e9507372f0b1b963James Dong    private final DisplayInfo mDisplayInfo = new DisplayInfo();
700c1bc742181ded4930842b46e9507372f0b1b963James Dong    private final Display mDisplay;
710c1bc742181ded4930842b46e9507372f0b1b963James Dong
720c1bc742181ded4930842b46e9507372f0b1b963James Dong    Rect mBaseDisplayRect = new Rect();
730c1bc742181ded4930842b46e9507372f0b1b963James Dong    Rect mContentRect = new Rect();
740c1bc742181ded4930842b46e9507372f0b1b963James Dong
750c1bc742181ded4930842b46e9507372f0b1b963James Dong    // Accessed directly by all users.
760c1bc742181ded4930842b46e9507372f0b1b963James Dong    boolean layoutNeeded;
770c1bc742181ded4930842b46e9507372f0b1b963James Dong    int pendingLayoutChanges;
780c1bc742181ded4930842b46e9507372f0b1b963James Dong    final boolean isDefaultDisplay;
790c1bc742181ded4930842b46e9507372f0b1b963James Dong
800c1bc742181ded4930842b46e9507372f0b1b963James Dong    /** Window tokens that are in the process of exiting, but still on screen for animations. */
810c1bc742181ded4930842b46e9507372f0b1b963James Dong    final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
820c1bc742181ded4930842b46e9507372f0b1b963James Dong
830c1bc742181ded4930842b46e9507372f0b1b963James Dong    /** Array containing all TaskStacks on this display.  Array
840c1bc742181ded4930842b46e9507372f0b1b963James Dong     * is stored in display order with the current bottom stack at 0. */
850c1bc742181ded4930842b46e9507372f0b1b963James Dong    private final ArrayList<TaskStack> mStacks = new ArrayList<TaskStack>();
860c1bc742181ded4930842b46e9507372f0b1b963James Dong
870c1bc742181ded4930842b46e9507372f0b1b963James Dong    /** A special TaskStack with id==HOME_STACK_ID that moves to the bottom whenever any TaskStack
880c1bc742181ded4930842b46e9507372f0b1b963James Dong     * (except a future lockscreen TaskStack) moves to the top. */
890c1bc742181ded4930842b46e9507372f0b1b963James Dong    private TaskStack mHomeStack = null;
900c1bc742181ded4930842b46e9507372f0b1b963James Dong
910c1bc742181ded4930842b46e9507372f0b1b963James Dong    /** Detect user tapping outside of current focused stack bounds .*/
920c1bc742181ded4930842b46e9507372f0b1b963James Dong    StackTapPointerEventListener mTapDetector;
930c1bc742181ded4930842b46e9507372f0b1b963James Dong
940c1bc742181ded4930842b46e9507372f0b1b963James Dong    /** Detect user tapping outside of current focused stack bounds .*/
950c1bc742181ded4930842b46e9507372f0b1b963James Dong    Region mTouchExcludeRegion = new Region();
960c1bc742181ded4930842b46e9507372f0b1b963James Dong
970c1bc742181ded4930842b46e9507372f0b1b963James Dong    /** Save allocating when calculating rects */
980c1bc742181ded4930842b46e9507372f0b1b963James Dong    Rect mTmpRect = new Rect();
990c1bc742181ded4930842b46e9507372f0b1b963James Dong
1000c1bc742181ded4930842b46e9507372f0b1b963James Dong    /** For gathering Task objects in order. */
1010c1bc742181ded4930842b46e9507372f0b1b963James Dong    final ArrayList<Task> mTmpTaskHistory = new ArrayList<Task>();
1020c1bc742181ded4930842b46e9507372f0b1b963James Dong
1030c1bc742181ded4930842b46e9507372f0b1b963James Dong    final WindowManagerService mService;
1040c1bc742181ded4930842b46e9507372f0b1b963James Dong
1050c1bc742181ded4930842b46e9507372f0b1b963James Dong    static final int DEFER_DETACH = 1;
1060c1bc742181ded4930842b46e9507372f0b1b963James Dong    static final int DEFER_REMOVAL = 2;
1070c1bc742181ded4930842b46e9507372f0b1b963James Dong    int mDeferredActions;
1080c1bc742181ded4930842b46e9507372f0b1b963James Dong
1090c1bc742181ded4930842b46e9507372f0b1b963James Dong    /**
1100c1bc742181ded4930842b46e9507372f0b1b963James Dong     * @param display May not be null.
1110c1bc742181ded4930842b46e9507372f0b1b963James Dong     * @param service You know.
1120c1bc742181ded4930842b46e9507372f0b1b963James Dong     */
1130c1bc742181ded4930842b46e9507372f0b1b963James Dong    DisplayContent(Display display, WindowManagerService service) {
1140c1bc742181ded4930842b46e9507372f0b1b963James Dong        mDisplay = display;
1150c1bc742181ded4930842b46e9507372f0b1b963James Dong        mDisplayId = display.getDisplayId();
1160c1bc742181ded4930842b46e9507372f0b1b963James Dong        display.getDisplayInfo(mDisplayInfo);
1170c1bc742181ded4930842b46e9507372f0b1b963James Dong        isDefaultDisplay = mDisplayId == Display.DEFAULT_DISPLAY;
1180c1bc742181ded4930842b46e9507372f0b1b963James Dong        mService = service;
1190c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1200c1bc742181ded4930842b46e9507372f0b1b963James Dong
1210c1bc742181ded4930842b46e9507372f0b1b963James Dong    int getDisplayId() {
1220c1bc742181ded4930842b46e9507372f0b1b963James Dong        return mDisplayId;
1230c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1240c1bc742181ded4930842b46e9507372f0b1b963James Dong
1250c1bc742181ded4930842b46e9507372f0b1b963James Dong    WindowList getWindowList() {
1260c1bc742181ded4930842b46e9507372f0b1b963James Dong        return mWindows;
1270c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1280c1bc742181ded4930842b46e9507372f0b1b963James Dong
1290c1bc742181ded4930842b46e9507372f0b1b963James Dong    Display getDisplay() {
1300c1bc742181ded4930842b46e9507372f0b1b963James Dong        return mDisplay;
1310c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1320c1bc742181ded4930842b46e9507372f0b1b963James Dong
1330c1bc742181ded4930842b46e9507372f0b1b963James Dong    DisplayInfo getDisplayInfo() {
1340c1bc742181ded4930842b46e9507372f0b1b963James Dong        return mDisplayInfo;
1350c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1360c1bc742181ded4930842b46e9507372f0b1b963James Dong
1370c1bc742181ded4930842b46e9507372f0b1b963James Dong    /**
1380c1bc742181ded4930842b46e9507372f0b1b963James Dong     * Returns true if the specified UID has access to this display.
1390c1bc742181ded4930842b46e9507372f0b1b963James Dong     */
1400c1bc742181ded4930842b46e9507372f0b1b963James Dong    public boolean hasAccess(int uid) {
1410c1bc742181ded4930842b46e9507372f0b1b963James Dong        return mDisplay.hasAccess(uid);
1420c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1430c1bc742181ded4930842b46e9507372f0b1b963James Dong
1440c1bc742181ded4930842b46e9507372f0b1b963James Dong    public boolean isPrivate() {
1450c1bc742181ded4930842b46e9507372f0b1b963James Dong        return (mDisplay.getFlags() & Display.FLAG_PRIVATE) != 0;
1460c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1470c1bc742181ded4930842b46e9507372f0b1b963James Dong
1480c1bc742181ded4930842b46e9507372f0b1b963James Dong    ArrayList<TaskStack> getStacks() {
1490c1bc742181ded4930842b46e9507372f0b1b963James Dong        return mStacks;
1500c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1510c1bc742181ded4930842b46e9507372f0b1b963James Dong
1520c1bc742181ded4930842b46e9507372f0b1b963James Dong    /**
1530c1bc742181ded4930842b46e9507372f0b1b963James Dong     * Retrieve the tasks on this display in stack order from the bottommost TaskStack up.
1540c1bc742181ded4930842b46e9507372f0b1b963James Dong     * @return All the Tasks, in order, on this display.
1550c1bc742181ded4930842b46e9507372f0b1b963James Dong     */
1560c1bc742181ded4930842b46e9507372f0b1b963James Dong    ArrayList<Task> getTasks() {
1570c1bc742181ded4930842b46e9507372f0b1b963James Dong        mTmpTaskHistory.clear();
1580c1bc742181ded4930842b46e9507372f0b1b963James Dong        final int numStacks = mStacks.size();
1590c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
1600c1bc742181ded4930842b46e9507372f0b1b963James Dong            mTmpTaskHistory.addAll(mStacks.get(stackNdx).getTasks());
1610c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
1620c1bc742181ded4930842b46e9507372f0b1b963James Dong        return mTmpTaskHistory;
1630c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1640c1bc742181ded4930842b46e9507372f0b1b963James Dong
1650c1bc742181ded4930842b46e9507372f0b1b963James Dong    TaskStack getHomeStack() {
1660c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (mHomeStack == null) {
1670c1bc742181ded4930842b46e9507372f0b1b963James Dong            Slog.e(TAG, "getHomeStack: Returning null from this=" + this);
1680c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
1690c1bc742181ded4930842b46e9507372f0b1b963James Dong        return mHomeStack;
1700c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1710c1bc742181ded4930842b46e9507372f0b1b963James Dong
1720c1bc742181ded4930842b46e9507372f0b1b963James Dong    void updateDisplayInfo() {
1730c1bc742181ded4930842b46e9507372f0b1b963James Dong        mDisplay.getDisplayInfo(mDisplayInfo);
1740c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (int i = mStacks.size() - 1; i >= 0; --i) {
1750c1bc742181ded4930842b46e9507372f0b1b963James Dong            mStacks.get(i).updateDisplayInfo();
1760c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
1770c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1780c1bc742181ded4930842b46e9507372f0b1b963James Dong
1790c1bc742181ded4930842b46e9507372f0b1b963James Dong    void getLogicalDisplayRect(Rect out) {
1800c1bc742181ded4930842b46e9507372f0b1b963James Dong        // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
1810c1bc742181ded4930842b46e9507372f0b1b963James Dong        final int orientation = mDisplayInfo.rotation;
1820c1bc742181ded4930842b46e9507372f0b1b963James Dong        boolean rotated = (orientation == Surface.ROTATION_90
1830c1bc742181ded4930842b46e9507372f0b1b963James Dong                || orientation == Surface.ROTATION_270);
1840c1bc742181ded4930842b46e9507372f0b1b963James Dong        final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
1850c1bc742181ded4930842b46e9507372f0b1b963James Dong        final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
1860c1bc742181ded4930842b46e9507372f0b1b963James Dong        int width = mDisplayInfo.logicalWidth;
1870c1bc742181ded4930842b46e9507372f0b1b963James Dong        int left = (physWidth - width) / 2;
1880c1bc742181ded4930842b46e9507372f0b1b963James Dong        int height = mDisplayInfo.logicalHeight;
1890c1bc742181ded4930842b46e9507372f0b1b963James Dong        int top = (physHeight - height) / 2;
1900c1bc742181ded4930842b46e9507372f0b1b963James Dong        out.set(left, top, left + width, top + height);
1910c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1920c1bc742181ded4930842b46e9507372f0b1b963James Dong
1930c1bc742181ded4930842b46e9507372f0b1b963James Dong    /** Refer to {@link WindowManagerService#attachStack(int, int)} */
1940c1bc742181ded4930842b46e9507372f0b1b963James Dong    void attachStack(TaskStack stack) {
1950c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (stack.mStackId == HOME_STACK_ID) {
1960c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (mHomeStack != null) {
1970c1bc742181ded4930842b46e9507372f0b1b963James Dong                throw new IllegalArgumentException("attachStack: HOME_STACK_ID (0) not first.");
1980c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
1990c1bc742181ded4930842b46e9507372f0b1b963James Dong            mHomeStack = stack;
2000c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
2010c1bc742181ded4930842b46e9507372f0b1b963James Dong        mStacks.add(stack);
2020c1bc742181ded4930842b46e9507372f0b1b963James Dong        layoutNeeded = true;
2030c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
2040c1bc742181ded4930842b46e9507372f0b1b963James Dong
2050c1bc742181ded4930842b46e9507372f0b1b963James Dong    void moveStack(TaskStack stack, boolean toTop) {
2060c1bc742181ded4930842b46e9507372f0b1b963James Dong        mStacks.remove(stack);
2070c1bc742181ded4930842b46e9507372f0b1b963James Dong        mStacks.add(toTop ? mStacks.size() : 0, stack);
2080c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
2090c1bc742181ded4930842b46e9507372f0b1b963James Dong
2100c1bc742181ded4930842b46e9507372f0b1b963James Dong    void detachStack(TaskStack stack) {
2110c1bc742181ded4930842b46e9507372f0b1b963James Dong        mStacks.remove(stack);
2120c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
2130c1bc742181ded4930842b46e9507372f0b1b963James Dong
2140c1bc742181ded4930842b46e9507372f0b1b963James Dong    /**
2150c1bc742181ded4930842b46e9507372f0b1b963James Dong     * Propagate the new bounds to all child stacks.
2160c1bc742181ded4930842b46e9507372f0b1b963James Dong     * @param contentRect The bounds to apply at the top level.
2170c1bc742181ded4930842b46e9507372f0b1b963James Dong     */
2180c1bc742181ded4930842b46e9507372f0b1b963James Dong    void resize(Rect contentRect) {
2190c1bc742181ded4930842b46e9507372f0b1b963James Dong        mContentRect.set(contentRect);
2200c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
2210c1bc742181ded4930842b46e9507372f0b1b963James Dong
2220c1bc742181ded4930842b46e9507372f0b1b963James Dong    int stackIdFromPoint(int x, int y) {
2230c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
2240c1bc742181ded4930842b46e9507372f0b1b963James Dong            final TaskStack stack = mStacks.get(stackNdx);
2250c1bc742181ded4930842b46e9507372f0b1b963James Dong            stack.getBounds(mTmpRect);
2260c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (mTmpRect.contains(x, y)) {
2270c1bc742181ded4930842b46e9507372f0b1b963James Dong                return stack.mStackId;
2280c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
2290c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
2300c1bc742181ded4930842b46e9507372f0b1b963James Dong        return -1;
2310c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
2320c1bc742181ded4930842b46e9507372f0b1b963James Dong
2330c1bc742181ded4930842b46e9507372f0b1b963James Dong    void setTouchExcludeRegion(TaskStack focusedStack) {
2340c1bc742181ded4930842b46e9507372f0b1b963James Dong        mTouchExcludeRegion.set(mBaseDisplayRect);
2350c1bc742181ded4930842b46e9507372f0b1b963James Dong        WindowList windows = getWindowList();
2360c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (int i = windows.size() - 1; i >= 0; --i) {
2370c1bc742181ded4930842b46e9507372f0b1b963James Dong            final WindowState win = windows.get(i);
2380c1bc742181ded4930842b46e9507372f0b1b963James Dong            final TaskStack stack = win.getStack();
2390c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (win.isVisibleLw() && stack != null && stack != focusedStack) {
2400c1bc742181ded4930842b46e9507372f0b1b963James Dong                mTmpRect.set(win.mVisibleFrame);
2410c1bc742181ded4930842b46e9507372f0b1b963James Dong                mTmpRect.intersect(win.mVisibleInsets);
2420c1bc742181ded4930842b46e9507372f0b1b963James Dong                mTouchExcludeRegion.op(mTmpRect, Region.Op.DIFFERENCE);
2430c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
2440c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
2450c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
2460c1bc742181ded4930842b46e9507372f0b1b963James Dong
2470c1bc742181ded4930842b46e9507372f0b1b963James Dong    void switchUserStacks(int newUserId) {
2480c1bc742181ded4930842b46e9507372f0b1b963James Dong        final WindowList windows = getWindowList();
2490c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (int i = 0; i < windows.size(); i++) {
2500c1bc742181ded4930842b46e9507372f0b1b963James Dong            final WindowState win = windows.get(i);
2510c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (win.isHiddenFromUserLocked()) {
2520c1bc742181ded4930842b46e9507372f0b1b963James Dong                if (DEBUG_VISIBILITY) Slog.w(TAG, "user changing " + newUserId + " hiding "
2530c1bc742181ded4930842b46e9507372f0b1b963James Dong                        + win + ", attrs=" + win.mAttrs.type + ", belonging to "
2540c1bc742181ded4930842b46e9507372f0b1b963James Dong                        + win.mOwnerUid);
2550c1bc742181ded4930842b46e9507372f0b1b963James Dong                win.hideLw(false);
2560c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
2570c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
2580c1bc742181ded4930842b46e9507372f0b1b963James Dong
2590c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
2600c1bc742181ded4930842b46e9507372f0b1b963James Dong            mStacks.get(stackNdx).switchUser(newUserId);
2610c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
2620c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
2630c1bc742181ded4930842b46e9507372f0b1b963James Dong
2640c1bc742181ded4930842b46e9507372f0b1b963James Dong    void resetAnimationBackgroundAnimator() {
2650c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
2660c1bc742181ded4930842b46e9507372f0b1b963James Dong            mStacks.get(stackNdx).resetAnimationBackgroundAnimator();
2670c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
2680c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
2690c1bc742181ded4930842b46e9507372f0b1b963James Dong
2700c1bc742181ded4930842b46e9507372f0b1b963James Dong    boolean animateDimLayers() {
2710c1bc742181ded4930842b46e9507372f0b1b963James Dong        boolean result = false;
2720c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
2730c1bc742181ded4930842b46e9507372f0b1b963James Dong            result |= mStacks.get(stackNdx).animateDimLayers();
2740c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
2750c1bc742181ded4930842b46e9507372f0b1b963James Dong        return result;
2760c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
2770c1bc742181ded4930842b46e9507372f0b1b963James Dong
2780c1bc742181ded4930842b46e9507372f0b1b963James Dong    void resetDimming() {
2790c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
2800c1bc742181ded4930842b46e9507372f0b1b963James Dong            mStacks.get(stackNdx).resetDimmingTag();
2810c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
2820c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
2830c1bc742181ded4930842b46e9507372f0b1b963James Dong
2840c1bc742181ded4930842b46e9507372f0b1b963James Dong    boolean isDimming() {
2850c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
2860c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (mStacks.get(stackNdx).isDimming()) {
2870c1bc742181ded4930842b46e9507372f0b1b963James Dong                return true;
2880c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
2890c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
2900c1bc742181ded4930842b46e9507372f0b1b963James Dong        return false;
2910c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
2920c1bc742181ded4930842b46e9507372f0b1b963James Dong
2930c1bc742181ded4930842b46e9507372f0b1b963James Dong    void stopDimmingIfNeeded() {
2940c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
2950c1bc742181ded4930842b46e9507372f0b1b963James Dong            mStacks.get(stackNdx).stopDimmingIfNeeded();
2960c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
2970c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
2980c1bc742181ded4930842b46e9507372f0b1b963James Dong
2990c1bc742181ded4930842b46e9507372f0b1b963James Dong    void close() {
3000c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
3010c1bc742181ded4930842b46e9507372f0b1b963James Dong            mStacks.get(stackNdx).close();
3020c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
3030c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
3040c1bc742181ded4930842b46e9507372f0b1b963James Dong
3050c1bc742181ded4930842b46e9507372f0b1b963James Dong    public void dump(String prefix, PrintWriter pw) {
3060c1bc742181ded4930842b46e9507372f0b1b963James Dong        pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
3070c1bc742181ded4930842b46e9507372f0b1b963James Dong        final String subPrefix = "  " + prefix;
3080c1bc742181ded4930842b46e9507372f0b1b963James Dong        pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
3090c1bc742181ded4930842b46e9507372f0b1b963James Dong            pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
3100c1bc742181ded4930842b46e9507372f0b1b963James Dong            pw.print("dpi");
3110c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (mInitialDisplayWidth != mBaseDisplayWidth
3120c1bc742181ded4930842b46e9507372f0b1b963James Dong                    || mInitialDisplayHeight != mBaseDisplayHeight
3130c1bc742181ded4930842b46e9507372f0b1b963James Dong                    || mInitialDisplayDensity != mBaseDisplayDensity) {
3140c1bc742181ded4930842b46e9507372f0b1b963James Dong                pw.print(" base=");
3150c1bc742181ded4930842b46e9507372f0b1b963James Dong                pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
3160c1bc742181ded4930842b46e9507372f0b1b963James Dong                pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
3170c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
3180c1bc742181ded4930842b46e9507372f0b1b963James Dong            pw.print(" cur=");
3190c1bc742181ded4930842b46e9507372f0b1b963James Dong            pw.print(mDisplayInfo.logicalWidth);
3200c1bc742181ded4930842b46e9507372f0b1b963James Dong            pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
3210c1bc742181ded4930842b46e9507372f0b1b963James Dong            pw.print(" app=");
3220c1bc742181ded4930842b46e9507372f0b1b963James Dong            pw.print(mDisplayInfo.appWidth);
3230c1bc742181ded4930842b46e9507372f0b1b963James Dong            pw.print("x"); pw.print(mDisplayInfo.appHeight);
3240c1bc742181ded4930842b46e9507372f0b1b963James Dong            pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
3250c1bc742181ded4930842b46e9507372f0b1b963James Dong            pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
3260c1bc742181ded4930842b46e9507372f0b1b963James Dong            pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
3270c1bc742181ded4930842b46e9507372f0b1b963James Dong            pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
3280c1bc742181ded4930842b46e9507372f0b1b963James Dong            pw.print(subPrefix); pw.print("layoutNeeded="); pw.println(layoutNeeded);
3290c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
3300c1bc742181ded4930842b46e9507372f0b1b963James Dong            final TaskStack stack = mStacks.get(stackNdx);
3310c1bc742181ded4930842b46e9507372f0b1b963James Dong            pw.print(prefix); pw.print("mStacks[" + stackNdx + "]"); pw.println(stack.mStackId);
3320c1bc742181ded4930842b46e9507372f0b1b963James Dong            stack.dump(prefix + "  ", pw);
3330c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
3340c1bc742181ded4930842b46e9507372f0b1b963James Dong        pw.println();
3350c1bc742181ded4930842b46e9507372f0b1b963James Dong        pw.println("  Application tokens in bottom up Z order:");
3360c1bc742181ded4930842b46e9507372f0b1b963James Dong        int ndx = 0;
3370c1bc742181ded4930842b46e9507372f0b1b963James Dong        final int numStacks = mStacks.size();
3380c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
3390c1bc742181ded4930842b46e9507372f0b1b963James Dong            ArrayList<Task> tasks = mStacks.get(stackNdx).getTasks();
3400c1bc742181ded4930842b46e9507372f0b1b963James Dong            for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
3410c1bc742181ded4930842b46e9507372f0b1b963James Dong                AppTokenList tokens = tasks.get(taskNdx).mAppTokens;
3420c1bc742181ded4930842b46e9507372f0b1b963James Dong                for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
3430c1bc742181ded4930842b46e9507372f0b1b963James Dong                    final AppWindowToken wtoken = tokens.get(tokenNdx);
3440c1bc742181ded4930842b46e9507372f0b1b963James Dong                    pw.print("  App #"); pw.print(ndx++);
3450c1bc742181ded4930842b46e9507372f0b1b963James Dong                            pw.print(' '); pw.print(wtoken); pw.println(":");
3460c1bc742181ded4930842b46e9507372f0b1b963James Dong                    wtoken.dump(pw, "    ");
3470c1bc742181ded4930842b46e9507372f0b1b963James Dong                }
3480c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
3490c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
3500c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (ndx == 0) {
3510c1bc742181ded4930842b46e9507372f0b1b963James Dong            pw.println("    None");
3520c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
3530c1bc742181ded4930842b46e9507372f0b1b963James Dong        pw.println();
3540c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (!mExitingTokens.isEmpty()) {
3550c1bc742181ded4930842b46e9507372f0b1b963James Dong            pw.println();
3560c1bc742181ded4930842b46e9507372f0b1b963James Dong            pw.println("  Exiting tokens:");
3570c1bc742181ded4930842b46e9507372f0b1b963James Dong            for (int i=mExitingTokens.size()-1; i>=0; i--) {
3580c1bc742181ded4930842b46e9507372f0b1b963James Dong                WindowToken token = mExitingTokens.get(i);
3590c1bc742181ded4930842b46e9507372f0b1b963James Dong                pw.print("  Exiting #"); pw.print(i);
3600c1bc742181ded4930842b46e9507372f0b1b963James Dong                pw.print(' '); pw.print(token);
3610c1bc742181ded4930842b46e9507372f0b1b963James Dong                pw.println(':');
3620c1bc742181ded4930842b46e9507372f0b1b963James Dong                token.dump(pw, "    ");
3630c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
3640c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
3650c1bc742181ded4930842b46e9507372f0b1b963James Dong        pw.println();
3660c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
3670c1bc742181ded4930842b46e9507372f0b1b963James Dong
3680c1bc742181ded4930842b46e9507372f0b1b963James Dong    @Override
3690c1bc742181ded4930842b46e9507372f0b1b963James Dong    public String toString() {
3700c1bc742181ded4930842b46e9507372f0b1b963James Dong        return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mStacks;
3710c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
3720c1bc742181ded4930842b46e9507372f0b1b963James Dong}
3730c1bc742181ded4930842b46e9507372f0b1b963James Dong