Merge "Adding the new activity on the same TF of the cleared activity" into tm-dev
This commit is contained in:
@@ -192,6 +192,7 @@ class ActivityStarter {
|
|||||||
|
|
||||||
private Task mInTask;
|
private Task mInTask;
|
||||||
private TaskFragment mInTaskFragment;
|
private TaskFragment mInTaskFragment;
|
||||||
|
private TaskFragment mAddingToTaskFragment;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean mAddingToTask;
|
boolean mAddingToTask;
|
||||||
|
|
||||||
@@ -2254,20 +2255,27 @@ class ActivityStarter {
|
|||||||
// In this situation we want to remove all activities from the task up to the one
|
// In this situation we want to remove all activities from the task up to the one
|
||||||
// being started. In most cases this means we are resetting the task to its initial
|
// being started. In most cases this means we are resetting the task to its initial
|
||||||
// state.
|
// state.
|
||||||
final ActivityRecord top = targetTask.performClearTop(mStartActivity, mLaunchFlags);
|
final ActivityRecord clearTop = targetTask.performClearTop(mStartActivity,
|
||||||
|
mLaunchFlags);
|
||||||
|
|
||||||
if (top != null) {
|
if (clearTop != null && !clearTop.finishing) {
|
||||||
if (top.isRootOfTask()) {
|
if (clearTop.isRootOfTask()) {
|
||||||
// Activity aliases may mean we use different intents for the top activity,
|
// Activity aliases may mean we use different intents for the top activity,
|
||||||
// so make sure the task now has the identity of the new intent.
|
// so make sure the task now has the identity of the new intent.
|
||||||
top.getTask().setIntent(mStartActivity);
|
clearTop.getTask().setIntent(mStartActivity);
|
||||||
}
|
}
|
||||||
deliverNewIntent(top, intentGrants);
|
deliverNewIntent(clearTop, intentGrants);
|
||||||
} else {
|
} else {
|
||||||
// A special case: we need to start the activity because it is not currently
|
// A special case: we need to start the activity because it is not currently
|
||||||
// running, and the caller has asked to clear the current task to have this
|
// running, and the caller has asked to clear the current task to have this
|
||||||
// activity at the top.
|
// activity at the top.
|
||||||
mAddingToTask = true;
|
mAddingToTask = true;
|
||||||
|
// Adding the new activity to the same embedded TF of the clear-top activity if
|
||||||
|
// possible.
|
||||||
|
if (clearTop != null && clearTop.getTaskFragment() != null
|
||||||
|
&& clearTop.getTaskFragment().isEmbedded()) {
|
||||||
|
mAddingToTaskFragment = clearTop.getTaskFragment();
|
||||||
|
}
|
||||||
if (targetTask.getRootTask() == null) {
|
if (targetTask.getRootTask() == null) {
|
||||||
// Target root task got cleared when we all activities were removed above.
|
// Target root task got cleared when we all activities were removed above.
|
||||||
// Go ahead and reset it.
|
// Go ahead and reset it.
|
||||||
@@ -2892,14 +2900,19 @@ class ActivityStarter {
|
|||||||
newParent = mInTaskFragment;
|
newParent = mInTaskFragment;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final ActivityRecord top = task.topRunningActivity(false /* focusableOnly */,
|
TaskFragment candidateTf = mAddingToTaskFragment != null ? mAddingToTaskFragment : null;
|
||||||
false /* includingEmbeddedTask */);
|
if (candidateTf == null) {
|
||||||
final TaskFragment taskFragment = top != null ? top.getTaskFragment() : null;
|
final ActivityRecord top = task.topRunningActivity(false /* focusableOnly */,
|
||||||
if (taskFragment != null && taskFragment.isEmbedded()
|
false /* includingEmbeddedTask */);
|
||||||
&& canEmbedActivity(taskFragment, mStartActivity, false /* newTask */, task)) {
|
if (top != null) {
|
||||||
|
candidateTf = top.getTaskFragment();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (candidateTf != null && candidateTf.isEmbedded()
|
||||||
|
&& canEmbedActivity(candidateTf, mStartActivity, false /* newTask */, task)) {
|
||||||
// Use the embedded TaskFragment of the top activity as the new parent if the
|
// Use the embedded TaskFragment of the top activity as the new parent if the
|
||||||
// activity can be embedded.
|
// activity can be embedded.
|
||||||
newParent = top.getTaskFragment();
|
newParent = candidateTf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1644,7 +1644,7 @@ class Task extends TaskFragment {
|
|||||||
* activities on top of it and return the instance.
|
* activities on top of it and return the instance.
|
||||||
*
|
*
|
||||||
* @param newR Description of the new activity being started.
|
* @param newR Description of the new activity being started.
|
||||||
* @return Returns the old activity that should be continued to be used,
|
* @return Returns the existing activity in the task that performs the clear-top operation,
|
||||||
* or {@code null} if none was found.
|
* or {@code null} if none was found.
|
||||||
*/
|
*/
|
||||||
private ActivityRecord clearTopActivities(ActivityRecord newR, int launchFlags) {
|
private ActivityRecord clearTopActivities(ActivityRecord newR, int launchFlags) {
|
||||||
@@ -1663,7 +1663,6 @@ class Task extends TaskFragment {
|
|||||||
&& !ActivityStarter.isDocumentLaunchesIntoExisting(launchFlags)) {
|
&& !ActivityStarter.isDocumentLaunchesIntoExisting(launchFlags)) {
|
||||||
if (!r.finishing) {
|
if (!r.finishing) {
|
||||||
r.finishIfPossible("clear-task-top", false /* oomAdj */);
|
r.finishIfPossible("clear-task-top", false /* oomAdj */);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -266,7 +266,7 @@ public class TaskTests extends WindowTestsBase {
|
|||||||
// Detach from process so the activities can be removed from hierarchy when finishing.
|
// Detach from process so the activities can be removed from hierarchy when finishing.
|
||||||
activity1.detachFromProcess();
|
activity1.detachFromProcess();
|
||||||
activity2.detachFromProcess();
|
activity2.detachFromProcess();
|
||||||
assertNull(task.performClearTop(activity1, 0 /* launchFlags */));
|
assertTrue(task.performClearTop(activity1, 0 /* launchFlags */).finishing);
|
||||||
assertFalse(task.hasChild());
|
assertFalse(task.hasChild());
|
||||||
// In real case, the task should be preserved for adding new activity.
|
// In real case, the task should be preserved for adding new activity.
|
||||||
assertTrue(task.isAttached());
|
assertTrue(task.isAttached());
|
||||||
|
|||||||
Reference in New Issue
Block a user