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
This commit is contained in:
Louis Chang
2023-03-22 02:30:34 +00:00
parent dc8992c4b0
commit a0b530e285
2 changed files with 18 additions and 7 deletions

View File

@@ -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

View File

@@ -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)