Task.java revision 935e50292e1404dc5f1705b2a1719cdaee3072b0
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 193797c22ea16e932329ebffdc7e7ce09f9ecd9545Wale Ogunwaleimport static android.app.ActivityManager.StackId.DOCKED_STACK_ID; 203797c22ea16e932329ebffdc7e7ce09f9ecd9545Wale Ogunwaleimport static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; 213797c22ea16e932329ebffdc7e7ce09f9ecd9545Wale Ogunwaleimport static android.app.ActivityManager.StackId.HOME_STACK_ID; 223797c22ea16e932329ebffdc7e7ce09f9ecd9545Wale Ogunwaleimport static android.app.ActivityManager.StackId.PINNED_STACK_ID; 231ed0d89e7e9a28a5dd52fdc40425466efd8d08efWale Ogunwaleimport static android.app.ActivityManager.RESIZE_MODE_SYSTEM_SCREEN_ROTATION; 2442bf39edbdad19f51497938d0a3469dd772f19e8Craig Mautnerimport static com.android.server.wm.WindowManagerService.TAG; 25e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwaleimport static com.android.server.wm.WindowManagerService.DEBUG_RESIZE; 26e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautnerimport static com.android.server.wm.WindowManagerService.DEBUG_STACK; 271ed0d89e7e9a28a5dd52fdc40425466efd8d08efWale Ogunwaleimport static com.android.server.wm.WindowManagerService.H.RESIZE_TASK; 2899db1863a84364339fc5dc9142f15910cdd96ed8Wale Ogunwale 293797c22ea16e932329ebffdc7e7ce09f9ecd9545Wale Ogunwaleimport android.app.ActivityManager.StackId; 30e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwaleimport android.content.res.Configuration; 31e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwaleimport android.graphics.Rect; 322c2549c5f44b712dbbf66a69d91f07d6f5336ee6Craig Mautnerimport android.util.EventLog; 3342bf39edbdad19f51497938d0a3469dd772f19e8Craig Mautnerimport android.util.Slog; 34e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwaleimport android.view.DisplayInfo; 35e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwaleimport android.view.Surface; 36e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale 37e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautnerimport com.android.server.EventLogTags; 382c2549c5f44b712dbbf66a69d91f07d6f5336ee6Craig Mautner 39e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwaleimport java.io.PrintWriter; 40e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwaleimport java.util.ArrayList; 41e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale 42e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwaleclass Task implements DimLayer.DimLayerUser { 432cc92f55c0257cdc837585b36987c610fb0a8251Wale Ogunwale // Return value from {@link setBounds} indicating no change was made to the Task bounds. 442cc92f55c0257cdc837585b36987c610fb0a8251Wale Ogunwale static final int BOUNDS_CHANGE_NONE = 0; 452cc92f55c0257cdc837585b36987c610fb0a8251Wale Ogunwale // Return value from {@link setBounds} indicating the position of the Task bounds changed. 462cc92f55c0257cdc837585b36987c610fb0a8251Wale Ogunwale static final int BOUNDS_CHANGE_POSITION = 1; 472cc92f55c0257cdc837585b36987c610fb0a8251Wale Ogunwale // Return value from {@link setBounds} indicating the size of the Task bounds changed. 482cc92f55c0257cdc837585b36987c610fb0a8251Wale Ogunwale static final int BOUNDS_CHANGE_SIZE = 1 << 1; 492cc92f55c0257cdc837585b36987c610fb0a8251Wale Ogunwale 50c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner TaskStack mStack; 5105d6272bad2d707b488a6f8784ce8aea5e25b110Craig Mautner final AppTokenList mAppTokens = new AppTokenList(); 5283162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner final int mTaskId; 53ac6f843c917b68ea8805711965b149a9338e3a0eCraig Mautner final int mUserId; 549ef471f7f2f59de032d7cb9c3c7241486109979eCraig Mautner boolean mDeferRemoval = false; 55e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautner final WindowManagerService mService; 56b1fd65c0ff5784b90d765edb7e3c3115d767dff0Craig Mautner 57e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale // Content limits relative to the DisplayContent this sits in. 58e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale private Rect mBounds = new Rect(); 59e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale 60e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale // Device rotation as of the last time {@link #mBounds} was set. 61e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale int mRotation; 62e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale 63e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale // Whether mBounds is fullscreen 64e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale private boolean mFullscreen = true; 65e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale 66e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale // Contains configurations settings that are different from the global configuration due to 67e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale // stack specific operations. E.g. {@link #setBounds}. 68e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale Configuration mOverrideConfig; 69e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale 70e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale // For comparison with DisplayContent bounds. 71e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale private Rect mTmpRect = new Rect(); 72e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale // For handling display rotations. 73e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale private Rect mTmpRect2 = new Rect(); 74e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale 753005e75585dcda30b64603e320e0711b583624ddChong Zhang // Whether the task is currently being drag-resized 763005e75585dcda30b64603e320e0711b583624ddChong Zhang private boolean mDragResizing; 773005e75585dcda30b64603e320e0711b583624ddChong Zhang 78ebcc875f10f05db7365cd8afbf4e9425221ab14dFilip Gruszczynski Task(int taskId, TaskStack stack, int userId, WindowManagerService service, Rect bounds, 79ebcc875f10f05db7365cd8afbf4e9425221ab14dFilip Gruszczynski Configuration config) { 8083162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner mTaskId = taskId; 81c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner mStack = stack; 82ac6f843c917b68ea8805711965b149a9338e3a0eCraig Mautner mUserId = userId; 83e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautner mService = service; 84ebcc875f10f05db7365cd8afbf4e9425221ab14dFilip Gruszczynski setBounds(bounds, config); 85c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner } 86c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner 87c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner DisplayContent getDisplayContent() { 88c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner return mStack.getDisplayContent(); 89c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner } 90c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner 91c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner void addAppToken(int addPos, AppWindowToken wtoken) { 9242bf39edbdad19f51497938d0a3469dd772f19e8Craig Mautner final int lastPos = mAppTokens.size(); 9383162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner if (addPos >= lastPos) { 9483162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner addPos = lastPos; 9583162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner } else { 9683162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner for (int pos = 0; pos < lastPos && pos < addPos; ++pos) { 9783162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner if (mAppTokens.get(pos).removed) { 9883162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner // addPos assumes removed tokens are actually gone. 9983162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner ++addPos; 10083162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner } 10101f79cf91610ec9f85345ea6eeae50ea2f28578fCraig Mautner } 10242bf39edbdad19f51497938d0a3469dd772f19e8Craig Mautner } 103c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner mAppTokens.add(addPos, wtoken); 10483162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner wtoken.mTask = this; 10542bf39edbdad19f51497938d0a3469dd772f19e8Craig Mautner mDeferRemoval = false; 106c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner } 107c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner 108e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautner void removeLocked() { 109e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautner if (!mAppTokens.isEmpty() && mStack.isAnimating()) { 11083162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner if (DEBUG_STACK) Slog.i(TAG, "removeTask: deferring removing taskId=" + mTaskId); 111e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautner mDeferRemoval = true; 112e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautner return; 113e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautner } 11483162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner if (DEBUG_STACK) Slog.i(TAG, "removeTask: removing taskId=" + mTaskId); 11583162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "removeTask"); 116e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautner mDeferRemoval = false; 1170689ae903628f12ff073376b655b9d972533796bFilip Gruszczynski DisplayContent content = getDisplayContent(); 1180689ae903628f12ff073376b655b9d972533796bFilip Gruszczynski if (content != null) { 119112eb8c1f76fff6a670d7c5f85e8c3d656cd3aa8Chong Zhang content.mDimLayerController.removeDimLayerUser(this); 1200689ae903628f12ff073376b655b9d972533796bFilip Gruszczynski } 121e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautner mStack.removeTask(this); 12283162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner mService.mTaskIdToTask.delete(mTaskId); 123e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautner } 124e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautner 12553a29a90f35f72462c0d6ad650921d5566c1f8f0Wale Ogunwale void moveTaskToStack(TaskStack stack, boolean toTop) { 12653a29a90f35f72462c0d6ad650921d5566c1f8f0Wale Ogunwale if (stack == mStack) { 12753a29a90f35f72462c0d6ad650921d5566c1f8f0Wale Ogunwale return; 12853a29a90f35f72462c0d6ad650921d5566c1f8f0Wale Ogunwale } 12953a29a90f35f72462c0d6ad650921d5566c1f8f0Wale Ogunwale if (DEBUG_STACK) Slog.i(TAG, "moveTaskToStack: removing taskId=" + mTaskId 13053a29a90f35f72462c0d6ad650921d5566c1f8f0Wale Ogunwale + " from stack=" + mStack); 131000957cef387dc7d08fc6563e2221e9023194984Wale Ogunwale EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "moveTask"); 13253a29a90f35f72462c0d6ad650921d5566c1f8f0Wale Ogunwale if (mStack != null) { 13353a29a90f35f72462c0d6ad650921d5566c1f8f0Wale Ogunwale mStack.removeTask(this); 13453a29a90f35f72462c0d6ad650921d5566c1f8f0Wale Ogunwale } 13553a29a90f35f72462c0d6ad650921d5566c1f8f0Wale Ogunwale stack.addTask(this, toTop); 13653a29a90f35f72462c0d6ad650921d5566c1f8f0Wale Ogunwale } 13753a29a90f35f72462c0d6ad650921d5566c1f8f0Wale Ogunwale 138935e50292e1404dc5f1705b2a1719cdaee3072b0Wale Ogunwale void positionTaskInStack(TaskStack stack, int position, Rect bounds, Configuration config) { 139ddc1cb2c15549ed23dce9d416680a009fa6ae23cWale Ogunwale if (mStack != null && stack != mStack) { 140ddc1cb2c15549ed23dce9d416680a009fa6ae23cWale Ogunwale if (DEBUG_STACK) Slog.i(TAG, "positionTaskInStack: removing taskId=" + mTaskId 141ddc1cb2c15549ed23dce9d416680a009fa6ae23cWale Ogunwale + " from stack=" + mStack); 142ddc1cb2c15549ed23dce9d416680a009fa6ae23cWale Ogunwale EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, "moveTask"); 143ddc1cb2c15549ed23dce9d416680a009fa6ae23cWale Ogunwale mStack.removeTask(this); 144ddc1cb2c15549ed23dce9d416680a009fa6ae23cWale Ogunwale } 145ddc1cb2c15549ed23dce9d416680a009fa6ae23cWale Ogunwale stack.positionTask(this, position, showForAllUsers()); 146935e50292e1404dc5f1705b2a1719cdaee3072b0Wale Ogunwale setBounds(bounds, config); 147ddc1cb2c15549ed23dce9d416680a009fa6ae23cWale Ogunwale } 148ddc1cb2c15549ed23dce9d416680a009fa6ae23cWale Ogunwale 149c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner boolean removeAppToken(AppWindowToken wtoken) { 15042bf39edbdad19f51497938d0a3469dd772f19e8Craig Mautner boolean removed = mAppTokens.remove(wtoken); 151c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner if (mAppTokens.size() == 0) { 152000957cef387dc7d08fc6563e2221e9023194984Wale Ogunwale EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, mTaskId, 1532c2549c5f44b712dbbf66a69d91f07d6f5336ee6Craig Mautner "removeAppToken: last token"); 154e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautner if (mDeferRemoval) { 155e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautner removeLocked(); 156e3119b7d353e71d1f94ddff932b722b4d285931eCraig Mautner } 157c00204b4d14d49a0417b44ca21aee4f0d4c466e0Craig Mautner } 15883162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner wtoken.mTask = null; 15983162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner /* Leave mTaskId for now, it might be useful for debug 16083162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner wtoken.mTaskId = -1; 16183162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner */ 16242bf39edbdad19f51497938d0a3469dd772f19e8Craig Mautner return removed; 163b1fd65c0ff5784b90d765edb7e3c3115d767dff0Craig Mautner } 1645d9c7be84d9628c1cf199fcf9015942835c4671bCraig Mautner 165cbd84af39a329890013b0c3b6763280ba2ad78c9Craig Mautner void setSendingToBottom(boolean toBottom) { 166cbd84af39a329890013b0c3b6763280ba2ad78c9Craig Mautner for (int appTokenNdx = 0; appTokenNdx < mAppTokens.size(); appTokenNdx++) { 167cbd84af39a329890013b0c3b6763280ba2ad78c9Craig Mautner mAppTokens.get(appTokenNdx).sendingToBottom = toBottom; 168cbd84af39a329890013b0c3b6763280ba2ad78c9Craig Mautner } 169cbd84af39a329890013b0c3b6763280ba2ad78c9Craig Mautner } 170cbd84af39a329890013b0c3b6763280ba2ad78c9Craig Mautner 171ebcc875f10f05db7365cd8afbf4e9425221ab14dFilip Gruszczynski /** Set the task bounds. Passing in null sets the bounds to fullscreen. */ 1722cc92f55c0257cdc837585b36987c610fb0a8251Wale Ogunwale int setBounds(Rect bounds, Configuration config) { 173ebcc875f10f05db7365cd8afbf4e9425221ab14dFilip Gruszczynski if (config == null) { 174ebcc875f10f05db7365cd8afbf4e9425221ab14dFilip Gruszczynski config = Configuration.EMPTY; 175b34a7ad1af54132b6b046ab8f768e0ffb81cf581Wale Ogunwale } 176ebcc875f10f05db7365cd8afbf4e9425221ab14dFilip Gruszczynski if (bounds == null && !Configuration.EMPTY.equals(config)) { 177ebcc875f10f05db7365cd8afbf4e9425221ab14dFilip Gruszczynski throw new IllegalArgumentException("null bounds but non empty configuration: " 178ebcc875f10f05db7365cd8afbf4e9425221ab14dFilip Gruszczynski + config); 179b34a7ad1af54132b6b046ab8f768e0ffb81cf581Wale Ogunwale } 180ebcc875f10f05db7365cd8afbf4e9425221ab14dFilip Gruszczynski if (bounds != null && Configuration.EMPTY.equals(config)) { 181ebcc875f10f05db7365cd8afbf4e9425221ab14dFilip Gruszczynski throw new IllegalArgumentException("non null bounds, but empty configuration"); 182b34a7ad1af54132b6b046ab8f768e0ffb81cf581Wale Ogunwale } 183e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale boolean oldFullscreen = mFullscreen; 184e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale int rotation = Surface.ROTATION_0; 185e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale final DisplayContent displayContent = mStack.getDisplayContent(); 186e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale if (displayContent != null) { 187e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale displayContent.getLogicalDisplayRect(mTmpRect); 188e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale rotation = displayContent.getDisplayInfo().rotation; 189e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale if (bounds == null) { 190e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale bounds = mTmpRect; 191e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale mFullscreen = true; 192e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale } else { 19399db1863a84364339fc5dc9142f15910cdd96ed8Wale Ogunwale if ((mStack.mStackId != FREEFORM_WORKSPACE_STACK_ID 19499db1863a84364339fc5dc9142f15910cdd96ed8Wale Ogunwale && mStack.mStackId != PINNED_STACK_ID) || bounds.isEmpty()) { 195234dbf875f795fdb72f82dc6ea805201ee31fb0eStefan Kuhne // ensure bounds are entirely within the display rect 196234dbf875f795fdb72f82dc6ea805201ee31fb0eStefan Kuhne if (!bounds.intersect(mTmpRect)) { 197234dbf875f795fdb72f82dc6ea805201ee31fb0eStefan Kuhne // Can't set bounds outside the containing display...Sorry! 1982cc92f55c0257cdc837585b36987c610fb0a8251Wale Ogunwale return BOUNDS_CHANGE_NONE; 199234dbf875f795fdb72f82dc6ea805201ee31fb0eStefan Kuhne } 200e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale } 201e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale mFullscreen = mTmpRect.equals(bounds); 202e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale } 203e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale } 204e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale 205e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale if (bounds == null) { 206e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale // Can't set to fullscreen if we don't have a display to get bounds from... 2072cc92f55c0257cdc837585b36987c610fb0a8251Wale Ogunwale return BOUNDS_CHANGE_NONE; 208e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale } 209e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale if (mBounds.equals(bounds) && oldFullscreen == mFullscreen && mRotation == rotation) { 2102cc92f55c0257cdc837585b36987c610fb0a8251Wale Ogunwale return BOUNDS_CHANGE_NONE; 2112cc92f55c0257cdc837585b36987c610fb0a8251Wale Ogunwale } 2122cc92f55c0257cdc837585b36987c610fb0a8251Wale Ogunwale 2132cc92f55c0257cdc837585b36987c610fb0a8251Wale Ogunwale int boundsChange = BOUNDS_CHANGE_NONE; 2142cc92f55c0257cdc837585b36987c610fb0a8251Wale Ogunwale if (mBounds.left != bounds.left || mBounds.right != bounds.right) { 2152cc92f55c0257cdc837585b36987c610fb0a8251Wale Ogunwale boundsChange |= BOUNDS_CHANGE_POSITION; 2162cc92f55c0257cdc837585b36987c610fb0a8251Wale Ogunwale } 2172cc92f55c0257cdc837585b36987c610fb0a8251Wale Ogunwale if (mBounds.width() != bounds.width() || mBounds.height() != bounds.height()) { 2182cc92f55c0257cdc837585b36987c610fb0a8251Wale Ogunwale boundsChange |= BOUNDS_CHANGE_SIZE; 219e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale } 220e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale 221e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale mBounds.set(bounds); 222e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale mRotation = rotation; 2230689ae903628f12ff073376b655b9d972533796bFilip Gruszczynski if (displayContent != null) { 224112eb8c1f76fff6a670d7c5f85e8c3d656cd3aa8Chong Zhang displayContent.mDimLayerController.updateDimLayer(this); 2250689ae903628f12ff073376b655b9d972533796bFilip Gruszczynski } 226ebcc875f10f05db7365cd8afbf4e9425221ab14dFilip Gruszczynski mOverrideConfig = mFullscreen ? Configuration.EMPTY : config; 2272cc92f55c0257cdc837585b36987c610fb0a8251Wale Ogunwale return boundsChange; 228e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale } 229e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale 23087b21722c2336490ecf8b66f6acfc46ce8cc6f46Chong Zhang boolean resizeLocked(Rect bounds, Configuration configuration, boolean forced) { 2313005e75585dcda30b64603e320e0711b583624ddChong Zhang int boundsChanged = setBounds(bounds, configuration); 23287b21722c2336490ecf8b66f6acfc46ce8cc6f46Chong Zhang if (forced) { 2333005e75585dcda30b64603e320e0711b583624ddChong Zhang boundsChanged |= BOUNDS_CHANGE_SIZE; 2343005e75585dcda30b64603e320e0711b583624ddChong Zhang } 2353005e75585dcda30b64603e320e0711b583624ddChong Zhang if (boundsChanged == BOUNDS_CHANGE_NONE) { 2363005e75585dcda30b64603e320e0711b583624ddChong Zhang return false; 2373005e75585dcda30b64603e320e0711b583624ddChong Zhang } 2383005e75585dcda30b64603e320e0711b583624ddChong Zhang if ((boundsChanged & BOUNDS_CHANGE_SIZE) == BOUNDS_CHANGE_SIZE) { 2393005e75585dcda30b64603e320e0711b583624ddChong Zhang resizeWindows(); 2403005e75585dcda30b64603e320e0711b583624ddChong Zhang } 2413005e75585dcda30b64603e320e0711b583624ddChong Zhang return true; 2423005e75585dcda30b64603e320e0711b583624ddChong Zhang } 2433005e75585dcda30b64603e320e0711b583624ddChong Zhang 244f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale /** Return true if the current bound can get outputted to the rest of the system as-is. */ 245f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale private boolean useCurrentBounds() { 246f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale final DisplayContent displayContent = mStack.getDisplayContent(); 247f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale if (mFullscreen 2483797c22ea16e932329ebffdc7e7ce09f9ecd9545Wale Ogunwale || !StackId.isTaskResizeableByDockedStack(mStack.mStackId) 249f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale || displayContent == null 250f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale || displayContent.getDockedStackLocked() != null) { 251f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale return true; 252f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale } 253f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale return false; 254f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale } 255f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale 256f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale /** Bounds of the task with other system factors taken into consideration. */ 2570689ae903628f12ff073376b655b9d972533796bFilip Gruszczynski @Override 2580689ae903628f12ff073376b655b9d972533796bFilip Gruszczynski public void getBounds(Rect out) { 259f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale if (useCurrentBounds()) { 260f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale // No need to adjust the output bounds if fullscreen or the docked stack is visible 261f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale // since it is already what we want to represent to the rest of the system. 262f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale out.set(mBounds); 263f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale return; 264f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale } 265f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale 266f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale // The bounds has been adjusted to accommodate for a docked stack, but the docked stack 267f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale // is not currently visible. Go ahead a represent it as fullscreen to the rest of the 268f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale // system. 269f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale mStack.getDisplayContent().getLogicalDisplayRect(out); 270e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale } 271e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale 2723005e75585dcda30b64603e320e0711b583624ddChong Zhang void setDragResizing(boolean dragResizing) { 2733005e75585dcda30b64603e320e0711b583624ddChong Zhang mDragResizing = dragResizing; 2743005e75585dcda30b64603e320e0711b583624ddChong Zhang } 2753005e75585dcda30b64603e320e0711b583624ddChong Zhang 2763005e75585dcda30b64603e320e0711b583624ddChong Zhang boolean isDragResizing() { 2773005e75585dcda30b64603e320e0711b583624ddChong Zhang return mDragResizing; 2783005e75585dcda30b64603e320e0711b583624ddChong Zhang } 2793005e75585dcda30b64603e320e0711b583624ddChong Zhang 280e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale void updateDisplayInfo(final DisplayContent displayContent) { 281e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale if (displayContent == null) { 282e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale return; 283e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale } 284e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale if (mFullscreen) { 285ebcc875f10f05db7365cd8afbf4e9425221ab14dFilip Gruszczynski setBounds(null, Configuration.EMPTY); 286e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale return; 287e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale } 288e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale final int newRotation = displayContent.getDisplayInfo().rotation; 289e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale if (mRotation == newRotation) { 290e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale return; 291e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale } 292e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale 293e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale // Device rotation changed. We don't want the task to move around on the screen when 294e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale // this happens, so update the task bounds so it stays in the same place. 2959474421a56c8bf66086a9d253013687eb5207331Wale Ogunwale mTmpRect2.set(mBounds); 2969474421a56c8bf66086a9d253013687eb5207331Wale Ogunwale displayContent.rotateBounds(mRotation, newRotation, mTmpRect2); 2971ed0d89e7e9a28a5dd52fdc40425466efd8d08efWale Ogunwale if (setBounds(mTmpRect2, mOverrideConfig) != BOUNDS_CHANGE_NONE) { 2981ed0d89e7e9a28a5dd52fdc40425466efd8d08efWale Ogunwale // Post message to inform activity manager of the bounds change simulating 2991ed0d89e7e9a28a5dd52fdc40425466efd8d08efWale Ogunwale // a one-way call. We do this to prevent a deadlock between window manager 30044bc4daff31d2d6f632695008a0e5f5272ff4f56Filip Gruszczynski // lock and activity manager lock been held. Only tasks within the freeform stack 30144bc4daff31d2d6f632695008a0e5f5272ff4f56Filip Gruszczynski // are resizeable independently of their stack resizing. 30244bc4daff31d2d6f632695008a0e5f5272ff4f56Filip Gruszczynski if (mStack.mStackId == FREEFORM_WORKSPACE_STACK_ID) { 30344bc4daff31d2d6f632695008a0e5f5272ff4f56Filip Gruszczynski mService.mH.sendMessage(mService.mH.obtainMessage( 30444bc4daff31d2d6f632695008a0e5f5272ff4f56Filip Gruszczynski RESIZE_TASK, mTaskId, RESIZE_MODE_SYSTEM_SCREEN_ROTATION, mBounds)); 30544bc4daff31d2d6f632695008a0e5f5272ff4f56Filip Gruszczynski } 3061ed0d89e7e9a28a5dd52fdc40425466efd8d08efWale Ogunwale } 307e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale } 308e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale 309e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale void resizeWindows() { 310e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale final ArrayList<WindowState> resizingWindows = mService.mResizingWindows; 311e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) { 312e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale final ArrayList<WindowState> windows = mAppTokens.get(activityNdx).allAppWindows; 313e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { 314e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale final WindowState win = windows.get(winNdx); 315e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale if (!resizingWindows.contains(win)) { 316e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale if (DEBUG_RESIZE) Slog.d(TAG, "setBounds: Resizing " + win); 317e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale resizingWindows.add(win); 318e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale } 319e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale } 320e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale } 321e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale } 322e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale 323c28098f69b8ba5d3039ecd0fa154e880f4613843Winson /** 324c28098f69b8ba5d3039ecd0fa154e880f4613843Winson * Cancels any running app transitions associated with the task. 325c28098f69b8ba5d3039ecd0fa154e880f4613843Winson */ 326c28098f69b8ba5d3039ecd0fa154e880f4613843Winson void cancelTaskWindowTransition() { 327c28098f69b8ba5d3039ecd0fa154e880f4613843Winson for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) { 328c28098f69b8ba5d3039ecd0fa154e880f4613843Winson mAppTokens.get(activityNdx).mAppAnimator.clearAnimation(); 329c28098f69b8ba5d3039ecd0fa154e880f4613843Winson } 330c28098f69b8ba5d3039ecd0fa154e880f4613843Winson } 331c28098f69b8ba5d3039ecd0fa154e880f4613843Winson 33213d30660ef6da2d924e4fc943ccd187767ee0cd2Winson /** 33313d30660ef6da2d924e4fc943ccd187767ee0cd2Winson * Cancels any running thumbnail transitions associated with the task. 33413d30660ef6da2d924e4fc943ccd187767ee0cd2Winson */ 33513d30660ef6da2d924e4fc943ccd187767ee0cd2Winson void cancelTaskThumbnailTransition() { 33613d30660ef6da2d924e4fc943ccd187767ee0cd2Winson for (int activityNdx = mAppTokens.size() - 1; activityNdx >= 0; --activityNdx) { 33713d30660ef6da2d924e4fc943ccd187767ee0cd2Winson mAppTokens.get(activityNdx).mAppAnimator.clearThumbnail(); 33813d30660ef6da2d924e4fc943ccd187767ee0cd2Winson } 33913d30660ef6da2d924e4fc943ccd187767ee0cd2Winson } 34013d30660ef6da2d924e4fc943ccd187767ee0cd2Winson 3416dfdfd6741c5a3dd8d8a49ddbd6ee5dfe2fd292dWale Ogunwale boolean showForAllUsers() { 3423fcb4a89750d6df42f850021cd754500fc084086Wale Ogunwale final int tokensCount = mAppTokens.size(); 3436dfdfd6741c5a3dd8d8a49ddbd6ee5dfe2fd292dWale Ogunwale return (tokensCount != 0) && mAppTokens.get(tokensCount - 1).showForAllUsers; 3443fcb4a89750d6df42f850021cd754500fc084086Wale Ogunwale } 3453fcb4a89750d6df42f850021cd754500fc084086Wale Ogunwale 346db20b5f7a1fdb847f2266df0fbae6046dc95c757Chong Zhang boolean inHomeStack() { 347db20b5f7a1fdb847f2266df0fbae6046dc95c757Chong Zhang return mStack != null && mStack.mStackId == HOME_STACK_ID; 348db20b5f7a1fdb847f2266df0fbae6046dc95c757Chong Zhang } 349db20b5f7a1fdb847f2266df0fbae6046dc95c757Chong Zhang 35009b21efb97d539543259b33e2da9d4c7a41966c8Chong Zhang boolean inFreeformWorkspace() { 35109b21efb97d539543259b33e2da9d4c7a41966c8Chong Zhang return mStack != null && mStack.mStackId == FREEFORM_WORKSPACE_STACK_ID; 35209b21efb97d539543259b33e2da9d4c7a41966c8Chong Zhang } 35309b21efb97d539543259b33e2da9d4c7a41966c8Chong Zhang 354955b2fc732382022959889e90694801c36b8a71aFilip Gruszczynski boolean inDockedWorkspace() { 355955b2fc732382022959889e90694801c36b8a71aFilip Gruszczynski return mStack != null && mStack.mStackId == DOCKED_STACK_ID; 356955b2fc732382022959889e90694801c36b8a71aFilip Gruszczynski } 357955b2fc732382022959889e90694801c36b8a71aFilip Gruszczynski 3589184ec686072e9343c9dd73cf45324e5e89e042fChong Zhang WindowState getTopAppMainWindow() { 3599184ec686072e9343c9dd73cf45324e5e89e042fChong Zhang final int tokensCount = mAppTokens.size(); 3609184ec686072e9343c9dd73cf45324e5e89e042fChong Zhang return tokensCount > 0 ? mAppTokens.get(tokensCount - 1).findMainWindow() : null; 3619184ec686072e9343c9dd73cf45324e5e89e042fChong Zhang } 362bef461f6129044bc092f0c3693bfc122d1acb6d1Chong Zhang 363bef461f6129044bc092f0c3693bfc122d1acb6d1Chong Zhang AppWindowToken getTopAppWindowToken() { 364bef461f6129044bc092f0c3693bfc122d1acb6d1Chong Zhang final int tokensCount = mAppTokens.size(); 365bef461f6129044bc092f0c3693bfc122d1acb6d1Chong Zhang return tokensCount > 0 ? mAppTokens.get(tokensCount - 1) : null; 366bef461f6129044bc092f0c3693bfc122d1acb6d1Chong Zhang } 3679184ec686072e9343c9dd73cf45324e5e89e042fChong Zhang 3685d9c7be84d9628c1cf199fcf9015942835c4671bCraig Mautner @Override 369e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale public boolean isFullscreen() { 370f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale if (useCurrentBounds()) { 371f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale return mFullscreen; 372f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale } 373f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale // The bounds has been adjusted to accommodate for a docked stack, but the docked stack 374f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale // is not currently visible. Go ahead a represent it as fullscreen to the rest of the 375f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale // system. 376f175e8a6d0d3f3ce6be94bde451e6e03f67d0705Wale Ogunwale return true; 377e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale } 378e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale 379e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale @Override 380e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale public DisplayInfo getDisplayInfo() { 381e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale return mStack.getDisplayContent().getDisplayInfo(); 382e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale } 383e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale 384e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale @Override 3855d9c7be84d9628c1cf199fcf9015942835c4671bCraig Mautner public String toString() { 38683162a90278d9d52d8fca7ee20ba314b452261deCraig Mautner return "{taskId=" + mTaskId + " appTokens=" + mAppTokens + " mdr=" + mDeferRemoval + "}"; 3875d9c7be84d9628c1cf199fcf9015942835c4671bCraig Mautner } 388e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale 3890689ae903628f12ff073376b655b9d972533796bFilip Gruszczynski @Override 3900689ae903628f12ff073376b655b9d972533796bFilip Gruszczynski public String toShortString() { 3910689ae903628f12ff073376b655b9d972533796bFilip Gruszczynski return "Task=" + mTaskId; 3920689ae903628f12ff073376b655b9d972533796bFilip Gruszczynski } 3930689ae903628f12ff073376b655b9d972533796bFilip Gruszczynski 394e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale public void printTo(String prefix, PrintWriter pw) { 395e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale pw.print(prefix); pw.print("taskId="); pw.print(mTaskId); 396e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale pw.print(prefix); pw.print("appTokens="); pw.print(mAppTokens); 397e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale pw.print(prefix); pw.print("mdr="); pw.println(mDeferRemoval); 398e4a0c5722b1d8db95dfc842d716452dbbf02c86dWale Ogunwale } 399b1fd65c0ff5784b90d765edb7e3c3115d767dff0Craig Mautner} 400