Use TaskFactory to create ActivityStack.

ActivityStack now can be used as a Task by itself, so we need to make
sure they are of right type.

Also changed the signature of that constructor to make it more natural.

Bug: 150409355
Test: WM smoke tests & TH.
Test: atest TaskRecordTests
Change-Id: Ia6aa8decd0af79e58344442e93bd15ca0e373fc9
This commit is contained in:
Garfield Tan
2020-02-28 09:48:15 -08:00
parent 755ce9edf9
commit 9867b5172a
4 changed files with 27 additions and 26 deletions

View File

@@ -556,9 +556,9 @@ class ActivityStack extends Task {
}
}
ActivityStack(DisplayContent display, int id, ActivityStackSupervisor supervisor,
int activityType, ActivityInfo info, Intent intent) {
this(supervisor.mService, id, info, intent, null /*voiceSession*/, null /*voiceInteractor*/,
ActivityStack(ActivityTaskManagerService atmService, int id, int activityType,
ActivityInfo info, Intent intent) {
this(atmService, id, info, intent, null /*voiceSession*/, null /*voiceInteractor*/,
null /*taskDescription*/, null /*stack*/);
setActivityType(activityType);

View File

@@ -5874,8 +5874,8 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
// Since this stack will be put into a tile, its windowingMode will be inherited.
windowingMode = WINDOWING_MODE_UNDEFINED;
}
final ActivityStack stack = new ActivityStack(this, stackId,
mRootWindowContainer.mStackSupervisor, activityType, info, intent);
final ActivityStack stack = (ActivityStack) Task.create(mAtmService, stackId, activityType,
info, intent);
addStack(stack, onTop ? POSITION_TOP : POSITION_BOTTOM);
stack.setWindowingMode(windowingMode, false /* animate */, false /* showRecents */,
false /* enteringSplitScreenMode */, false /* deferEnsuringVisibility */,

View File

@@ -3636,6 +3636,11 @@ class Task extends WindowContainer<WindowContainer> {
sTaskFactory = factory;
}
static Task create(ActivityTaskManagerService service, int taskId, int activityType,
ActivityInfo info, Intent intent) {
return getTaskFactory().create(service, taskId, activityType, info, intent);
}
static Task create(ActivityTaskManagerService service, int taskId, ActivityInfo info,
Intent intent, IVoiceInteractionSession voiceSession,
IVoiceInteractor voiceInteractor, ActivityStack stack) {
@@ -3643,11 +3648,6 @@ class Task extends WindowContainer<WindowContainer> {
service, taskId, info, intent, voiceSession, voiceInteractor, stack);
}
static Task create(ActivityTaskManagerService service, int taskId, ActivityInfo info,
Intent intent, TaskDescription taskDescription, ActivityStack stack) {
return getTaskFactory().create(service, taskId, info, intent, taskDescription, stack);
}
static Task restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor)
throws IOException, XmlPullParserException {
return getTaskFactory().restoreFromXml(in, stackSupervisor);
@@ -3659,6 +3659,10 @@ class Task extends WindowContainer<WindowContainer> {
* {@link #setTaskFactory(TaskFactory)}.
*/
static class TaskFactory {
Task create(ActivityTaskManagerService service, int taskId, int activityType,
ActivityInfo info, Intent intent) {
return new ActivityStack(service, taskId, activityType, info, intent);
}
Task create(ActivityTaskManagerService service, int taskId, ActivityInfo info,
Intent intent, IVoiceInteractionSession voiceSession,
@@ -3667,12 +3671,6 @@ class Task extends WindowContainer<WindowContainer> {
null /*taskDescription*/, stack);
}
Task create(ActivityTaskManagerService service, int taskId, ActivityInfo info,
Intent intent, TaskDescription taskDescription, ActivityStack stack) {
return new ActivityStack(service, taskId, info, intent, null /*voiceSession*/,
null /*voiceInteractor*/, taskDescription, stack);
}
/**
* Should only be used when we're restoring {@link Task} from storage.
*/

View File

@@ -111,7 +111,6 @@ public class TaskRecordTests extends ActivityTestsBase {
@Before
public void setUp() throws Exception {
Task.setTaskFactory(null);
mParentBounds = new Rect(10 /*left*/, 30 /*top*/, 80 /*right*/, 60 /*bottom*/);
removeGlobalMinSizeRestriction();
}
@@ -148,11 +147,16 @@ public class TaskRecordTests extends ActivityTestsBase {
TestTaskFactory factory = new TestTaskFactory();
Task.setTaskFactory(factory);
assertFalse(factory.mCreated);
try {
assertFalse(factory.mCreated);
Task.create(null, 0, null, null, null, null);
Task.create(mService, 0 /*taskId*/, 0 /*activityType*/,
new ActivityInfo(), new Intent());
assertTrue(factory.mCreated);
assertTrue(factory.mCreated);
} finally {
Task.setTaskFactory(null);
}
}
@Test
@@ -509,7 +513,7 @@ public class TaskRecordTests extends ActivityTestsBase {
info.targetActivity = targetClassName;
final Task task = Task.create(mService, 1 /* taskId */, info, intent,
null /* taskDescription */, null /*stack*/);
null /* voiceSession */, null /* voiceInteractor */, null /*stack*/);
assertEquals("The alias activity component should be saved in task intent.", aliasClassName,
task.intent.getComponent().getClassName());
@@ -997,17 +1001,16 @@ public class TaskRecordTests extends ActivityTestsBase {
private boolean mCreated = false;
@Override
Task create(ActivityTaskManagerService service, int taskId, ActivityInfo info,
Intent intent, IVoiceInteractionSession voiceSession,
IVoiceInteractor voiceInteractor, ActivityStack stack) {
Task create(ActivityTaskManagerService service, int taskId, int activityType,
ActivityInfo info, Intent intent) {
mCreated = true;
return null;
}
@Override
Task create(ActivityTaskManagerService service, int taskId, ActivityInfo info,
Intent intent, ActivityManager.TaskDescription taskDescription,
ActivityStack stack) {
Intent intent, IVoiceInteractionSession voiceSession,
IVoiceInteractor voiceInteractor, ActivityStack stack) {
mCreated = true;
return null;
}