From a0b530e2850e1cacd10003b1e98ff827242a9f45 Mon Sep 17 00:00:00 2001 From: Louis Chang Date: Wed, 22 Mar 2023 02:30:34 +0000 Subject: [PATCH] Ensure the activity type is set to the activity This CL reverts the changes in commit f920308. The activity type was an attribute in ActivityRecord, but added as part of window configuration after unify. To keep the same behavior as it used to be, this CL makes sure the activity type is set to the activity's requested override configuration. In general, the activity type is not necessary to be set while creating a Task. The activity type of a Task is determined while the first activity added into the task. Also throw exceptions on debuggable builds if activity type is changed once set. Bug: 274751858 Test: wm presubmit Test: drag contacts to split-screen Change-Id: Ibf18bd6ec932ffef21bf556beea9004c25473203 --- .../com/android/server/wm/ActivityRecord.java | 9 +++++++-- .../core/java/com/android/server/wm/Task.java | 16 +++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index a327a426204a1..cb928251f17f8 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -9059,8 +9059,13 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } if (activityType != ACTIVITY_TYPE_UNDEFINED && activityType != getActivityType()) { - Slog.w(TAG, "Can't change activity type once set: " + this - + " activityType=" + activityTypeToString(getActivityType())); + final String errorMessage = "Can't change activity type once set: " + this + + " activityType=" + activityTypeToString(getActivityType()) + ", was " + + activityTypeToString(activityType); + if (Build.IS_DEBUGGABLE) { + throw new IllegalStateException(errorMessage); + } + Slog.w(TAG, errorMessage); } // Configuration's equality doesn't consider seq so if only seq number changes in resolved diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java index 699e02e8cc6af..fce3ec728f1a5 100644 --- a/services/core/java/com/android/server/wm/Task.java +++ b/services/core/java/com/android/server/wm/Task.java @@ -1429,14 +1429,22 @@ class Task extends TaskFragment { // Only set this based on the first activity if (!hadActivity) { - if (r.getActivityType() == ACTIVITY_TYPE_UNDEFINED) { + int activityOverrideType = + r.getRequestedOverrideConfiguration().windowConfiguration.getActivityType(); + if (activityOverrideType == ACTIVITY_TYPE_UNDEFINED) { // Normally non-standard activity type for the activity record will be set when the // object is created, however we delay setting the standard application type until // this point so that the task can set the type for additional activities added in // the else condition below. - r.setActivityType(ACTIVITY_TYPE_STANDARD); + activityOverrideType = activityType != ACTIVITY_TYPE_UNDEFINED ? activityType + : ACTIVITY_TYPE_STANDARD; + // Set the Activity's requestedOverrideConfiguration directly to reduce + // WC#onConfigurationChanged calls since it will be called while setting the + // Task's activity type below. + r.getRequestedOverrideConfiguration().windowConfiguration.setActivityType( + activityOverrideType); } - setActivityType(r.getActivityType()); + setActivityType(activityOverrideType); isPersistable = r.isPersistable(); mCallingUid = r.launchedFromUid; mCallingPackage = r.launchedFromPackage; @@ -5775,8 +5783,6 @@ class Task extends TaskFragment { final int activityType = getActivityType(); task = new Task.Builder(mAtmService) .setTaskId(taskId) - .setActivityType(activityType != ACTIVITY_TYPE_UNDEFINED ? activityType - : ACTIVITY_TYPE_STANDARD) .setActivityInfo(info) .setActivityOptions(options) .setIntent(intent)