Merge "Remove meaningless ActivityStarter#mReuseTask" into tm-dev

This commit is contained in:
Riddle Hsu
2022-04-07 10:41:45 +00:00
committed by Android (Google) Code Review

View File

@@ -195,7 +195,6 @@ class ActivityStarter {
private TaskFragment mInTaskFragment; private TaskFragment mInTaskFragment;
@VisibleForTesting @VisibleForTesting
boolean mAddingToTask; boolean mAddingToTask;
private Task mReuseTask;
private ActivityInfo mNewTaskInfo; private ActivityInfo mNewTaskInfo;
private Intent mNewTaskIntent; private Intent mNewTaskIntent;
@@ -204,6 +203,7 @@ class ActivityStarter {
// The task that the last activity was started into. We currently reset the actual start // The task that the last activity was started into. We currently reset the actual start
// activity's task and as a result may not have a reference to the task in all cases // activity's task and as a result may not have a reference to the task in all cases
private Task mTargetTask; private Task mTargetTask;
private boolean mIsTaskCleared;
private boolean mMovedToFront; private boolean mMovedToFront;
private boolean mNoAnimation; private boolean mNoAnimation;
private boolean mAvoidMoveToFront; private boolean mAvoidMoveToFront;
@@ -597,7 +597,6 @@ class ActivityStarter {
mInTask = starter.mInTask; mInTask = starter.mInTask;
mInTaskFragment = starter.mInTaskFragment; mInTaskFragment = starter.mInTaskFragment;
mAddingToTask = starter.mAddingToTask; mAddingToTask = starter.mAddingToTask;
mReuseTask = starter.mReuseTask;
mNewTaskInfo = starter.mNewTaskInfo; mNewTaskInfo = starter.mNewTaskInfo;
mNewTaskIntent = starter.mNewTaskIntent; mNewTaskIntent = starter.mNewTaskIntent;
@@ -605,6 +604,7 @@ class ActivityStarter {
mTargetTask = starter.mTargetTask; mTargetTask = starter.mTargetTask;
mTargetRootTask = starter.mTargetRootTask; mTargetRootTask = starter.mTargetRootTask;
mIsTaskCleared = starter.mIsTaskCleared;
mMovedToFront = starter.mMovedToFront; mMovedToFront = starter.mMovedToFront;
mNoAnimation = starter.mNoAnimation; mNoAnimation = starter.mNoAnimation;
mAvoidMoveToFront = starter.mAvoidMoveToFront; mAvoidMoveToFront = starter.mAvoidMoveToFront;
@@ -1568,10 +1568,7 @@ class ActivityStarter {
return; return;
} }
final int clearTaskFlags = FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK; if (result == START_TASK_TO_FRONT || result == START_DELIVERED_TO_TOP) {
boolean clearedTask = (mLaunchFlags & clearTaskFlags) == clearTaskFlags
&& mReuseTask != null;
if (result == START_TASK_TO_FRONT || result == START_DELIVERED_TO_TOP || clearedTask) {
// The activity was already running so it wasn't started, but either brought to the // The activity was already running so it wasn't started, but either brought to the
// front or the new intent was delivered to it since it was already in front. Notify // front or the new intent was delivered to it since it was already in front. Notify
// anyone interested in this piece of information. // anyone interested in this piece of information.
@@ -1581,7 +1578,7 @@ class ActivityStarter {
final ActivityRecord top = targetTask.getTopNonFinishingActivity(); final ActivityRecord top = targetTask.getTopNonFinishingActivity();
final boolean visible = top != null && top.isVisible(); final boolean visible = top != null && top.isVisible();
mService.getTaskChangeNotificationController().notifyActivityRestartAttempt( mService.getTaskChangeNotificationController().notifyActivityRestartAttempt(
targetTask.getTaskInfo(), homeTaskVisible, clearedTask, visible); targetTask.getTaskInfo(), homeTaskVisible, mIsTaskCleared, visible);
} }
if (ActivityManager.isStartResultSuccessful(result)) { if (ActivityManager.isStartResultSuccessful(result)) {
@@ -1927,6 +1924,7 @@ class ActivityStarter {
return START_SUCCESS; return START_SUCCESS;
} }
/** Returns the leaf task where the target activity may be placed. */
private Task computeTargetTask() { private Task computeTargetTask() {
if (mStartActivity.resultTo == null && mInTask == null && !mAddingToTask if (mStartActivity.resultTo == null && mInTask == null && !mAddingToTask
&& (mLaunchFlags & FLAG_ACTIVITY_NEW_TASK) != 0) { && (mLaunchFlags & FLAG_ACTIVITY_NEW_TASK) != 0) {
@@ -1937,11 +1935,9 @@ class ActivityStarter {
} else if (mInTask != null) { } else if (mInTask != null) {
// The task is specified from AppTaskImpl, so it may not be attached yet. // The task is specified from AppTaskImpl, so it may not be attached yet.
if (!mInTask.isAttached()) { if (!mInTask.isAttached()) {
// Clear reuse task so it can find a proper parent to add the task. // Attach the task to display area. Ignore the returned root task (though usually
if (mReuseTask == mInTask) { // they are the same) because "target task" should be leaf task.
mReuseTask = null; getOrCreateRootTask(mStartActivity, mLaunchFlags, mInTask, mOptions);
}
return getOrCreateRootTask(mStartActivity, mLaunchFlags, mInTask, mOptions);
} }
return mInTask; return mInTask;
} else { } else {
@@ -2233,13 +2229,12 @@ class ActivityStarter {
// activity. Well that should not be too hard... // activity. Well that should not be too hard...
// Note: we must persist the {@link Task} first as intentActivity could be // Note: we must persist the {@link Task} first as intentActivity could be
// removed from calling performClearTaskLocked (For example, if it is being brought out // removed from calling performClearTaskLocked (For example, if it is being brought out
// of history or if it is finished immediately), thus disassociating the task. Also note // of history or if it is finished immediately), thus disassociating the task. Keep the
// that mReuseTask is reset as a result of {@link Task#performClearTaskLocked} // task-overlay activity because the targetTask will be reused to launch new activity.
// launching another activity. Keep the task-overlay activity because the targetTask
// will be reused to launch new activity.
targetTask.performClearTaskForReuse(true /* excludingTaskOverlay*/); targetTask.performClearTaskForReuse(true /* excludingTaskOverlay*/);
targetTask.setIntent(mStartActivity); targetTask.setIntent(mStartActivity);
mAddingToTask = true; mAddingToTask = true;
mIsTaskCleared = true;
} else if ((mLaunchFlags & FLAG_ACTIVITY_CLEAR_TOP) != 0 } else if ((mLaunchFlags & FLAG_ACTIVITY_CLEAR_TOP) != 0
|| isDocumentLaunchesIntoExisting(mLaunchFlags) || isDocumentLaunchesIntoExisting(mLaunchFlags)
|| isLaunchModeOneOf(LAUNCH_SINGLE_INSTANCE, LAUNCH_SINGLE_TASK, || isLaunchModeOneOf(LAUNCH_SINGLE_INSTANCE, LAUNCH_SINGLE_TASK,
@@ -2352,7 +2347,6 @@ class ActivityStarter {
mInTask = null; mInTask = null;
mInTaskFragment = null; mInTaskFragment = null;
mAddingToTask = false; mAddingToTask = false;
mReuseTask = null;
mNewTaskInfo = null; mNewTaskInfo = null;
mNewTaskIntent = null; mNewTaskIntent = null;
@@ -2360,6 +2354,7 @@ class ActivityStarter {
mTargetRootTask = null; mTargetRootTask = null;
mTargetTask = null; mTargetTask = null;
mIsTaskCleared = false;
mMovedToFront = false; mMovedToFront = false;
mNoAnimation = false; mNoAnimation = false;
mAvoidMoveToFront = false; mAvoidMoveToFront = false;
@@ -2577,8 +2572,6 @@ class ActivityStarter {
} else { } else {
mAddingToTask = true; mAddingToTask = true;
} }
mReuseTask = mInTask;
} else { } else {
mInTask = null; mInTask = null;
// Launch ResolverActivity in the source task, so that it stays in the task bounds // Launch ResolverActivity in the source task, so that it stays in the task bounds
@@ -2851,7 +2844,7 @@ class ActivityStarter {
mNewTaskIntent != null ? mNewTaskIntent : mIntent, mVoiceSession, mNewTaskIntent != null ? mNewTaskIntent : mIntent, mVoiceSession,
mVoiceInteractor, toTop, mStartActivity, mSourceRecord, mOptions); mVoiceInteractor, toTop, mStartActivity, mSourceRecord, mOptions);
task.mTransitionController.collectExistenceChange(task); task.mTransitionController.collectExistenceChange(task);
addOrReparentStartingActivity(task, "setTaskFromReuseOrCreateNewTask - mReuseTask"); addOrReparentStartingActivity(task, "setTaskFromReuseOrCreateNewTask");
ProtoLog.v(WM_DEBUG_TASKS, "Starting new activity %s in new task %s", ProtoLog.v(WM_DEBUG_TASKS, "Starting new activity %s in new task %s",
mStartActivity, mStartActivity.getTask()); mStartActivity, mStartActivity.getTask());
@@ -2961,11 +2954,6 @@ class ActivityStarter {
private Task getOrCreateRootTask(ActivityRecord r, int launchFlags, Task task, private Task getOrCreateRootTask(ActivityRecord r, int launchFlags, Task task,
ActivityOptions aOptions) { ActivityOptions aOptions) {
// We are reusing a task, keep the root task!
if (mReuseTask != null) {
return mReuseTask.getRootTask();
}
final boolean onTop = final boolean onTop =
(aOptions == null || !aOptions.getAvoidMoveToFront()) && !mLaunchTaskBehind; (aOptions == null || !aOptions.getAvoidMoveToFront()) && !mLaunchTaskBehind;
final Task sourceTask = mSourceRecord != null ? mSourceRecord.getTask() : null; final Task sourceTask = mSourceRecord != null ? mSourceRecord.getTask() : null;