Don't send split info callback before activity is created
Sending a split info callback before activity created would give developer a reference to a not fully initalized class. It is possible that an attemp to apply actions to such an activity in the split callback would lead to unexpected issues for developers. E.g. one might assuming that the UI for an activity would've been constructed at this point and try to update it to fit the split or collapsed state requirements. Bug: 228770009 Test: atest CtsWindowManagerJetpackTestCases:ActivityEmbeddingLifecycleTests Change-Id: I3a19a028ad6da9a6d534a97d315bce5f95b191af
This commit is contained in:
@@ -757,22 +757,14 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
|
||||
return null;
|
||||
}
|
||||
|
||||
private void updateCallbackIfNecessary() {
|
||||
updateCallbackIfNecessary(true /* deferCallbackUntilAllActivitiesCreated */);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies listeners about changes to split states if necessary.
|
||||
*
|
||||
* @param deferCallbackUntilAllActivitiesCreated boolean to indicate whether the split info
|
||||
* callback should be deferred until all the
|
||||
* organized activities have been created.
|
||||
*/
|
||||
private void updateCallbackIfNecessary(boolean deferCallbackUntilAllActivitiesCreated) {
|
||||
private void updateCallbackIfNecessary() {
|
||||
if (mEmbeddingCallback == null) {
|
||||
return;
|
||||
}
|
||||
if (deferCallbackUntilAllActivitiesCreated && !allActivitiesCreated()) {
|
||||
if (!allActivitiesCreated()) {
|
||||
return;
|
||||
}
|
||||
List<SplitInfo> currentSplitStates = getActiveSplitStates();
|
||||
@@ -828,9 +820,7 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
|
||||
for (int i = mTaskContainers.size() - 1; i >= 0; i--) {
|
||||
final List<TaskFragmentContainer> containers = mTaskContainers.valueAt(i).mContainers;
|
||||
for (TaskFragmentContainer container : containers) {
|
||||
if (container.getInfo() == null
|
||||
|| container.getInfo().getActivities().size()
|
||||
!= container.collectActivities().size()) {
|
||||
if (!container.taskInfoActivityCountMatchesCreated()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1011,11 +1001,8 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
|
||||
&& container.getTaskFragmentToken().equals(initialTaskFragmentToken)) {
|
||||
// The onTaskFragmentInfoChanged callback containing this activity has not
|
||||
// reached the client yet, so add the activity to the pending appeared
|
||||
// activities and send a split info callback to the client before
|
||||
// {@link Activity#onCreate} is called.
|
||||
// activities.
|
||||
container.addPendingAppearedActivity(activity);
|
||||
updateCallbackIfNecessary(
|
||||
false /* deferCallbackUntilAllActivitiesCreated */);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,6 +119,18 @@ class TaskFragmentContainer {
|
||||
return allActivities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the count of activities from the same process in task fragment info corresponds to
|
||||
* the ones created and available on the client side.
|
||||
*/
|
||||
boolean taskInfoActivityCountMatchesCreated() {
|
||||
if (mInfo == null) {
|
||||
return false;
|
||||
}
|
||||
return mPendingAppearedActivities.isEmpty()
|
||||
&& mInfo.getActivities().size() == collectActivities().size();
|
||||
}
|
||||
|
||||
ActivityStack toActivityStack() {
|
||||
return new ActivityStack(collectActivities(), isEmpty());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user