Merge "Avoid re-adding to existing split" into sc-v2-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
ef81c4557f
@@ -149,6 +149,7 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
|
||||
* Checks if the activity start should be routed to a particular container. It can create a new
|
||||
* container for the activity and a new split container if necessary.
|
||||
*/
|
||||
// TODO(b/190433398): Break down into smaller functions.
|
||||
void onActivityCreated(@NonNull Activity launchedActivity) {
|
||||
final ComponentName componentName = launchedActivity.getComponentName();
|
||||
|
||||
@@ -202,6 +203,18 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the split is already set.
|
||||
final TaskFragmentContainer activityBelowContainer = getContainerWithActivity(
|
||||
activityBelow.getActivityToken());
|
||||
if (currentContainer != null && activityBelowContainer != null) {
|
||||
final SplitContainer existingSplit = getActiveSplitForContainers(currentContainer,
|
||||
activityBelowContainer);
|
||||
if (existingSplit != null) {
|
||||
// There is already an active split with the activity below.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final ExtensionSplitPairRule splitPairRule = getSplitRule(
|
||||
activityBelow.getComponentName(), componentName, splitRules);
|
||||
if (splitPairRule == null) {
|
||||
@@ -339,7 +352,7 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the top active split container that has the provided container.
|
||||
* Returns the top active split container that has the provided container, if available.
|
||||
*/
|
||||
@Nullable
|
||||
private SplitContainer getActiveSplitForContainer(@NonNull TaskFragmentContainer container) {
|
||||
@@ -353,6 +366,26 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the active split that has the provided containers as primary and secondary or as
|
||||
* secondary and primary, if available.
|
||||
*/
|
||||
@Nullable
|
||||
private SplitContainer getActiveSplitForContainers(
|
||||
@NonNull TaskFragmentContainer firstContainer,
|
||||
@NonNull TaskFragmentContainer secondContainer) {
|
||||
for (int i = mSplitContainers.size() - 1; i >= 0; i--) {
|
||||
SplitContainer splitContainer = mSplitContainers.get(i);
|
||||
final TaskFragmentContainer primary = splitContainer.getPrimaryContainer();
|
||||
final TaskFragmentContainer secondary = splitContainer.getSecondaryContainer();
|
||||
if ((firstContainer == secondary && secondContainer == primary)
|
||||
|| (firstContainer == primary && secondContainer == secondary)) {
|
||||
return splitContainer;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the container requires a placeholder and launches it if necessary.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user