diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java index 312e309e39507..c112843763645 100644 --- a/services/core/java/com/android/server/am/ActivityStack.java +++ b/services/core/java/com/android/server/am/ActivityStack.java @@ -4753,8 +4753,7 @@ final class ActivityStack { } void addConfigOverride(ActivityRecord r, TaskRecord task) { - final Rect bounds = task.getLaunchBounds(); - task.updateOverrideConfiguration(bounds); + final Rect bounds = task.updateOverrideConfigurationFromLaunchBounds(); mWindowManager.addAppToken(task.mActivities.indexOf(r), r.appToken, r.task.taskId, mStackId, r.info.screenOrientation, r.fullscreen, (r.info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0, r.userId, r.info.configChanges, @@ -4810,10 +4809,9 @@ final class ActivityStack { } private void setAppTask(ActivityRecord r, TaskRecord task) { - final Rect bounds = task.getLaunchBounds(); - task.updateOverrideConfiguration(bounds); + final Rect bounds = task.updateOverrideConfigurationFromLaunchBounds(); mWindowManager.setAppTask( - r.appToken, task.taskId, mStackId, task.getLaunchBounds(), task.mOverrideConfig); + r.appToken, task.taskId, mStackId, bounds, task.mOverrideConfig); mWindowManager.setTaskResizeable(task.taskId, task.mResizeable); r.taskConfigOverride = task.mOverrideConfig; } diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java index c634e0e6a6ac3..022b60b02d36a 100644 --- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java +++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java @@ -1673,7 +1673,7 @@ public final class ActivityStackSupervisor implements DisplayListener { if (task.mResizeable && options != null) { int stackId = options.getLaunchStackId(); if (canUseActivityOptionsLaunchBounds(options, stackId)) { - Rect bounds = options.getLaunchBounds(); + final Rect bounds = TaskRecord.validateBounds(options.getLaunchBounds()); task.updateOverrideConfiguration(bounds); if (stackId == INVALID_STACK_ID) { stackId = task.getLaunchStackId(); @@ -1841,6 +1841,7 @@ public final class ActivityStackSupervisor implements DisplayListener { // can have the right fullscreen state. bounds = null; } + bounds = TaskRecord.validateBounds(bounds); mTmpBounds.clear(); mTmpConfigs.clear(); @@ -1857,8 +1858,8 @@ public final class ActivityStackSupervisor implements DisplayListener { fitWithinBounds(tempRect2, bounds); task.updateOverrideConfiguration(tempRect2); } else { - task.updateOverrideConfiguration(tempTaskBounds != null - ? tempTaskBounds : bounds); + task.updateOverrideConfiguration( + tempTaskBounds != null ? tempTaskBounds : bounds); } } @@ -1973,6 +1974,7 @@ public final class ActivityStackSupervisor implements DisplayListener { // Nothing to do here... return true; } + bounds = TaskRecord.validateBounds(bounds); if (!mWindowManager.isValidTaskId(task.taskId)) { // Task doesn't exist in window manager yet (e.g. was restored from recents). diff --git a/services/core/java/com/android/server/am/ActivityStarter.java b/services/core/java/com/android/server/am/ActivityStarter.java index cfa44335f6eb4..6fa8950507611 100644 --- a/services/core/java/com/android/server/am/ActivityStarter.java +++ b/services/core/java/com/android/server/am/ActivityStarter.java @@ -1739,7 +1739,7 @@ class ActivityStarter { if (options != null && (r.isResizeable() || (inTask != null && inTask.mResizeable))) { if (mSupervisor.canUseActivityOptionsLaunchBounds( options, options.getLaunchStackId())) { - newBounds = options.getLaunchBounds(); + newBounds = TaskRecord.validateBounds(options.getLaunchBounds()); } } return newBounds; diff --git a/services/core/java/com/android/server/am/TaskRecord.java b/services/core/java/com/android/server/am/TaskRecord.java index 38ba737e38ce6..f7e30c0356257 100644 --- a/services/core/java/com/android/server/am/TaskRecord.java +++ b/services/core/java/com/android/server/am/TaskRecord.java @@ -1311,6 +1311,20 @@ final class TaskRecord { return !mOverrideConfig.equals(oldConfig) ? mOverrideConfig : null; } + Rect updateOverrideConfigurationFromLaunchBounds() { + final Rect bounds = validateBounds(getLaunchBounds()); + updateOverrideConfiguration(bounds); + return bounds; + } + + static Rect validateBounds(Rect bounds) { + if (bounds != null && bounds.isEmpty()) { + Slog.wtf(TAG, "Received strange task bounds: " + bounds, new Throwable()); + return null; + } + return bounds; + } + private void reportMultiWindowModeChange() { for (int i = mActivities.size() - 1; i >= 0; i--) { final ActivityRecord r = mActivities.get(i); diff --git a/services/core/java/com/android/server/wm/TaskStack.java b/services/core/java/com/android/server/wm/TaskStack.java index e75780f6a095f..27d6e03703dff 100644 --- a/services/core/java/com/android/server/wm/TaskStack.java +++ b/services/core/java/com/android/server/wm/TaskStack.java @@ -18,7 +18,6 @@ package com.android.server.wm; import android.app.ActivityManager.StackId; import android.content.res.Configuration; -import android.content.res.Resources; import android.graphics.Rect; import android.os.Debug; import android.util.EventLog; @@ -89,6 +88,7 @@ public class TaskStack implements DimLayer.DimLayerUser { /** Detach this stack from its display when animation completes. */ boolean mDeferDetach; + private boolean mUpdateBoundsAfterRotation = false; TaskStack(WindowManagerService service, int stackId) { mService = service; @@ -239,6 +239,7 @@ public class TaskStack implements DimLayer.DimLayerUser { } void updateDisplayInfo(Rect bounds) { + mUpdateBoundsAfterRotation = false; if (mDisplayContent != null) { for (int taskNdx = mTasks.size() - 1; taskNdx >= 0; --taskNdx) { mTasks.get(taskNdx).updateDisplayInfo(mDisplayContent); @@ -248,6 +249,7 @@ public class TaskStack implements DimLayer.DimLayerUser { } else if (mFullscreen) { setBounds(null); } else { + mUpdateBoundsAfterRotation = true; mTmpRect2.set(mBounds); final int newRotation = mDisplayContent.getDisplayInfo().rotation; if (mRotation == newRotation) { @@ -265,6 +267,10 @@ public class TaskStack implements DimLayer.DimLayerUser { * yet. */ void updateBoundsAfterRotation() { + if (!mUpdateBoundsAfterRotation) { + return; + } + mUpdateBoundsAfterRotation = false; final int newRotation = getDisplayInfo().rotation; mDisplayContent.rotateBounds(mRotation, newRotation, mTmpRect2); if (mStackId == DOCKED_STACK_ID) {