Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 19 | import static android.app.ActivityManager.DOCKED_STACK_ID; |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 20 | import static com.android.server.wm.WindowManagerService.TAG; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 21 | import static com.android.server.wm.WindowManagerService.DEBUG_RESIZE; |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 22 | import static com.android.server.wm.WindowManagerService.DEBUG_STACK; |
Stefan Kuhne | 234dbf8 | 2015-08-13 09:44:28 -0700 | [diff] [blame] | 23 | import static android.app.ActivityManager.FREEFORM_WORKSPACE_STACK_ID; |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 24 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 25 | import android.content.res.Configuration; |
| 26 | import android.graphics.Rect; |
Craig Mautner | 2c2549c | 2013-11-12 08:31:15 -0800 | [diff] [blame] | 27 | import android.util.EventLog; |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 28 | import android.util.Slog; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 29 | import android.util.SparseArray; |
| 30 | import android.util.TypedValue; |
| 31 | import android.view.DisplayInfo; |
| 32 | import android.view.Surface; |
| 33 | |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 34 | import com.android.server.EventLogTags; |
Craig Mautner | 2c2549c | 2013-11-12 08:31:15 -0800 | [diff] [blame] | 35 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 36 | import java.io.PrintWriter; |
| 37 | import java.util.ArrayList; |
| 38 | |
| 39 | class Task implements DimLayer.DimLayerUser { |
| 40 | /** Amount of time in milliseconds to animate the dim surface from one value to another, |
| 41 | * when no window animation is driving it. */ |
| 42 | private static final int DEFAULT_DIM_DURATION = 200; |
| 43 | |
Wale Ogunwale | 2cc92f5 | 2015-09-09 13:12:10 -0700 | [diff] [blame] | 44 | // Return value from {@link setBounds} indicating no change was made to the Task bounds. |
| 45 | static final int BOUNDS_CHANGE_NONE = 0; |
| 46 | // Return value from {@link setBounds} indicating the position of the Task bounds changed. |
| 47 | static final int BOUNDS_CHANGE_POSITION = 1; |
| 48 | // Return value from {@link setBounds} indicating the size of the Task bounds changed. |
| 49 | static final int BOUNDS_CHANGE_SIZE = 1 << 1; |
| 50 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 51 | TaskStack mStack; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 52 | final AppTokenList mAppTokens = new AppTokenList(); |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 53 | final int mTaskId; |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 54 | final int mUserId; |
Craig Mautner | 9ef471f | 2014-02-07 13:11:47 -0800 | [diff] [blame] | 55 | boolean mDeferRemoval = false; |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 56 | final WindowManagerService mService; |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 57 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 58 | // Content limits relative to the DisplayContent this sits in. |
| 59 | private Rect mBounds = new Rect(); |
| 60 | |
| 61 | // Device rotation as of the last time {@link #mBounds} was set. |
| 62 | int mRotation; |
| 63 | |
| 64 | // Whether mBounds is fullscreen |
| 65 | private boolean mFullscreen = true; |
| 66 | |
| 67 | // Contains configurations settings that are different from the global configuration due to |
| 68 | // stack specific operations. E.g. {@link #setBounds}. |
| 69 | Configuration mOverrideConfig; |
| 70 | |
| 71 | // For comparison with DisplayContent bounds. |
| 72 | private Rect mTmpRect = new Rect(); |
| 73 | // For handling display rotations. |
| 74 | private Rect mTmpRect2 = new Rect(); |
| 75 | |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 76 | // Whether the task is currently being drag-resized |
| 77 | private boolean mDragResizing; |
| 78 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 79 | // The particular window with FLAG_DIM_BEHIND set. If null, hide mDimLayer. |
| 80 | WindowStateAnimator mDimWinAnimator; |
| 81 | // Used to support {@link android.view.WindowManager.LayoutParams#FLAG_DIM_BEHIND} |
| 82 | private DimLayer mDimLayer; |
| 83 | // Set to false at the start of performLayoutAndPlaceSurfaces. If it is still false by the end |
| 84 | // then stop any dimming. |
| 85 | private boolean mContinueDimming; |
| 86 | // Shared dim layer for fullscreen tasks. {@link #mDimLayer} will point to this instead |
| 87 | // of creating a new object per fullscreen task on a display. |
| 88 | private static final SparseArray<DimLayer> sSharedFullscreenDimLayers = new SparseArray<>(); |
| 89 | |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 90 | Task(int taskId, TaskStack stack, int userId, WindowManagerService service, Rect bounds, |
| 91 | Configuration config) { |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 92 | mTaskId = taskId; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 93 | mStack = stack; |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 94 | mUserId = userId; |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 95 | mService = service; |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 96 | setBounds(bounds, config); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | DisplayContent getDisplayContent() { |
| 100 | return mStack.getDisplayContent(); |
| 101 | } |
| 102 | |
| 103 | void addAppToken(int addPos, AppWindowToken wtoken) { |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 104 | final int lastPos = mAppTokens.size(); |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 105 | if (addPos >= lastPos) { |
| 106 | addPos = lastPos; |
| 107 | } else { |
| 108 | for (int pos = 0; pos < lastPos && pos < addPos; ++pos) { |
| 109 | if (mAppTokens.get(pos).removed) { |
| 110 | // addPos assumes removed tokens are actually gone. |
| 111 | ++addPos; |
| 112 | } |
Craig Mautner | 01f79cf | 2014-08-27 09:56:02 -0700 | [diff] [blame] | 113 | } |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 114 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 115 | mAppTokens.add(addPos, wtoken); |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 116 | wtoken.mTask = this; |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 117 | mDeferRemoval = false; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 118 | } |
| 119 | |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 120 | void removeLocked() { |
| 121 | if (!mAppTokens.isEmpty() && mStack.isAnimating()) { |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 122 | if (DEBUG_STACK) Slog.i(TAG, "removeTask: deferring removing taskId=" + mTaskId); |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 123 | mDeferRemoval = true; |
| 124 | return; |
| 125 | } |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 126 | if (DEBUG_STACK) Slog.i(TAG, "removeTask: removing taskId=" + mTaskId); |
| 127 | EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "removeTask"); |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 128 | mDeferRemoval = false; |
| 129 | mStack.removeTask(this); |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 130 | mService.mTaskIdToTask.delete(mTaskId); |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 131 | } |
| 132 | |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 133 | void moveTaskToStack(TaskStack stack, boolean toTop) { |
| 134 | if (stack == mStack) { |
| 135 | return; |
| 136 | } |
| 137 | if (DEBUG_STACK) Slog.i(TAG, "moveTaskToStack: removing taskId=" + mTaskId |
| 138 | + " from stack=" + mStack); |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 139 | EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "moveTask"); |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 140 | if (mStack != null) { |
| 141 | mStack.removeTask(this); |
| 142 | } |
| 143 | stack.addTask(this, toTop); |
| 144 | } |
| 145 | |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 146 | void positionTaskInStack(TaskStack stack, int position) { |
| 147 | if (mStack != null && stack != mStack) { |
| 148 | if (DEBUG_STACK) Slog.i(TAG, "positionTaskInStack: removing taskId=" + mTaskId |
| 149 | + " from stack=" + mStack); |
| 150 | EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "moveTask"); |
| 151 | mStack.removeTask(this); |
| 152 | } |
| 153 | stack.positionTask(this, position, showForAllUsers()); |
| 154 | } |
| 155 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 156 | boolean removeAppToken(AppWindowToken wtoken) { |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 157 | boolean removed = mAppTokens.remove(wtoken); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 158 | if (mAppTokens.size() == 0) { |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 159 | EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, |
Craig Mautner | 2c2549c | 2013-11-12 08:31:15 -0800 | [diff] [blame] | 160 | "removeAppToken: last token"); |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 161 | if (mDeferRemoval) { |
| 162 | removeLocked(); |
| 163 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 164 | } |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 165 | wtoken.mTask = null; |
| 166 | /* Leave mTaskId for now, it might be useful for debug |
| 167 | wtoken.mTaskId = -1; |
| 168 | */ |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 169 | return removed; |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 170 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 171 | |
Craig Mautner | cbd84af | 2014-10-22 13:21:22 -0700 | [diff] [blame] | 172 | void setSendingToBottom(boolean toBottom) { |
| 173 | for (int appTokenNdx = 0; appTokenNdx < mAppTokens.size(); appTokenNdx++) { |
| 174 | mAppTokens.get(appTokenNdx).sendingToBottom = toBottom; |
| 175 | } |
| 176 | } |
| 177 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 178 | /** Set the task bounds. Passing in null sets the bounds to fullscreen. */ |
Wale Ogunwale | 2cc92f5 | 2015-09-09 13:12:10 -0700 | [diff] [blame] | 179 | int setBounds(Rect bounds, Configuration config) { |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 180 | if (config == null) { |
| 181 | config = Configuration.EMPTY; |
| 182 | } |
| 183 | if (bounds == null && !Configuration.EMPTY.equals(config)) { |
| 184 | throw new IllegalArgumentException("null bounds but non empty configuration: " |
| 185 | + config); |
| 186 | } |
| 187 | if (bounds != null && Configuration.EMPTY.equals(config)) { |
| 188 | throw new IllegalArgumentException("non null bounds, but empty configuration"); |
| 189 | } |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 190 | boolean oldFullscreen = mFullscreen; |
| 191 | int rotation = Surface.ROTATION_0; |
| 192 | final DisplayContent displayContent = mStack.getDisplayContent(); |
| 193 | if (displayContent != null) { |
| 194 | displayContent.getLogicalDisplayRect(mTmpRect); |
| 195 | rotation = displayContent.getDisplayInfo().rotation; |
| 196 | if (bounds == null) { |
| 197 | bounds = mTmpRect; |
| 198 | mFullscreen = true; |
| 199 | } else { |
Stefan Kuhne | 234dbf8 | 2015-08-13 09:44:28 -0700 | [diff] [blame] | 200 | if (mStack.mStackId != FREEFORM_WORKSPACE_STACK_ID || bounds.isEmpty()) { |
| 201 | // ensure bounds are entirely within the display rect |
| 202 | if (!bounds.intersect(mTmpRect)) { |
| 203 | // Can't set bounds outside the containing display...Sorry! |
Wale Ogunwale | 2cc92f5 | 2015-09-09 13:12:10 -0700 | [diff] [blame] | 204 | return BOUNDS_CHANGE_NONE; |
Stefan Kuhne | 234dbf8 | 2015-08-13 09:44:28 -0700 | [diff] [blame] | 205 | } |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 206 | } |
| 207 | mFullscreen = mTmpRect.equals(bounds); |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | if (bounds == null) { |
| 212 | // Can't set to fullscreen if we don't have a display to get bounds from... |
Wale Ogunwale | 2cc92f5 | 2015-09-09 13:12:10 -0700 | [diff] [blame] | 213 | return BOUNDS_CHANGE_NONE; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 214 | } |
| 215 | if (mBounds.equals(bounds) && oldFullscreen == mFullscreen && mRotation == rotation) { |
Wale Ogunwale | 2cc92f5 | 2015-09-09 13:12:10 -0700 | [diff] [blame] | 216 | return BOUNDS_CHANGE_NONE; |
| 217 | } |
| 218 | |
| 219 | int boundsChange = BOUNDS_CHANGE_NONE; |
| 220 | if (mBounds.left != bounds.left || mBounds.right != bounds.right) { |
| 221 | boundsChange |= BOUNDS_CHANGE_POSITION; |
| 222 | } |
| 223 | if (mBounds.width() != bounds.width() || mBounds.height() != bounds.height()) { |
| 224 | boundsChange |= BOUNDS_CHANGE_SIZE; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | mBounds.set(bounds); |
| 228 | mRotation = rotation; |
| 229 | updateDimLayer(); |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 230 | mOverrideConfig = mFullscreen ? Configuration.EMPTY : config; |
Wale Ogunwale | 2cc92f5 | 2015-09-09 13:12:10 -0700 | [diff] [blame] | 231 | return boundsChange; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Chong Zhang | 87b2172 | 2015-09-21 15:39:51 -0700 | [diff] [blame] | 234 | boolean resizeLocked(Rect bounds, Configuration configuration, boolean forced) { |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 235 | int boundsChanged = setBounds(bounds, configuration); |
Chong Zhang | 87b2172 | 2015-09-21 15:39:51 -0700 | [diff] [blame] | 236 | if (forced) { |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 237 | boundsChanged |= BOUNDS_CHANGE_SIZE; |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 238 | } |
| 239 | if (boundsChanged == BOUNDS_CHANGE_NONE) { |
| 240 | return false; |
| 241 | } |
| 242 | if ((boundsChanged & BOUNDS_CHANGE_SIZE) == BOUNDS_CHANGE_SIZE) { |
| 243 | resizeWindows(); |
| 244 | } |
| 245 | return true; |
| 246 | } |
| 247 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 248 | void getBounds(Rect out) { |
| 249 | out.set(mBounds); |
| 250 | } |
| 251 | |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 252 | void setDragResizing(boolean dragResizing) { |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 253 | mDragResizing = dragResizing; |
| 254 | } |
| 255 | |
| 256 | boolean isDragResizing() { |
| 257 | return mDragResizing; |
| 258 | } |
| 259 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 260 | void updateDisplayInfo(final DisplayContent displayContent) { |
| 261 | if (displayContent == null) { |
| 262 | return; |
| 263 | } |
| 264 | if (mFullscreen) { |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 265 | setBounds(null, Configuration.EMPTY); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 266 | return; |
| 267 | } |
| 268 | final int newRotation = displayContent.getDisplayInfo().rotation; |
| 269 | if (mRotation == newRotation) { |
| 270 | return; |
| 271 | } |
| 272 | |
| 273 | // Device rotation changed. We don't want the task to move around on the screen when |
| 274 | // this happens, so update the task bounds so it stays in the same place. |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 275 | mTmpRect2.set(mBounds); |
| 276 | displayContent.rotateBounds(mRotation, newRotation, mTmpRect2); |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 277 | setBounds(mTmpRect2, mOverrideConfig); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | /** Updates the dim layer bounds, recreating it if needed. */ |
| 281 | private void updateDimLayer() { |
| 282 | DimLayer newDimLayer; |
| 283 | final boolean previousFullscreen = |
| 284 | mDimLayer != null && sSharedFullscreenDimLayers.indexOfValue(mDimLayer) > -1; |
| 285 | final int displayId = mStack.getDisplayContent().getDisplayId(); |
| 286 | if (mFullscreen) { |
| 287 | if (previousFullscreen) { |
| 288 | // Nothing to do here... |
| 289 | return; |
| 290 | } |
| 291 | // Use shared fullscreen dim layer |
| 292 | newDimLayer = sSharedFullscreenDimLayers.get(displayId); |
| 293 | if (newDimLayer == null) { |
| 294 | if (mDimLayer != null) { |
| 295 | // Re-purpose the previous dim layer. |
| 296 | newDimLayer = mDimLayer; |
| 297 | } else { |
| 298 | // Create new full screen dim layer. |
| 299 | newDimLayer = new DimLayer(mService, this, displayId); |
| 300 | } |
| 301 | newDimLayer.setBounds(mBounds); |
| 302 | sSharedFullscreenDimLayers.put(displayId, newDimLayer); |
| 303 | } else if (mDimLayer != null) { |
| 304 | mDimLayer.destroySurface(); |
| 305 | } |
| 306 | } else { |
| 307 | newDimLayer = (mDimLayer == null || previousFullscreen) |
| 308 | ? new DimLayer(mService, this, displayId) : mDimLayer; |
| 309 | newDimLayer.setBounds(mBounds); |
| 310 | } |
| 311 | mDimLayer = newDimLayer; |
| 312 | } |
| 313 | |
| 314 | boolean animateDimLayers() { |
| 315 | final int dimLayer; |
| 316 | final float dimAmount; |
| 317 | if (mDimWinAnimator == null) { |
| 318 | dimLayer = mDimLayer.getLayer(); |
| 319 | dimAmount = 0; |
| 320 | } else { |
| 321 | dimLayer = mDimWinAnimator.mAnimLayer - WindowManagerService.LAYER_OFFSET_DIM; |
| 322 | dimAmount = mDimWinAnimator.mWin.mAttrs.dimAmount; |
| 323 | } |
| 324 | final float targetAlpha = mDimLayer.getTargetAlpha(); |
| 325 | if (targetAlpha != dimAmount) { |
| 326 | if (mDimWinAnimator == null) { |
| 327 | mDimLayer.hide(DEFAULT_DIM_DURATION); |
| 328 | } else { |
| 329 | long duration = (mDimWinAnimator.mAnimating && mDimWinAnimator.mAnimation != null) |
| 330 | ? mDimWinAnimator.mAnimation.computeDurationHint() |
| 331 | : DEFAULT_DIM_DURATION; |
| 332 | if (targetAlpha > dimAmount) { |
| 333 | duration = getDimBehindFadeDuration(duration); |
| 334 | } |
| 335 | mDimLayer.show(dimLayer, dimAmount, duration); |
| 336 | } |
| 337 | } else if (mDimLayer.getLayer() != dimLayer) { |
| 338 | mDimLayer.setLayer(dimLayer); |
| 339 | } |
| 340 | if (mDimLayer.isAnimating()) { |
| 341 | if (!mService.okToDisplay()) { |
| 342 | // Jump to the end of the animation. |
| 343 | mDimLayer.show(); |
| 344 | } else { |
| 345 | return mDimLayer.stepAnimation(); |
| 346 | } |
| 347 | } |
| 348 | return false; |
| 349 | } |
| 350 | |
| 351 | private long getDimBehindFadeDuration(long duration) { |
| 352 | TypedValue tv = new TypedValue(); |
| 353 | mService.mContext.getResources().getValue( |
| 354 | com.android.internal.R.fraction.config_dimBehindFadeDuration, tv, true); |
| 355 | if (tv.type == TypedValue.TYPE_FRACTION) { |
| 356 | duration = (long)tv.getFraction(duration, duration); |
| 357 | } else if (tv.type >= TypedValue.TYPE_FIRST_INT && tv.type <= TypedValue.TYPE_LAST_INT) { |
| 358 | duration = tv.data; |
| 359 | } |
| 360 | return duration; |
| 361 | } |
| 362 | |
| 363 | void clearContinueDimming() { |
| 364 | mContinueDimming = false; |
| 365 | } |
| 366 | |
| 367 | void setContinueDimming() { |
| 368 | mContinueDimming = true; |
| 369 | } |
| 370 | |
| 371 | boolean getContinueDimming() { |
| 372 | return mContinueDimming; |
| 373 | } |
| 374 | |
| 375 | boolean isDimming() { |
| 376 | return mDimLayer.isDimming(); |
| 377 | } |
| 378 | |
| 379 | boolean isDimming(WindowStateAnimator winAnimator) { |
| 380 | return mDimWinAnimator == winAnimator && isDimming(); |
| 381 | } |
| 382 | |
| 383 | void startDimmingIfNeeded(WindowStateAnimator newWinAnimator) { |
| 384 | // Only set dim params on the highest dimmed layer. |
| 385 | // Don't turn on for an unshown surface, or for any layer but the highest dimmed layer. |
| 386 | if (newWinAnimator.mSurfaceShown && (mDimWinAnimator == null |
| 387 | || !mDimWinAnimator.mSurfaceShown |
| 388 | || mDimWinAnimator.mAnimLayer < newWinAnimator.mAnimLayer)) { |
| 389 | mDimWinAnimator = newWinAnimator; |
| 390 | if (mDimWinAnimator.mWin.mAppToken == null |
| 391 | && !mFullscreen && mStack.getDisplayContent() != null) { |
| 392 | // Dim should cover the entire screen for system windows. |
| 393 | mStack.getDisplayContent().getLogicalDisplayRect(mTmpRect); |
| 394 | mDimLayer.setBounds(mTmpRect); |
| 395 | } |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | void stopDimmingIfNeeded() { |
| 400 | if (!mContinueDimming && isDimming()) { |
| 401 | mDimWinAnimator = null; |
| 402 | mDimLayer.setBounds(mBounds); |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | void close() { |
| 407 | if (mDimLayer != null) { |
| 408 | mDimLayer.destroySurface(); |
| 409 | mDimLayer = null; |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | void resizeWindows() { |
| 414 | final ArrayList<WindowState> resizingWindows = mService.mResizingWindows; |
| 415 | for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) { |
| 416 | final ArrayList<WindowState> windows = mAppTokens.get(activityNdx).allAppWindows; |
| 417 | for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { |
| 418 | final WindowState win = windows.get(winNdx); |
| 419 | if (!resizingWindows.contains(win)) { |
| 420 | if (DEBUG_RESIZE) Slog.d(TAG, "setBounds: Resizing " + win); |
| 421 | resizingWindows.add(win); |
| 422 | } |
| 423 | } |
| 424 | } |
| 425 | } |
| 426 | |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 427 | boolean showForAllUsers() { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 428 | final int tokensCount = mAppTokens.size(); |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 429 | return (tokensCount != 0) && mAppTokens.get(tokensCount - 1).showForAllUsers; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Chong Zhang | 09b21ef | 2015-09-14 10:20:21 -0700 | [diff] [blame] | 432 | boolean inFreeformWorkspace() { |
| 433 | return mStack != null && mStack.mStackId == FREEFORM_WORKSPACE_STACK_ID; |
| 434 | } |
| 435 | |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 436 | boolean inDockedWorkspace() { |
| 437 | return mStack != null && mStack.mStackId == DOCKED_STACK_ID; |
| 438 | } |
| 439 | |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame^] | 440 | WindowState getTopAppMainWindow() { |
| 441 | final int tokensCount = mAppTokens.size(); |
| 442 | return tokensCount > 0 ? mAppTokens.get(tokensCount - 1).findMainWindow() : null; |
| 443 | } |
| 444 | |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 445 | @Override |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 446 | public boolean isFullscreen() { |
| 447 | return mFullscreen; |
| 448 | } |
| 449 | |
| 450 | @Override |
| 451 | public DisplayInfo getDisplayInfo() { |
| 452 | return mStack.getDisplayContent().getDisplayInfo(); |
| 453 | } |
| 454 | |
| 455 | @Override |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 456 | public String toString() { |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 457 | return "{taskId=" + mTaskId + " appTokens=" + mAppTokens + " mdr=" + mDeferRemoval + "}"; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 458 | } |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 459 | |
| 460 | public void printTo(String prefix, PrintWriter pw) { |
| 461 | pw.print(prefix); pw.print("taskId="); pw.print(mTaskId); |
| 462 | pw.print(prefix); pw.print("appTokens="); pw.print(mAppTokens); |
| 463 | pw.print(prefix); pw.print("mdr="); pw.println(mDeferRemoval); |
| 464 | if (mDimLayer.isDimming()) { |
| 465 | pw.print(prefix); pw.println("mDimLayer:"); |
| 466 | mDimLayer.printTo(prefix + " ", pw); |
| 467 | pw.print(prefix); pw.print("mDimWinAnimator="); pw.println(mDimWinAnimator); |
| 468 | } else { |
| 469 | pw.println(); |
| 470 | } |
| 471 | } |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 472 | } |