Task.java revision 234dbf875f795fdb72f82dc6ea805201ee31fb0e
1b1fd65c0ff5784b90d765edb7e3c3115d767dff0Craig Mautner/*
2b1fd65c0ff5784b90d765edb7e3c3115d767dff0Craig Mautner * Copyright (C) 2013 The Android Open Source Project
3b1fd65c0ff5784b90d765edb7e3c3115d767dff0Craig Mautner *
4b1fd65c0ff5784b90d765edb7e3c3115d767dff0Craig Mautner * Licensed under the Apache License, Version 2.0 (the "License");
5b1fd65c0ff5784b90d765edb7e3c3115d767dff0Craig Mautner * you may not use this file except in compliance with the License.
6b1fd65c0ff5784b90d765edb7e3c3115d767dff0Craig Mautner * You may obtain a copy of the License at
7b1fd65c0ff5784b90d765edb7e3c3115d767dff0Craig Mautner *
8b1fd65c0ff5784b90d765edb7e3c3115d767dff0Craig Mautner *      http://www.apache.org/licenses/LICENSE-2.0
9b1fd65c0ff5784b90d765edb7e3c3115d767dff0Craig Mautner *
10b1fd65c0ff5784b90d765edb7e3c3115d767dff0Craig Mautner * Unless required by applicable law or agreed to in writing, software
11b1fd65c0ff5784b90d765edb7e3c3115d767dff0Craig Mautner * distributed under the License is distributed on an "AS IS" BASIS,
12b1fd65c0ff5784b90d765edb7e3c3115d767dff0Craig Mautner * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13b1fd65c0ff5784b90d765edb7e3c3115d767dff0Craig Mautner * See the License for the specific language governing permissions and
14b1fd65c0ff5784b90d765edb7e3c3115d767dff0Craig Mautner * limitations under the License.
15b1fd65c0ff5784b90d765edb7e3c3115d767dff0Craig Mautner */
16b1fd65c0ff5784b90d765edb7e3c3115d767dff0Craig Mautner
17b1fd65c0ff5784b90d765edb7e3c3115d767dff0Craig Mautnerpackage com.android.server.wm;
18b1fd65c0ff5784b90d765edb7e3c3115d767dff0Craig Mautner
1942bf39edbdad19f51497938d0a3469dd772f19e8Craig Mautnerimport static com.android.server.wm.WindowManagerService.TAG;
20e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwaleimport static com.android.server.wm.WindowManagerService.DEBUG_RESIZE;
21e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautnerimport static com.android.server.wm.WindowManagerService.DEBUG_STACK;
22234dbf875f795fdb72f82dc6ea805201ee31fb0eStefan Kuhneimport static android.app.ActivityManager.FREEFORM_WORKSPACE_STACK_ID;
2342bf39edbdad19f51497938d0a3469dd772f19e8Craig Mautner
24e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwaleimport android.content.res.Configuration;
25e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwaleimport android.graphics.Rect;
26e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwaleimport android.util.DisplayMetrics;
272c2549c5f44b712dbbf66a69d91f07d6f5336ee6Craig Mautnerimport android.util.EventLog;
2842bf39edbdad19f51497938d0a3469dd772f19e8Craig Mautnerimport android.util.Slog;
29e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwaleimport android.util.SparseArray;
30e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwaleimport android.util.TypedValue;
31e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwaleimport android.view.DisplayInfo;
32e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwaleimport android.view.Surface;
33e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
34e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautnerimport com.android.server.EventLogTags;
352c2549c5f44b712dbbf66a69d91f07d6f5336ee6Craig Mautner
36e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwaleimport java.io.PrintWriter;
37e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwaleimport java.util.ArrayList;
38e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
39e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwaleclass Task implements DimLayer.DimLayerUser {
40e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    /** Amount of time in milliseconds to animate the dim surface from one value to another,
41e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale     * when no window animation is driving it. */
42e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    private static final int DEFAULT_DIM_DURATION = 200;
43e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
44c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner    TaskStack mStack;
4505d6272bad2d707b488a6f8784ce8aea5e25b110Craig Mautner    final AppTokenList mAppTokens = new AppTokenList();
4683162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner    final int mTaskId;
47ac6f843c917b68ea8805711965b149a9338e3a0eCraig Mautner    final int mUserId;
489ef471f7f2f59de032d7cb9c3c7241486109979eCraig Mautner    boolean mDeferRemoval = false;
49e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautner    final WindowManagerService mService;
50b1fd65c0ff5784b90d765edb7e3c3115d767dff0Craig Mautner
51e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    // Content limits relative to the DisplayContent this sits in.
52e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    private Rect mBounds = new Rect();
53e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
54e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    // Device rotation as of the last time {@link #mBounds} was set.
55e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    int mRotation;
56e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
57e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    // Whether mBounds is fullscreen
58e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    private boolean mFullscreen = true;
59e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
60e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    // Contains configurations settings that are different from the global configuration due to
61e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    // stack specific operations. E.g. {@link #setBounds}.
62e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    Configuration mOverrideConfig;
63e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
64e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    // For comparison with DisplayContent bounds.
65e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    private Rect mTmpRect = new Rect();
66e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    // For handling display rotations.
67e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    private Rect mTmpRect2 = new Rect();
68e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
69e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    // The particular window with FLAG_DIM_BEHIND set. If null, hide mDimLayer.
70e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    WindowStateAnimator mDimWinAnimator;
71e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    // Used to support {@link android.view.WindowManager.LayoutParams#FLAG_DIM_BEHIND}
72e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    private DimLayer mDimLayer;
73e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    // Set to false at the start of performLayoutAndPlaceSurfaces. If it is still false by the end
74e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    // then stop any dimming.
75e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    private boolean mContinueDimming;
76e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    // Shared dim layer for fullscreen tasks. {@link #mDimLayer} will point to this instead
77e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    // of creating a new object per fullscreen task on a display.
78e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    private static final SparseArray<DimLayer> sSharedFullscreenDimLayers = new SparseArray<>();
79e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
80706ed793409f800a2b8dfbe66ac6992d057549deWale Ogunwale    Task(int taskId, TaskStack stack, int userId, WindowManagerService service, Rect bounds) {
8183162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner        mTaskId = taskId;
82c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner        mStack = stack;
83ac6f843c917b68ea8805711965b149a9338e3a0eCraig Mautner        mUserId = userId;
84e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautner        mService = service;
85e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        mOverrideConfig = Configuration.EMPTY;
86706ed793409f800a2b8dfbe66ac6992d057549deWale Ogunwale        setBounds(bounds);
87c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner    }
88c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner
89c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner    DisplayContent getDisplayContent() {
90c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner        return mStack.getDisplayContent();
91c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner    }
92c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner
93c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner    void addAppToken(int addPos, AppWindowToken wtoken) {
9442bf39edbdad19f51497938d0a3469dd772f19e8Craig Mautner        final int lastPos = mAppTokens.size();
9583162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner        if (addPos >= lastPos) {
9683162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner            addPos = lastPos;
9783162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner        } else {
9883162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner            for (int pos = 0; pos < lastPos && pos < addPos; ++pos) {
9983162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner                if (mAppTokens.get(pos).removed) {
10083162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner                    // addPos assumes removed tokens are actually gone.
10183162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner                    ++addPos;
10283162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner                }
10301f79cf91610ec9f85345ea6eeae50ea2f28578fCraig Mautner            }
10442bf39edbdad19f51497938d0a3469dd772f19e8Craig Mautner        }
105c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner        mAppTokens.add(addPos, wtoken);
10683162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner        wtoken.mTask = this;
10742bf39edbdad19f51497938d0a3469dd772f19e8Craig Mautner        mDeferRemoval = false;
108c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner    }
109c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner
110e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautner    void removeLocked() {
111e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautner        if (!mAppTokens.isEmpty() && mStack.isAnimating()) {
11283162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner            if (DEBUG_STACK) Slog.i(TAG, "removeTask: deferring removing taskId=" + mTaskId);
113e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautner            mDeferRemoval = true;
114e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautner            return;
115e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautner        }
11683162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner        if (DEBUG_STACK) Slog.i(TAG, "removeTask: removing taskId=" + mTaskId);
11783162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner        EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "removeTask");
118e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautner        mDeferRemoval = false;
119e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautner        mStack.removeTask(this);
12083162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner        mService.mTaskIdToTask.delete(mTaskId);
121e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautner    }
122e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautner
12353a29a90f35f72462c0d6ad650921d5566c1f8f0Wale Ogunwale    void moveTaskToStack(TaskStack stack, boolean toTop) {
12453a29a90f35f72462c0d6ad650921d5566c1f8f0Wale Ogunwale        if (stack == mStack) {
12553a29a90f35f72462c0d6ad650921d5566c1f8f0Wale Ogunwale            return;
12653a29a90f35f72462c0d6ad650921d5566c1f8f0Wale Ogunwale        }
12753a29a90f35f72462c0d6ad650921d5566c1f8f0Wale Ogunwale        if (DEBUG_STACK) Slog.i(TAG, "moveTaskToStack: removing taskId=" + mTaskId
12853a29a90f35f72462c0d6ad650921d5566c1f8f0Wale Ogunwale                + " from stack=" + mStack);
129000957cef387dc7d08fc6563e2221e9023194984Wale Ogunwale        EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "moveTask");
13053a29a90f35f72462c0d6ad650921d5566c1f8f0Wale Ogunwale        if (mStack != null) {
13153a29a90f35f72462c0d6ad650921d5566c1f8f0Wale Ogunwale            mStack.removeTask(this);
13253a29a90f35f72462c0d6ad650921d5566c1f8f0Wale Ogunwale        }
13353a29a90f35f72462c0d6ad650921d5566c1f8f0Wale Ogunwale        stack.addTask(this, toTop);
13453a29a90f35f72462c0d6ad650921d5566c1f8f0Wale Ogunwale    }
13553a29a90f35f72462c0d6ad650921d5566c1f8f0Wale Ogunwale
136ddc1cb2c15549ed23dce9d416680a009fa6ae23cWale Ogunwale    void positionTaskInStack(TaskStack stack, int position) {
137ddc1cb2c15549ed23dce9d416680a009fa6ae23cWale Ogunwale        if (mStack != null && stack != mStack) {
138ddc1cb2c15549ed23dce9d416680a009fa6ae23cWale Ogunwale            if (DEBUG_STACK) Slog.i(TAG, "positionTaskInStack: removing taskId=" + mTaskId
139ddc1cb2c15549ed23dce9d416680a009fa6ae23cWale Ogunwale                    + " from stack=" + mStack);
140ddc1cb2c15549ed23dce9d416680a009fa6ae23cWale Ogunwale            EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "moveTask");
141ddc1cb2c15549ed23dce9d416680a009fa6ae23cWale Ogunwale            mStack.removeTask(this);
142ddc1cb2c15549ed23dce9d416680a009fa6ae23cWale Ogunwale        }
143ddc1cb2c15549ed23dce9d416680a009fa6ae23cWale Ogunwale        stack.positionTask(this, position, showForAllUsers());
144ddc1cb2c15549ed23dce9d416680a009fa6ae23cWale Ogunwale    }
145ddc1cb2c15549ed23dce9d416680a009fa6ae23cWale Ogunwale
146c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner    boolean removeAppToken(AppWindowToken wtoken) {
14742bf39edbdad19f51497938d0a3469dd772f19e8Craig Mautner        boolean removed = mAppTokens.remove(wtoken);
148c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner        if (mAppTokens.size() == 0) {
149000957cef387dc7d08fc6563e2221e9023194984Wale Ogunwale            EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId,
1502c2549c5f44b712dbbf66a69d91f07d6f5336ee6Craig Mautner                    "removeAppToken: last token");
151e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautner            if (mDeferRemoval) {
152e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautner                removeLocked();
153e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautner            }
154c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner        }
15583162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner        wtoken.mTask = null;
15683162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner        /* Leave mTaskId for now, it might be useful for debug
15783162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner        wtoken.mTaskId = -1;
15883162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner         */
15942bf39edbdad19f51497938d0a3469dd772f19e8Craig Mautner        return removed;
160b1fd65c0ff5784b90d765edb7e3c3115d767dff0Craig Mautner    }
1615d9c7be84d9628c1cf199fcf9015942835c4671bCraig Mautner
162cbd84af39a329890013b0c3b6763280ba2ad78c9Craig Mautner    void setSendingToBottom(boolean toBottom) {
163cbd84af39a329890013b0c3b6763280ba2ad78c9Craig Mautner        for (int appTokenNdx = 0; appTokenNdx < mAppTokens.size(); appTokenNdx++) {
164cbd84af39a329890013b0c3b6763280ba2ad78c9Craig Mautner            mAppTokens.get(appTokenNdx).sendingToBottom = toBottom;
165cbd84af39a329890013b0c3b6763280ba2ad78c9Craig Mautner        }
166cbd84af39a329890013b0c3b6763280ba2ad78c9Craig Mautner    }
167cbd84af39a329890013b0c3b6763280ba2ad78c9Craig Mautner
168e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    /** Set the task bounds. Passing in null sets the bounds to fullscreen. */
169e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    boolean setBounds(Rect bounds) {
170e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        boolean oldFullscreen = mFullscreen;
171e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        int rotation = Surface.ROTATION_0;
172e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        final DisplayContent displayContent = mStack.getDisplayContent();
173e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        if (displayContent != null) {
174e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            displayContent.getLogicalDisplayRect(mTmpRect);
175e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            rotation = displayContent.getDisplayInfo().rotation;
176e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            if (bounds == null) {
177e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                bounds = mTmpRect;
178e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                mFullscreen = true;
179e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            } else {
180234dbf875f795fdb72f82dc6ea805201ee31fb0eStefan Kuhne                if (mStack.mStackId != FREEFORM_WORKSPACE_STACK_ID || bounds.isEmpty()) {
181234dbf875f795fdb72f82dc6ea805201ee31fb0eStefan Kuhne                    // ensure bounds are entirely within the display rect
182234dbf875f795fdb72f82dc6ea805201ee31fb0eStefan Kuhne                    if (!bounds.intersect(mTmpRect)) {
183234dbf875f795fdb72f82dc6ea805201ee31fb0eStefan Kuhne                        // Can't set bounds outside the containing display...Sorry!
184234dbf875f795fdb72f82dc6ea805201ee31fb0eStefan Kuhne                        return false;
185234dbf875f795fdb72f82dc6ea805201ee31fb0eStefan Kuhne                    }
186e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                }
187e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                mFullscreen = mTmpRect.equals(bounds);
188e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            }
189e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        }
190e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
191e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        if (bounds == null) {
192e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            // Can't set to fullscreen if we don't have a display to get bounds from...
193e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            return false;
194e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        }
195e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        if (mBounds.equals(bounds) && oldFullscreen == mFullscreen && mRotation == rotation) {
196e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            return false;
197e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        }
198e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
199e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        mBounds.set(bounds);
200e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        mRotation = rotation;
201e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        updateDimLayer();
202e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        updateOverrideConfiguration();
203e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        return true;
204e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    }
205e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
206e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    void getBounds(Rect out) {
207e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        out.set(mBounds);
208e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    }
209e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
210e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    private void updateOverrideConfiguration() {
211e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        final Configuration serviceConfig = mService.mCurConfiguration;
212e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        if (mFullscreen) {
213e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            mOverrideConfig = Configuration.EMPTY;
214e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            return;
215e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        }
216e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
217e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        if (mOverrideConfig == Configuration.EMPTY) {
218e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            mOverrideConfig  = new Configuration();
219e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        }
220e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
221e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        // TODO(multidisplay): Update Dp to that of display stack is on.
222e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        final float density = serviceConfig.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
223e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        mOverrideConfig.screenWidthDp =
224e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                Math.min((int)(mBounds.width() / density), serviceConfig.screenWidthDp);
225e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        mOverrideConfig.screenHeightDp =
226e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                Math.min((int)(mBounds.height() / density), serviceConfig.screenHeightDp);
227e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        mOverrideConfig.smallestScreenWidthDp =
228e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                Math.min(mOverrideConfig.screenWidthDp, mOverrideConfig.screenHeightDp);
229e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        mOverrideConfig.orientation =
230e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                (mOverrideConfig.screenWidthDp <= mOverrideConfig.screenHeightDp)
231e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                        ? Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
232e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    }
233e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
234e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    void updateDisplayInfo(final DisplayContent displayContent) {
235e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        if (displayContent == null) {
236e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            return;
237e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        }
238e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        if (mFullscreen) {
239e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            setBounds(null);
240e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            return;
241e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        }
242e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        final int newRotation = displayContent.getDisplayInfo().rotation;
243e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        if (mRotation == newRotation) {
244e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            return;
245e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        }
246e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
247e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        // Device rotation changed. We don't want the task to move around on the screen when
248e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        // this happens, so update the task bounds so it stays in the same place.
249e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        final int rotationDelta = DisplayContent.deltaRotation(mRotation, newRotation);
250e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        displayContent.getLogicalDisplayRect(mTmpRect);
251e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        switch (rotationDelta) {
252e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            case Surface.ROTATION_0:
253e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                mTmpRect2.set(mBounds);
254e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                break;
255e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            case Surface.ROTATION_90:
256e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                mTmpRect2.top = mTmpRect.bottom - mBounds.right;
257e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                mTmpRect2.left = mBounds.top;
258e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                mTmpRect2.right = mTmpRect2.left + mBounds.height();
259e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                mTmpRect2.bottom = mTmpRect2.top + mBounds.width();
260e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                break;
261e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            case Surface.ROTATION_180:
262e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                mTmpRect2.top = mTmpRect.bottom - mBounds.bottom;
263e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                mTmpRect2.left = mTmpRect.right - mBounds.right;
264e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                mTmpRect2.right = mTmpRect2.left + mBounds.width();
265e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                mTmpRect2.bottom = mTmpRect2.top + mBounds.height();
266e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                break;
267e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            case Surface.ROTATION_270:
268e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                mTmpRect2.top = mBounds.left;
269e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                mTmpRect2.left = mTmpRect.right - mBounds.bottom;
270e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                mTmpRect2.right = mTmpRect2.left + mBounds.height();
271e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                mTmpRect2.bottom = mTmpRect2.top + mBounds.width();
272e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                break;
273e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        }
274e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        setBounds(mTmpRect2);
275e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    }
276e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
277e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    /** Updates the dim layer bounds, recreating it if needed. */
278e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    private void updateDimLayer() {
279e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        DimLayer newDimLayer;
280e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        final boolean previousFullscreen =
281e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                mDimLayer != null && sSharedFullscreenDimLayers.indexOfValue(mDimLayer) > -1;
282e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        final int displayId = mStack.getDisplayContent().getDisplayId();
283e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        if (mFullscreen) {
284e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            if (previousFullscreen) {
285e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                // Nothing to do here...
286e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                return;
287e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            }
288e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            // Use shared fullscreen dim layer
289e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            newDimLayer = sSharedFullscreenDimLayers.get(displayId);
290e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            if (newDimLayer == null) {
291e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                if (mDimLayer != null) {
292e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                    // Re-purpose the previous dim layer.
293e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                    newDimLayer = mDimLayer;
294e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                } else {
295e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                    // Create new full screen dim layer.
296e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                    newDimLayer = new DimLayer(mService, this, displayId);
297e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                }
298e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                newDimLayer.setBounds(mBounds);
299e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                sSharedFullscreenDimLayers.put(displayId, newDimLayer);
300e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            } else if (mDimLayer != null) {
301e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                mDimLayer.destroySurface();
302e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            }
303e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        } else {
304e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            newDimLayer = (mDimLayer == null || previousFullscreen)
305e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                    ? new DimLayer(mService, this, displayId) : mDimLayer;
306e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            newDimLayer.setBounds(mBounds);
307e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        }
308e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        mDimLayer = newDimLayer;
309e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    }
310e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
311e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    boolean animateDimLayers() {
312e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        final int dimLayer;
313e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        final float dimAmount;
314e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        if (mDimWinAnimator == null) {
315e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            dimLayer = mDimLayer.getLayer();
316e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            dimAmount = 0;
317e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        } else {
318e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            dimLayer = mDimWinAnimator.mAnimLayer - WindowManagerService.LAYER_OFFSET_DIM;
319e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            dimAmount = mDimWinAnimator.mWin.mAttrs.dimAmount;
320e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        }
321e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        final float targetAlpha = mDimLayer.getTargetAlpha();
322e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        if (targetAlpha != dimAmount) {
323e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            if (mDimWinAnimator == null) {
324e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                mDimLayer.hide(DEFAULT_DIM_DURATION);
325e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            } else {
326e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                long duration = (mDimWinAnimator.mAnimating && mDimWinAnimator.mAnimation != null)
327e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                        ? mDimWinAnimator.mAnimation.computeDurationHint()
328e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                        : DEFAULT_DIM_DURATION;
329e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                if (targetAlpha > dimAmount) {
330e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                    duration = getDimBehindFadeDuration(duration);
331e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                }
332e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                mDimLayer.show(dimLayer, dimAmount, duration);
333e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            }
334e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        } else if (mDimLayer.getLayer() != dimLayer) {
335e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            mDimLayer.setLayer(dimLayer);
336e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        }
337e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        if (mDimLayer.isAnimating()) {
338e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            if (!mService.okToDisplay()) {
339e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                // Jump to the end of the animation.
340e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                mDimLayer.show();
341e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            } else {
342e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                return mDimLayer.stepAnimation();
343e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            }
344e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        }
345e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        return false;
346e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    }
347e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
348e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    private long getDimBehindFadeDuration(long duration) {
349e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        TypedValue tv = new TypedValue();
350e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        mService.mContext.getResources().getValue(
351e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                com.android.internal.R.fraction.config_dimBehindFadeDuration, tv, true);
352e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        if (tv.type == TypedValue.TYPE_FRACTION) {
353e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            duration = (long)tv.getFraction(duration, duration);
354e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        } else if (tv.type >= TypedValue.TYPE_FIRST_INT && tv.type <= TypedValue.TYPE_LAST_INT) {
355e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            duration = tv.data;
356e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        }
357e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        return duration;
358e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    }
359e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
360e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    void clearContinueDimming() {
361e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        mContinueDimming = false;
362e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    }
363e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
364e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    void setContinueDimming() {
365e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        mContinueDimming = true;
366e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    }
367e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
368e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    boolean getContinueDimming() {
369e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        return mContinueDimming;
370e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    }
371e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
372e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    boolean isDimming() {
373e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        return mDimLayer.isDimming();
374e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    }
375e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
376e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    boolean isDimming(WindowStateAnimator winAnimator) {
377e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        return mDimWinAnimator == winAnimator && isDimming();
378e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    }
379e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
380e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    void startDimmingIfNeeded(WindowStateAnimator newWinAnimator) {
381e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        // Only set dim params on the highest dimmed layer.
382e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        // Don't turn on for an unshown surface, or for any layer but the highest dimmed layer.
383e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        if (newWinAnimator.mSurfaceShown && (mDimWinAnimator == null
384e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                || !mDimWinAnimator.mSurfaceShown
385e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                || mDimWinAnimator.mAnimLayer < newWinAnimator.mAnimLayer)) {
386e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            mDimWinAnimator = newWinAnimator;
387e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            if (mDimWinAnimator.mWin.mAppToken == null
388e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                    && !mFullscreen && mStack.getDisplayContent() != null) {
389e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                // Dim should cover the entire screen for system windows.
390e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                mStack.getDisplayContent().getLogicalDisplayRect(mTmpRect);
391e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                mDimLayer.setBounds(mTmpRect);
392e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            }
393e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        }
394e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    }
395e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
396e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    void stopDimmingIfNeeded() {
397e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        if (!mContinueDimming && isDimming()) {
398e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            mDimWinAnimator = null;
399e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            mDimLayer.setBounds(mBounds);
400e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        }
401e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    }
402e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
403e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    void close() {
404e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        if (mDimLayer != null) {
405e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            mDimLayer.destroySurface();
406e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            mDimLayer = null;
407e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        }
408e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    }
409e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
410e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    void resizeWindows() {
411e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
412e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) {
413e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            final ArrayList<WindowState> windows = mAppTokens.get(activityNdx).allAppWindows;
414e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) {
415e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                final WindowState win = windows.get(winNdx);
416e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                if (!resizingWindows.contains(win)) {
417e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                    if (DEBUG_RESIZE) Slog.d(TAG, "setBounds: Resizing " + win);
418e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                    resizingWindows.add(win);
419e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                }
420e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            }
421e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        }
422e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    }
423e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
4246dfdfd6741c5a3dd8d8a49ddbd6ee5dfe2fd292dWale Ogunwale    boolean showForAllUsers() {
4253fcb4a89750d6df42f850021cd754500fc084086Wale Ogunwale        final int tokensCount = mAppTokens.size();
4266dfdfd6741c5a3dd8d8a49ddbd6ee5dfe2fd292dWale Ogunwale        return (tokensCount != 0) && mAppTokens.get(tokensCount - 1).showForAllUsers;
4273fcb4a89750d6df42f850021cd754500fc084086Wale Ogunwale    }
4283fcb4a89750d6df42f850021cd754500fc084086Wale Ogunwale
4295d9c7be84d9628c1cf199fcf9015942835c4671bCraig Mautner    @Override
430e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    public boolean isFullscreen() {
431e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        return mFullscreen;
432e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    }
433e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
434e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    @Override
435e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    public DisplayInfo getDisplayInfo() {
436e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        return mStack.getDisplayContent().getDisplayInfo();
437e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    }
438e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
439e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    @Override
4405d9c7be84d9628c1cf199fcf9015942835c4671bCraig Mautner    public String toString() {
44183162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner        return "{taskId=" + mTaskId + " appTokens=" + mAppTokens + " mdr=" + mDeferRemoval + "}";
4425d9c7be84d9628c1cf199fcf9015942835c4671bCraig Mautner    }
443e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale
444e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    public void printTo(String prefix, PrintWriter pw) {
445e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        pw.print(prefix); pw.print("taskId="); pw.print(mTaskId);
446e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                pw.print(prefix); pw.print("appTokens="); pw.print(mAppTokens);
447e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale                pw.print(prefix); pw.print("mdr="); pw.println(mDeferRemoval);
448e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        if (mDimLayer.isDimming()) {
449e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            pw.print(prefix); pw.println("mDimLayer:");
450e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            mDimLayer.printTo(prefix + " ", pw);
451e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            pw.print(prefix); pw.print("mDimWinAnimator="); pw.println(mDimWinAnimator);
452e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        } else {
453e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale            pw.println();
454e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale        }
455e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale    }
456b1fd65c0ff5784b90d765edb7e3c3115d767dff0Craig Mautner}
457