Merge "Skip duplicate setBounds requests for task fragments" into sc-v2-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
7d1040f716
@@ -99,39 +99,38 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTaskFragmentAppeared(@NonNull TaskFragmentAppearedInfo taskFragmentAppearedInfo) {
|
public void onTaskFragmentAppeared(@NonNull TaskFragmentAppearedInfo taskFragmentAppearedInfo) {
|
||||||
for (TaskFragmentContainer container : mContainers) {
|
TaskFragmentContainer container = getContainer(
|
||||||
if (container.getTaskFragmentToken().equals(
|
taskFragmentAppearedInfo.getTaskFragmentInfo().getFragmentToken());
|
||||||
taskFragmentAppearedInfo.getTaskFragmentInfo().getFragmentToken())) {
|
if (container == null) {
|
||||||
container.setInfo(taskFragmentAppearedInfo.getTaskFragmentInfo());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
container.setInfo(taskFragmentAppearedInfo.getTaskFragmentInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTaskFragmentInfoChanged(@NonNull TaskFragmentInfo taskFragmentInfo) {
|
public void onTaskFragmentInfoChanged(@NonNull TaskFragmentInfo taskFragmentInfo) {
|
||||||
for (TaskFragmentContainer container : mContainers) {
|
TaskFragmentContainer container = getContainer(taskFragmentInfo.getFragmentToken());
|
||||||
if (container.getTaskFragmentToken().equals(taskFragmentInfo.getFragmentToken())) {
|
if (container == null) {
|
||||||
container.setInfo(taskFragmentInfo);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
container.setInfo(taskFragmentInfo);
|
||||||
if (taskFragmentInfo.isEmpty()) {
|
if (taskFragmentInfo.isEmpty()) {
|
||||||
cleanupContainer(container, true /* shouldFinishDependent */);
|
cleanupContainer(container, true /* shouldFinishDependent */);
|
||||||
updateCallbackIfNecessary();
|
updateCallbackIfNecessary();
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTaskFragmentVanished(@NonNull TaskFragmentInfo taskFragmentInfo) {
|
public void onTaskFragmentVanished(@NonNull TaskFragmentInfo taskFragmentInfo) {
|
||||||
for (TaskFragmentContainer container : mContainers) {
|
TaskFragmentContainer container = getContainer(taskFragmentInfo.getFragmentToken());
|
||||||
if (container.getTaskFragmentToken().equals(taskFragmentInfo.getFragmentToken())) {
|
if (container == null) {
|
||||||
cleanupContainer(container, true /* shouldFinishDependent */);
|
|
||||||
updateCallbackIfNecessary();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
cleanupContainer(container, true /* shouldFinishDependent */);
|
||||||
|
updateCallbackIfNecessary();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -480,7 +479,7 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private TaskFragmentContainer getContainer(@NonNull IBinder fragmentToken) {
|
TaskFragmentContainer getContainer(@NonNull IBinder fragmentToken) {
|
||||||
for (TaskFragmentContainer container : mContainers) {
|
for (TaskFragmentContainer container : mContainers) {
|
||||||
if (container.getTaskFragmentToken().equals(fragmentToken)) {
|
if (container.getTaskFragmentToken().equals(fragmentToken)) {
|
||||||
return container;
|
return container;
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import android.content.Intent;
|
|||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.IBinder;
|
||||||
import android.window.TaskFragmentCreationParams;
|
import android.window.TaskFragmentCreationParams;
|
||||||
import android.window.WindowContainerTransaction;
|
import android.window.WindowContainerTransaction;
|
||||||
|
|
||||||
@@ -98,8 +99,6 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer {
|
|||||||
|
|
||||||
final Rect parentBounds = getParentContainerBounds(primaryActivity);
|
final Rect parentBounds = getParentContainerBounds(primaryActivity);
|
||||||
final Rect primaryRectBounds = getBoundsForPosition(POSITION_LEFT, parentBounds, rule);
|
final Rect primaryRectBounds = getBoundsForPosition(POSITION_LEFT, parentBounds, rule);
|
||||||
final Rect secondaryRectBounds = getBoundsForPosition(POSITION_RIGHT, parentBounds, rule);
|
|
||||||
|
|
||||||
TaskFragmentContainer primaryContainer = mController.getContainerWithActivity(
|
TaskFragmentContainer primaryContainer = mController.getContainerWithActivity(
|
||||||
primaryActivity.getActivityToken());
|
primaryActivity.getActivityToken());
|
||||||
if (primaryContainer == null) {
|
if (primaryContainer == null) {
|
||||||
@@ -115,10 +114,13 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer {
|
|||||||
|
|
||||||
wct.reparentActivityToTaskFragment(primaryContainer.getTaskFragmentToken(),
|
wct.reparentActivityToTaskFragment(primaryContainer.getTaskFragmentToken(),
|
||||||
primaryActivity.getActivityToken());
|
primaryActivity.getActivityToken());
|
||||||
|
|
||||||
|
primaryContainer.setLastRequestedBounds(primaryRectBounds);
|
||||||
} else {
|
} else {
|
||||||
resizeTaskFragmentIfRegistered(wct, primaryContainer, primaryRectBounds);
|
resizeTaskFragmentIfRegistered(wct, primaryContainer, primaryRectBounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Rect secondaryRectBounds = getBoundsForPosition(POSITION_RIGHT, parentBounds, rule);
|
||||||
TaskFragmentContainer secondaryContainer = mController.getContainerWithActivity(
|
TaskFragmentContainer secondaryContainer = mController.getContainerWithActivity(
|
||||||
secondaryActivity.getActivityToken());
|
secondaryActivity.getActivityToken());
|
||||||
if (secondaryContainer == null || secondaryContainer == primaryContainer) {
|
if (secondaryContainer == null || secondaryContainer == primaryContainer) {
|
||||||
@@ -134,6 +136,8 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer {
|
|||||||
|
|
||||||
wct.reparentActivityToTaskFragment(secondaryContainer.getTaskFragmentToken(),
|
wct.reparentActivityToTaskFragment(secondaryContainer.getTaskFragmentToken(),
|
||||||
secondaryActivity.getActivityToken());
|
secondaryActivity.getActivityToken());
|
||||||
|
|
||||||
|
secondaryContainer.setLastRequestedBounds(secondaryRectBounds);
|
||||||
} else {
|
} else {
|
||||||
resizeTaskFragmentIfRegistered(wct, secondaryContainer, secondaryRectBounds);
|
resizeTaskFragmentIfRegistered(wct, secondaryContainer, secondaryRectBounds);
|
||||||
}
|
}
|
||||||
@@ -177,6 +181,9 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer {
|
|||||||
activityIntent,
|
activityIntent,
|
||||||
activityOptions);
|
activityOptions);
|
||||||
|
|
||||||
|
primaryContainer.setLastRequestedBounds(primaryRectBounds);
|
||||||
|
secondaryContainer.setLastRequestedBounds(secondaryRectBounds);
|
||||||
|
|
||||||
// TODO(b/190433398): The primary container and the secondary container should also be set
|
// TODO(b/190433398): The primary container and the secondary container should also be set
|
||||||
// as adjacent (WCT#setAdjacentRoots) to make activities behind invisible.
|
// as adjacent (WCT#setAdjacentRoots) to make activities behind invisible.
|
||||||
|
|
||||||
@@ -199,7 +206,6 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer {
|
|||||||
final Rect primaryRectBounds = getBoundsForPosition(POSITION_LEFT, parentBounds, rule);
|
final Rect primaryRectBounds = getBoundsForPosition(POSITION_LEFT, parentBounds, rule);
|
||||||
final Rect secondaryRectBounds = getBoundsForPosition(POSITION_RIGHT, parentBounds, rule);
|
final Rect secondaryRectBounds = getBoundsForPosition(POSITION_RIGHT, parentBounds, rule);
|
||||||
|
|
||||||
// TODO(b/190433398): Check if the bounds actually changed.
|
|
||||||
// If the task fragments are not registered yet, the positions will be updated after they
|
// If the task fragments are not registered yet, the positions will be updated after they
|
||||||
// are created again.
|
// are created again.
|
||||||
resizeTaskFragmentIfRegistered(wct, splitContainer.getPrimaryContainer(),
|
resizeTaskFragmentIfRegistered(wct, splitContainer.getPrimaryContainer(),
|
||||||
@@ -219,10 +225,27 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer {
|
|||||||
if (container.getInfo() == null) {
|
if (container.getInfo() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// TODO(b/190433398): Check if the bounds actually changed.
|
|
||||||
resizeTaskFragment(wct, container.getTaskFragmentToken(), bounds);
|
resizeTaskFragment(wct, container.getTaskFragmentToken(), bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void resizeTaskFragment(@NonNull WindowContainerTransaction wct, @NonNull IBinder fragmentToken,
|
||||||
|
@Nullable Rect bounds) {
|
||||||
|
TaskFragmentContainer container = mController.getContainer(fragmentToken);
|
||||||
|
if (container == null) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Resizing a task fragment that is not registered with controller.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (container.areLastRequestedBoundsEqual(bounds)) {
|
||||||
|
// Return early if the provided bounds were already requested
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
container.setLastRequestedBounds(bounds);
|
||||||
|
super.resizeTaskFragment(wct, fragmentToken, bounds);
|
||||||
|
}
|
||||||
|
|
||||||
boolean shouldShowSideBySide(@NonNull SplitContainer splitContainer) {
|
boolean shouldShowSideBySide(@NonNull SplitContainer splitContainer) {
|
||||||
final Rect parentBounds = getParentContainerBounds(splitContainer.getPrimaryContainer());
|
final Rect parentBounds = getParentContainerBounds(splitContainer.getPrimaryContainer());
|
||||||
return shouldShowSideBySide(parentBounds, splitContainer.getSplitPairRule());
|
return shouldShowSideBySide(parentBounds, splitContainer.getSplitPairRule());
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import android.annotation.NonNull;
|
|||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.ActivityThread;
|
import android.app.ActivityThread;
|
||||||
|
import android.graphics.Rect;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.window.TaskFragmentInfo;
|
import android.window.TaskFragmentInfo;
|
||||||
@@ -59,6 +60,11 @@ class TaskFragmentContainer {
|
|||||||
/** Indicates whether the container was cleaned up after the last activity was removed. */
|
/** Indicates whether the container was cleaned up after the last activity was removed. */
|
||||||
private boolean mIsFinished;
|
private boolean mIsFinished;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bounds that were requested last via {@link android.window.WindowContainerTransaction}.
|
||||||
|
*/
|
||||||
|
private final Rect mLastRequestedBounds = new Rect();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a container with an existing activity that will be re-parented to it in a window
|
* Creates a container with an existing activity that will be re-parented to it in a window
|
||||||
* container transaction.
|
* container transaction.
|
||||||
@@ -199,4 +205,23 @@ class TaskFragmentContainer {
|
|||||||
boolean isFinished() {
|
boolean isFinished() {
|
||||||
return mIsFinished;
|
return mIsFinished;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if last requested bounds are equal to the provided value.
|
||||||
|
*/
|
||||||
|
boolean areLastRequestedBoundsEqual(@Nullable Rect bounds) {
|
||||||
|
return (bounds == null && mLastRequestedBounds.isEmpty())
|
||||||
|
|| mLastRequestedBounds.equals(bounds);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the last requested bounds.
|
||||||
|
*/
|
||||||
|
void setLastRequestedBounds(@Nullable Rect bounds) {
|
||||||
|
if (bounds == null) {
|
||||||
|
mLastRequestedBounds.setEmpty();
|
||||||
|
} else {
|
||||||
|
mLastRequestedBounds.set(bounds);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user