Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 19 | import android.content.res.Configuration; |
| 20 | import android.graphics.Rect; |
| 21 | import android.os.Handler; |
| 22 | import android.os.Looper; |
| 23 | import android.os.Message; |
| 24 | import android.util.Slog; |
| 25 | import android.util.SparseArray; |
Winson Chung | bdc646f | 2017-02-13 12:12:22 -0800 | [diff] [blame] | 26 | import android.view.DisplayInfo; |
| 27 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 28 | import com.android.internal.annotations.VisibleForTesting; |
| 29 | |
| 30 | import java.lang.ref.WeakReference; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 31 | |
| 32 | import static com.android.server.wm.WindowContainer.POSITION_BOTTOM; |
| 33 | import static com.android.server.wm.WindowContainer.POSITION_TOP; |
| 34 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK; |
| 35 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
| 36 | |
| 37 | /** |
| 38 | * Controller for the stack container. This is created by activity manager to link activity stacks |
| 39 | * to the stack container they use in window manager. |
| 40 | * |
| 41 | * Test class: {@link StackWindowControllerTests} |
| 42 | */ |
| 43 | public class StackWindowController |
| 44 | extends WindowContainerController<TaskStack, StackWindowListener> { |
| 45 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 46 | private final int mStackId; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 47 | |
| 48 | private final H mHandler; |
| 49 | |
Winson Chung | bdc646f | 2017-02-13 12:12:22 -0800 | [diff] [blame] | 50 | // Temp bounds only used in adjustConfigurationForBounds() |
| 51 | private final Rect mTmpRect = new Rect(); |
| 52 | private final Rect mTmpStableInsets = new Rect(); |
| 53 | private final Rect mTmpNonDecorInsets = new Rect(); |
| 54 | private final Rect mTmpDisplayBounds = new Rect(); |
| 55 | |
Wale Ogunwale | 034a8ec | 2017-09-02 17:14:40 -0700 | [diff] [blame] | 56 | public StackWindowController(int stackId, StackWindowListener listener, int displayId, |
| 57 | boolean onTop, Rect outBounds) { |
| 58 | this(stackId, listener, displayId, onTop, outBounds, WindowManagerService.getInstance()); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | @VisibleForTesting |
| 62 | public StackWindowController(int stackId, StackWindowListener listener, |
Wale Ogunwale | 034a8ec | 2017-09-02 17:14:40 -0700 | [diff] [blame] | 63 | int displayId, boolean onTop, Rect outBounds, WindowManagerService service) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 64 | super(listener, service); |
| 65 | mStackId = stackId; |
| 66 | mHandler = new H(new WeakReference<>(this), service.mH.getLooper()); |
| 67 | |
| 68 | synchronized (mWindowMap) { |
| 69 | final DisplayContent dc = mRoot.getDisplayContent(displayId); |
| 70 | if (dc == null) { |
| 71 | throw new IllegalArgumentException("Trying to add stackId=" + stackId |
| 72 | + " to unknown displayId=" + displayId); |
| 73 | } |
| 74 | |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 75 | dc.createStack(stackId, onTop, this); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 76 | getRawBounds(outBounds); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public void removeContainer() { |
| 82 | synchronized (mWindowMap) { |
| 83 | if (mContainer != null) { |
| 84 | mContainer.removeIfPossible(); |
| 85 | super.removeContainer(); |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 90 | public void reparent(int displayId, Rect outStackBounds, boolean onTop) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 91 | synchronized (mWindowMap) { |
| 92 | if (mContainer == null) { |
| 93 | throw new IllegalArgumentException("Trying to move unknown stackId=" + mStackId |
| 94 | + " to displayId=" + displayId); |
| 95 | } |
| 96 | |
| 97 | final DisplayContent targetDc = mRoot.getDisplayContent(displayId); |
| 98 | if (targetDc == null) { |
| 99 | throw new IllegalArgumentException("Trying to move stackId=" + mStackId |
| 100 | + " to unknown displayId=" + displayId); |
| 101 | } |
| 102 | |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 103 | targetDc.moveStackToDisplay(mContainer, onTop); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 104 | getRawBounds(outStackBounds); |
| 105 | } |
| 106 | } |
| 107 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 108 | public void positionChildAt(TaskWindowContainerController child, int position) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 109 | synchronized (mWindowMap) { |
| 110 | if (DEBUG_STACK) Slog.i(TAG_WM, "positionChildAt: positioning task=" + child |
| 111 | + " at " + position); |
| 112 | if (child.mContainer == null) { |
| 113 | if (DEBUG_STACK) Slog.i(TAG_WM, |
| 114 | "positionChildAt: could not find task=" + this); |
| 115 | return; |
| 116 | } |
| 117 | if (mContainer == null) { |
| 118 | if (DEBUG_STACK) Slog.i(TAG_WM, |
| 119 | "positionChildAt: could not find stack for task=" + mContainer); |
| 120 | return; |
| 121 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 122 | child.mContainer.positionAt(position); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 123 | mContainer.getDisplayContent().layoutAndAssignWindowLayersIfNeeded(); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | public void positionChildAtTop(TaskWindowContainerController child, boolean includingParents) { |
| 128 | if (child == null) { |
| 129 | // TODO: Fix the call-points that cause this to happen. |
| 130 | return; |
| 131 | } |
| 132 | |
| 133 | synchronized(mWindowMap) { |
| 134 | final Task childTask = child.mContainer; |
| 135 | if (childTask == null) { |
| 136 | Slog.e(TAG_WM, "positionChildAtTop: task=" + child + " not found"); |
| 137 | return; |
| 138 | } |
| 139 | mContainer.positionChildAt(POSITION_TOP, childTask, includingParents); |
| 140 | |
| 141 | if (mService.mAppTransition.isTransitionSet()) { |
| 142 | childTask.setSendingToBottom(false); |
| 143 | } |
| 144 | mContainer.getDisplayContent().layoutAndAssignWindowLayersIfNeeded(); |
| 145 | } |
| 146 | } |
| 147 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 148 | public void positionChildAtBottom(TaskWindowContainerController child, |
| 149 | boolean includingParents) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 150 | if (child == null) { |
| 151 | // TODO: Fix the call-points that cause this to happen. |
| 152 | return; |
| 153 | } |
| 154 | |
| 155 | synchronized(mWindowMap) { |
| 156 | final Task childTask = child.mContainer; |
| 157 | if (childTask == null) { |
| 158 | Slog.e(TAG_WM, "positionChildAtBottom: task=" + child + " not found"); |
| 159 | return; |
| 160 | } |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 161 | mContainer.positionChildAt(POSITION_BOTTOM, childTask, includingParents); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 162 | |
| 163 | if (mService.mAppTransition.isTransitionSet()) { |
| 164 | childTask.setSendingToBottom(true); |
| 165 | } |
| 166 | mContainer.getDisplayContent().layoutAndAssignWindowLayersIfNeeded(); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Re-sizes a stack and its containing tasks. |
| 172 | * |
| 173 | * @param bounds New stack bounds. Passing in null sets the bounds to fullscreen. |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 174 | * @param taskBounds Bounds for tasks in the resized stack, keyed by task id. |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 175 | * @param taskTempInsetBounds Inset bounds for individual tasks, keyed by task id. |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 176 | */ |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 177 | public void resize(Rect bounds, SparseArray<Rect> taskBounds, |
| 178 | SparseArray<Rect> taskTempInsetBounds) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 179 | synchronized (mWindowMap) { |
| 180 | if (mContainer == null) { |
| 181 | throw new IllegalArgumentException("resizeStack: stack " + this + " not found."); |
| 182 | } |
| 183 | // We might trigger a configuration change. Save the current task bounds for freezing. |
| 184 | mContainer.prepareFreezingTaskBounds(); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 185 | if (mContainer.setBounds(bounds, taskBounds, taskTempInsetBounds) |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 186 | && mContainer.isVisible()) { |
| 187 | mContainer.getDisplayContent().setLayoutNeeded(); |
| 188 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
| 189 | } |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 193 | /** |
| 194 | * @see TaskStack.getStackDockedModeBoundsLocked(Rect, Rect, Rect, boolean) |
| 195 | */ |
| 196 | public void getStackDockedModeBounds(Rect currentTempTaskBounds, Rect outStackBounds, |
| 197 | Rect outTempTaskBounds, boolean ignoreVisibility) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 198 | synchronized (mWindowMap) { |
| 199 | if (mContainer != null) { |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 200 | mContainer.getStackDockedModeBoundsLocked(currentTempTaskBounds, outStackBounds, |
| 201 | outTempTaskBounds, ignoreVisibility); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 202 | return; |
| 203 | } |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 204 | outStackBounds.setEmpty(); |
| 205 | outTempTaskBounds.setEmpty(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 206 | } |
| 207 | } |
| 208 | |
| 209 | public void prepareFreezingTaskBounds() { |
| 210 | synchronized (mWindowMap) { |
| 211 | if (mContainer == null) { |
| 212 | throw new IllegalArgumentException("prepareFreezingTaskBounds: stack " + this |
| 213 | + " not found."); |
| 214 | } |
| 215 | mContainer.prepareFreezingTaskBounds(); |
| 216 | } |
| 217 | } |
| 218 | |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 219 | public void getRawBounds(Rect outBounds) { |
| 220 | synchronized (mWindowMap) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 221 | if (mContainer.matchParentBounds()) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 222 | outBounds.setEmpty(); |
| 223 | } else { |
| 224 | mContainer.getRawBounds(outBounds); |
| 225 | } |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | |
| 229 | public void getBounds(Rect outBounds) { |
| 230 | synchronized (mWindowMap) { |
| 231 | if (mContainer != null) { |
| 232 | mContainer.getBounds(outBounds); |
| 233 | return; |
| 234 | } |
| 235 | outBounds.setEmpty(); |
| 236 | } |
| 237 | } |
| 238 | |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 239 | public void getBoundsForNewConfiguration(Rect outBounds) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 240 | synchronized(mWindowMap) { |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 241 | mContainer.getBoundsForNewConfiguration(outBounds); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | |
Winson Chung | bdc646f | 2017-02-13 12:12:22 -0800 | [diff] [blame] | 245 | /** |
| 246 | * Adjusts the screen size in dp's for the {@param config} for the given params. |
| 247 | */ |
| 248 | public void adjustConfigurationForBounds(Rect bounds, Rect insetBounds, |
| 249 | Rect nonDecorBounds, Rect stableBounds, boolean overrideWidth, |
| 250 | boolean overrideHeight, float density, Configuration config, |
| 251 | Configuration parentConfig) { |
| 252 | synchronized (mWindowMap) { |
| 253 | final TaskStack stack = mContainer; |
| 254 | final DisplayContent displayContent = stack.getDisplayContent(); |
| 255 | final DisplayInfo di = displayContent.getDisplayInfo(); |
| 256 | |
| 257 | // Get the insets and display bounds |
| 258 | mService.mPolicy.getStableInsetsLw(di.rotation, di.logicalWidth, di.logicalHeight, |
| 259 | mTmpStableInsets); |
| 260 | mService.mPolicy.getNonDecorInsetsLw(di.rotation, di.logicalWidth, di.logicalHeight, |
| 261 | mTmpNonDecorInsets); |
| 262 | mTmpDisplayBounds.set(0, 0, di.logicalWidth, di.logicalHeight); |
| 263 | |
| 264 | int width; |
| 265 | int height; |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 266 | |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 267 | final Rect parentAppBounds = parentConfig.windowConfiguration.getAppBounds(); |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 268 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 269 | config.windowConfiguration.setBounds(bounds); |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 270 | config.windowConfiguration.setAppBounds(!bounds.isEmpty() ? bounds : null); |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 271 | boolean intersectParentBounds = false; |
| 272 | |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 273 | if (stack.getWindowConfiguration().tasksAreFloating()) { |
Winson Chung | bdc646f | 2017-02-13 12:12:22 -0800 | [diff] [blame] | 274 | // Floating tasks should not be resized to the screen's bounds. |
| 275 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 276 | if (stack.inPinnedWindowingMode() |
| 277 | && bounds.width() == mTmpDisplayBounds.width() |
| 278 | && bounds.height() == mTmpDisplayBounds.height()) { |
Winson Chung | bdc646f | 2017-02-13 12:12:22 -0800 | [diff] [blame] | 279 | // If the bounds we are animating is the same as the fullscreen stack |
| 280 | // dimensions, then apply the same inset calculations that we normally do for |
| 281 | // the fullscreen stack, without intersecting it with the display bounds |
| 282 | stableBounds.inset(mTmpStableInsets); |
| 283 | nonDecorBounds.inset(mTmpNonDecorInsets); |
Andrii Kulian | 1893a61 | 2017-05-04 14:45:09 -0700 | [diff] [blame] | 284 | // Move app bounds to zero to apply intersection with parent correctly. They are |
| 285 | // used only for evaluating width and height, so it's OK to move them around. |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 286 | config.windowConfiguration.getAppBounds().offsetTo(0, 0); |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 287 | intersectParentBounds = true; |
Winson Chung | bdc646f | 2017-02-13 12:12:22 -0800 | [diff] [blame] | 288 | } |
| 289 | width = (int) (stableBounds.width() / density); |
| 290 | height = (int) (stableBounds.height() / density); |
| 291 | } else { |
| 292 | // For calculating screenWidthDp, screenWidthDp, we use the stable inset screen |
| 293 | // area, i.e. the screen area without the system bars. |
| 294 | // Additionally task dimensions should not be bigger than its parents dimensions. |
| 295 | // The non decor inset are areas that could never be removed in Honeycomb. See |
| 296 | // {@link WindowManagerPolicy#getNonDecorInsetsLw}. |
| 297 | intersectDisplayBoundsExcludeInsets(nonDecorBounds, |
| 298 | insetBounds != null ? insetBounds : bounds, mTmpNonDecorInsets, |
| 299 | mTmpDisplayBounds, overrideWidth, overrideHeight); |
| 300 | intersectDisplayBoundsExcludeInsets(stableBounds, |
| 301 | insetBounds != null ? insetBounds : bounds, mTmpStableInsets, |
| 302 | mTmpDisplayBounds, overrideWidth, overrideHeight); |
| 303 | width = Math.min((int) (stableBounds.width() / density), |
| 304 | parentConfig.screenWidthDp); |
| 305 | height = Math.min((int) (stableBounds.height() / density), |
| 306 | parentConfig.screenHeightDp); |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 307 | intersectParentBounds = true; |
| 308 | } |
| 309 | |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 310 | if (intersectParentBounds && config.windowConfiguration.getAppBounds() != null) { |
| 311 | config.windowConfiguration.getAppBounds().intersect(parentAppBounds); |
Winson Chung | bdc646f | 2017-02-13 12:12:22 -0800 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | config.screenWidthDp = width; |
| 315 | config.screenHeightDp = height; |
| 316 | config.smallestScreenWidthDp = getSmallestWidthForTaskBounds( |
| 317 | insetBounds != null ? insetBounds : bounds, density); |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | /** |
| 322 | * Intersects the specified {@code inOutBounds} with the display frame that excludes the stable |
| 323 | * inset areas. |
| 324 | * |
| 325 | * @param inOutBounds The inOutBounds to subtract the stable inset areas from. |
| 326 | */ |
| 327 | private void intersectDisplayBoundsExcludeInsets(Rect inOutBounds, Rect inInsetBounds, |
| 328 | Rect stableInsets, Rect displayBounds, boolean overrideWidth, boolean overrideHeight) { |
| 329 | mTmpRect.set(inInsetBounds); |
| 330 | mService.intersectDisplayInsetBounds(displayBounds, stableInsets, mTmpRect); |
| 331 | int leftInset = mTmpRect.left - inInsetBounds.left; |
| 332 | int topInset = mTmpRect.top - inInsetBounds.top; |
| 333 | int rightInset = overrideWidth ? 0 : inInsetBounds.right - mTmpRect.right; |
| 334 | int bottomInset = overrideHeight ? 0 : inInsetBounds.bottom - mTmpRect.bottom; |
| 335 | inOutBounds.inset(leftInset, topInset, rightInset, bottomInset); |
| 336 | } |
| 337 | |
| 338 | /** |
| 339 | * Calculates the smallest width for a task given the {@param bounds}. |
| 340 | * |
| 341 | * @return the smallest width to be used in the Configuration, in dips |
| 342 | */ |
| 343 | private int getSmallestWidthForTaskBounds(Rect bounds, float density) { |
| 344 | final DisplayContent displayContent = mContainer.getDisplayContent(); |
| 345 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
| 346 | |
| 347 | if (bounds == null || (bounds.width() == displayInfo.logicalWidth && |
| 348 | bounds.height() == displayInfo.logicalHeight)) { |
| 349 | // If the bounds are fullscreen, return the value of the fullscreen configuration |
| 350 | return displayContent.getConfiguration().smallestScreenWidthDp; |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 351 | } else if (mContainer.getWindowConfiguration().tasksAreFloating()) { |
Winson Chung | bdc646f | 2017-02-13 12:12:22 -0800 | [diff] [blame] | 352 | // For floating tasks, calculate the smallest width from the bounds of the task |
| 353 | return (int) (Math.min(bounds.width(), bounds.height()) / density); |
| 354 | } else { |
| 355 | // Iterating across all screen orientations, and return the minimum of the task |
| 356 | // width taking into account that the bounds might change because the snap algorithm |
| 357 | // snaps to a different value |
| 358 | return displayContent.getDockedDividerController() |
| 359 | .getSmallestWidthDpForBounds(bounds); |
| 360 | } |
| 361 | } |
| 362 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 363 | void requestResize(Rect bounds) { |
| 364 | mHandler.obtainMessage(H.REQUEST_RESIZE, bounds).sendToTarget(); |
| 365 | } |
| 366 | |
| 367 | @Override |
| 368 | public String toString() { |
| 369 | return "{StackWindowController stackId=" + mStackId + "}"; |
| 370 | } |
| 371 | |
| 372 | private static final class H extends Handler { |
| 373 | |
| 374 | static final int REQUEST_RESIZE = 0; |
| 375 | |
| 376 | private final WeakReference<StackWindowController> mController; |
| 377 | |
| 378 | H(WeakReference<StackWindowController> controller, Looper looper) { |
| 379 | super(looper); |
| 380 | mController = controller; |
| 381 | } |
| 382 | |
| 383 | @Override |
| 384 | public void handleMessage(Message msg) { |
| 385 | final StackWindowController controller = mController.get(); |
| 386 | final StackWindowListener listener = (controller != null) |
| 387 | ? controller.mListener : null; |
| 388 | if (listener == null) { |
| 389 | return; |
| 390 | } |
| 391 | switch (msg.what) { |
| 392 | case REQUEST_RESIZE: |
| 393 | listener.requestResize((Rect) msg.obj); |
| 394 | break; |
| 395 | } |
| 396 | } |
| 397 | } |
| 398 | } |