Upgrade resize mode setting for home activities when restoring task
We need to convert the resize mode of home activities saved before
version 1 of the persisted task record if they are marked as
RESIZE_MODE_RESIZEABLE to RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION
since we didn't have that differentiation before version 1 and the
system didn't resize home activities before then.
Bug: 30982291
Bug: 32231084
Test: Verify that a device runnin N upgraded to O doesn't resize the
home activity when in split-screen multi-window mode.
Change-Id: I3c9dfcc8be2651b06f7ab77abe4edb9653742952
(cherry picked from commit 625ed0c3027a6e8f3e1b1314f5a6984e8d2e3c65)
diff --git a/services/core/java/com/android/server/am/TaskPersister.java b/services/core/java/com/android/server/am/TaskPersister.java
index 0817f0d..1ecb2e9 100644
--- a/services/core/java/com/android/server/am/TaskPersister.java
+++ b/services/core/java/com/android/server/am/TaskPersister.java
@@ -54,6 +54,8 @@
import java.util.Comparator;
import java.util.List;
+import static android.app.ActivityManager.StackId.HOME_STACK_ID;
+
public class TaskPersister {
static final String TAG = "TaskPersister";
static final boolean DEBUG = false;
@@ -450,7 +452,7 @@
final int taskId = task.taskId;
if (mStackSupervisor.anyTaskForIdLocked(taskId,
- /* restoreFromRecents= */ false, 0) != null) {
+ /* restoreFromRecents= */ false, HOME_STACK_ID) != null) {
// Should not happen.
Slog.wtf(TAG, "Existing task with taskId " + taskId + "found");
} else if (userId != task.userId) {
diff --git a/services/core/java/com/android/server/am/TaskRecord.java b/services/core/java/com/android/server/am/TaskRecord.java
index 77d0db3..9d97dd3 100644
--- a/services/core/java/com/android/server/am/TaskRecord.java
+++ b/services/core/java/com/android/server/am/TaskRecord.java
@@ -75,6 +75,8 @@
import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED;
import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_NEVER;
import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE;
+import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE;
+import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
import static android.content.pm.ApplicationInfo.PRIVATE_FLAG_PRIVILEGED;
import static android.provider.Settings.Secure.USER_SETUP_COMPLETE;
import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ADD_REMOVE;
@@ -132,8 +134,11 @@
private static final String ATTR_NON_FULLSCREEN_BOUNDS = "non_fullscreen_bounds";
private static final String ATTR_MIN_WIDTH = "min_width";
private static final String ATTR_MIN_HEIGHT = "min_height";
+ private static final String ATTR_PERSIST_TASK_VERSION = "persist_task_version";
-
+ // Current version of the task record we persist. Used to check if we need to run any upgrade
+ // code.
+ private static final int PERSIST_TASK_VERSION = 1;
private static final String TASK_THUMBNAIL_SUFFIX = "_task_thumbnail";
static final int INVALID_TASK_ID = -1;
@@ -1231,6 +1236,7 @@
}
out.attribute(null, ATTR_MIN_WIDTH, String.valueOf(mMinWidth));
out.attribute(null, ATTR_MIN_HEIGHT, String.valueOf(mMinHeight));
+ out.attribute(null, ATTR_PERSIST_TASK_VERSION, String.valueOf(PERSIST_TASK_VERSION));
if (affinityIntent != null) {
out.startTag(null, TAG_AFFINITYINTENT);
@@ -1297,6 +1303,7 @@
Rect bounds = null;
int minWidth = INVALID_MIN_SIZE;
int minHeight = INVALID_MIN_SIZE;
+ int persistTaskVersion = 0;
for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
final String attrName = in.getAttributeName(attrNdx);
@@ -1366,6 +1373,8 @@
minWidth = Integer.parseInt(attrValue);
} else if (ATTR_MIN_HEIGHT.equals(attrName)) {
minHeight = Integer.parseInt(attrValue);
+ } else if (ATTR_PERSIST_TASK_VERSION.equals(attrName)) {
+ persistTaskVersion = Integer.parseInt(attrValue);
} else {
Slog.w(TAG, "TaskRecord: Unknown attribute=" + attrName);
}
@@ -1420,6 +1429,16 @@
+ ": effectiveUid=" + effectiveUid);
}
+ if (persistTaskVersion < 1) {
+ // We need to convert the resize mode of home activities saved before version one if
+ // they are marked as RESIZE_MODE_RESIZEABLE to RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION
+ // since we didn't have that differentiation before version 1 and the system didn't
+ // resize home activities before then.
+ if (taskType == HOME_ACTIVITY_TYPE && resizeMode == RESIZE_MODE_RESIZEABLE) {
+ resizeMode = RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
+ }
+ }
+
final TaskRecord task = new TaskRecord(stackSupervisor.mService, taskId, intent,
affinityIntent, affinity, rootAffinity, realActivity, origActivity, rootHasReset,
autoRemoveRecents, askedCompatMode, taskType, userId, effectiveUid, lastDescription,