setAdjacentTaskFragments for paired TaskFragment

Bug: 190433129
Test: Tested with sample app
Change-Id: Ifa4cf3df77f053d2f5806290989329d3a2b47160
This commit is contained in:
Chris Li
2021-07-27 14:02:20 -07:00
parent cc3b202fab
commit 36c3af87dc
5 changed files with 35 additions and 13 deletions

View File

@@ -506,15 +506,17 @@ public final class WindowContainerTransaction implements Parcelable {
* {@link #setAdjacentRoots(WindowContainerToken, WindowContainerToken)}, but can be used with
* fragmentTokens when that TaskFragments haven't been created (but will be created in the same
* {@link WindowContainerTransaction}).
* To reset it, pass {@code null} for {@code fragmentToken2}.
* @param fragmentToken1 client assigned unique token to create TaskFragment with specified
* in {@link TaskFragmentCreationParams#getFragmentToken()}.
* @param fragmentToken2 client assigned unique token to create TaskFragment with specified
* in {@link TaskFragmentCreationParams#getFragmentToken()}.
* in {@link TaskFragmentCreationParams#getFragmentToken()}. If it is
* {@code null}, the transaction will reset the adjacent TaskFragment.
* @hide
*/
@NonNull
public WindowContainerTransaction setAdjacentTaskFragments(
@NonNull IBinder fragmentToken1, @NonNull IBinder fragmentToken2) {
@NonNull IBinder fragmentToken1, @Nullable IBinder fragmentToken2) {
final HierarchyOp hierarchyOp =
new HierarchyOp.Builder(HierarchyOp.HIERARCHY_OP_TYPE_SET_ADJACENT_TASK_FRAGMENTS)
.setContainer(fragmentToken1)

View File

@@ -116,6 +116,9 @@ class JetpackTaskFragmentOrganizer extends TaskFragmentOrganizer {
secondaryFragmentBounds, WINDOWING_MODE_MULTI_WINDOW, activityIntent,
activityOptions);
// Set adjacent to each other so that the containers below will be invisible.
wct.setAdjacentTaskFragments(launchingFragmentToken, secondaryFragmentToken);
applyTransaction(wct);
}
@@ -126,6 +129,7 @@ class JetpackTaskFragmentOrganizer extends TaskFragmentOrganizer {
*/
void expandTaskFragment(WindowContainerTransaction wct, IBinder fragmentToken) {
resizeTaskFragment(wct, fragmentToken, new Rect());
wct.setAdjacentTaskFragments(fragmentToken, null);
}
/**

View File

@@ -142,8 +142,9 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer {
resizeTaskFragmentIfRegistered(wct, secondaryContainer, secondaryRectBounds);
}
// TODO(b/190433398): The primary container and the secondary container should also be set
// as adjacent (WCT#setAdjacentRoots) to make activities behind invisible.
// Set adjacent to each other so that the containers below will be invisible.
wct.setAdjacentTaskFragments(
primaryContainer.getTaskFragmentToken(), secondaryContainer.getTaskFragmentToken());
applyTransaction(wct);
mController.registerSplit(primaryContainer, primaryActivity, secondaryContainer, rule);
@@ -184,9 +185,6 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer {
primaryContainer.setLastRequestedBounds(primaryRectBounds);
secondaryContainer.setLastRequestedBounds(secondaryRectBounds);
// TODO(b/190433398): The primary container and the secondary container should also be set
// as adjacent (WCT#setAdjacentRoots) to make activities behind invisible.
mController.registerSplit(primaryContainer, launchingActivity, secondaryContainer,
rule);
}

View File

@@ -161,7 +161,8 @@ class TaskFragment extends WindowContainer<WindowContainer> {
/** Avoid reentrant of {@link #removeImmediately()}. */
private boolean mRemoving;
// The TaskFragment that adjacent to this one.
/** The TaskFragment that is adjacent to this one. */
@Nullable
private TaskFragment mAdjacentTaskFragment;
/**
@@ -282,9 +283,23 @@ class TaskFragment extends WindowContainer<WindowContainer> {
mRemoteToken = new RemoteToken(this);
}
void setAdjacentTaskFragment(TaskFragment taskFragment) {
mAdjacentTaskFragment = taskFragment;
taskFragment.mAdjacentTaskFragment = this;
void setAdjacentTaskFragment(@Nullable TaskFragment taskFragment) {
if (mAdjacentTaskFragment == taskFragment) {
return;
}
resetAdjacentTaskFragment();
if (taskFragment != null) {
mAdjacentTaskFragment = taskFragment;
taskFragment.setAdjacentTaskFragment(this);
}
}
private void resetAdjacentTaskFragment() {
// Reset the adjacent TaskFragment if its adjacent TaskFragment is also this TaskFragment.
if (mAdjacentTaskFragment != null && mAdjacentTaskFragment.mAdjacentTaskFragment == this) {
mAdjacentTaskFragment.mAdjacentTaskFragment = null;
}
mAdjacentTaskFragment = null;
}
void setTaskFragmentOrganizer(TaskFragmentOrganizerToken organizer, int pid) {
@@ -1951,6 +1966,7 @@ class TaskFragment extends WindowContainer<WindowContainer> {
return;
}
mRemoving = true;
resetAdjacentTaskFragment();
super.removeImmediately();
sendTaskFragmentVanished();
mRemoving = false;

View File

@@ -720,8 +720,10 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
fragmentToken = hop.getContainer();
final IBinder adjacentFragmentToken = hop.getAdjacentRoot();
final TaskFragment tf1 = mLaunchTaskFragments.get(fragmentToken);
final TaskFragment tf2 = mLaunchTaskFragments.get(adjacentFragmentToken);
if (tf1 == null || tf2 == null) {
final TaskFragment tf2 = adjacentFragmentToken != null
? mLaunchTaskFragments.get(adjacentFragmentToken)
: null;
if (tf1 == null || (adjacentFragmentToken != null && tf2 == null)) {
final Throwable exception = new IllegalArgumentException(
"Not allowed to set adjacent on invalid fragment tokens");
sendTaskFragmentOperationFailure(organizer, errorCallbackToken, exception);