Merge "Ensure TaskOrganizer works for newly created pinned stack" into rvc-dev
This commit is contained in:
@@ -126,7 +126,7 @@ public class PipTaskOrganizer extends TaskOrganizer {
|
|||||||
};
|
};
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private Handler.Callback mUpdateCallbacks = (msg) -> {
|
private final Handler.Callback mUpdateCallbacks = (msg) -> {
|
||||||
SomeArgs args = (SomeArgs) msg.obj;
|
SomeArgs args = (SomeArgs) msg.obj;
|
||||||
Consumer<Rect> updateBoundsCallback = (Consumer<Rect>) args.arg1;
|
Consumer<Rect> updateBoundsCallback = (Consumer<Rect>) args.arg1;
|
||||||
switch (msg.what) {
|
switch (msg.what) {
|
||||||
@@ -282,7 +282,7 @@ public class PipTaskOrganizer extends TaskOrganizer {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onTaskVanished(ActivityManager.RunningTaskInfo info) {
|
public void onTaskVanished(ActivityManager.RunningTaskInfo info) {
|
||||||
WindowContainerToken token = info.token;
|
final WindowContainerToken token = info.token;
|
||||||
Objects.requireNonNull(token, "Requires valid WindowContainerToken");
|
Objects.requireNonNull(token, "Requires valid WindowContainerToken");
|
||||||
if (token.asBinder() != mToken.asBinder()) {
|
if (token.asBinder() != mToken.asBinder()) {
|
||||||
Log.wtf(TAG, "Unrecognized token: " + token);
|
Log.wtf(TAG, "Unrecognized token: " + token);
|
||||||
@@ -297,6 +297,7 @@ public class PipTaskOrganizer extends TaskOrganizer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTaskInfoChanged(ActivityManager.RunningTaskInfo info) {
|
public void onTaskInfoChanged(ActivityManager.RunningTaskInfo info) {
|
||||||
|
Objects.requireNonNull(mToken, "onTaskInfoChanged requires valid existing mToken");
|
||||||
final PictureInPictureParams newParams = info.pictureInPictureParams;
|
final PictureInPictureParams newParams = info.pictureInPictureParams;
|
||||||
if (!shouldUpdateDestinationBounds(newParams)) {
|
if (!shouldUpdateDestinationBounds(newParams)) {
|
||||||
Log.d(TAG, "Ignored onTaskInfoChanged with PiP param: " + newParams);
|
Log.d(TAG, "Ignored onTaskInfoChanged with PiP param: " + newParams);
|
||||||
@@ -375,7 +376,7 @@ public class PipTaskOrganizer extends TaskOrganizer {
|
|||||||
@PipAnimationController.TransitionDirection int direction, int durationMs,
|
@PipAnimationController.TransitionDirection int direction, int durationMs,
|
||||||
Consumer<Rect> updateBoundsCallback) {
|
Consumer<Rect> updateBoundsCallback) {
|
||||||
if (!mInPip) {
|
if (!mInPip) {
|
||||||
// Ignore animation when we are no longer in PIP
|
// can be initiated in other component, ignore if we are no longer in PIP
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SomeArgs args = SomeArgs.obtain();
|
SomeArgs args = SomeArgs.obtain();
|
||||||
@@ -427,6 +428,10 @@ public class PipTaskOrganizer extends TaskOrganizer {
|
|||||||
private void scheduleFinishResizePip(SurfaceControl.Transaction tx,
|
private void scheduleFinishResizePip(SurfaceControl.Transaction tx,
|
||||||
Rect destinationBounds, @PipAnimationController.TransitionDirection int direction,
|
Rect destinationBounds, @PipAnimationController.TransitionDirection int direction,
|
||||||
Consumer<Rect> updateBoundsCallback) {
|
Consumer<Rect> updateBoundsCallback) {
|
||||||
|
if (!mInPip) {
|
||||||
|
// can be initiated in other component, ignore if we are no longer in PIP
|
||||||
|
return;
|
||||||
|
}
|
||||||
SomeArgs args = SomeArgs.obtain();
|
SomeArgs args = SomeArgs.obtain();
|
||||||
args.arg1 = updateBoundsCallback;
|
args.arg1 = updateBoundsCallback;
|
||||||
args.arg2 = tx;
|
args.arg2 = tx;
|
||||||
@@ -441,7 +446,7 @@ public class PipTaskOrganizer extends TaskOrganizer {
|
|||||||
public void scheduleOffsetPip(Rect originalBounds, int offset, int duration,
|
public void scheduleOffsetPip(Rect originalBounds, int offset, int duration,
|
||||||
Consumer<Rect> updateBoundsCallback) {
|
Consumer<Rect> updateBoundsCallback) {
|
||||||
if (!mInPip) {
|
if (!mInPip) {
|
||||||
// Ignore offsets when we are no longer in PIP
|
// can be initiated in other component, ignore if we are no longer in PIP
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SomeArgs args = SomeArgs.obtain();
|
SomeArgs args = SomeArgs.obtain();
|
||||||
|
|||||||
@@ -1298,6 +1298,19 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
|
|||||||
if (newTask != null && isState(RESUMED)) {
|
if (newTask != null && isState(RESUMED)) {
|
||||||
newTask.setResumedActivity(this, "onParentChanged");
|
newTask.setResumedActivity(this, "onParentChanged");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (stack != null && stack.topRunningActivity() == this) {
|
||||||
|
// carry over the PictureInPictureParams to the parent stack without calling
|
||||||
|
// TaskOrganizerController#dispatchTaskInfoChanged.
|
||||||
|
// this is to ensure the stack holding up-to-dated pinned stack information
|
||||||
|
// when activity is re-parented to enter pip mode, see also
|
||||||
|
// RootWindowContainer#moveActivityToPinnedStack
|
||||||
|
stack.mPictureInPictureParams.copyOnlySet(pictureInPictureArgs);
|
||||||
|
// make ensure the TaskOrganizer still works after re-parenting
|
||||||
|
if (firstWindowDrawn) {
|
||||||
|
stack.setHasBeenVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateColorTransform() {
|
private void updateColorTransform() {
|
||||||
|
|||||||
@@ -4093,11 +4093,8 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
|
|||||||
r.setPictureInPictureParams(params);
|
r.setPictureInPictureParams(params);
|
||||||
final float aspectRatio = r.pictureInPictureArgs.getAspectRatio();
|
final float aspectRatio = r.pictureInPictureArgs.getAspectRatio();
|
||||||
final List<RemoteAction> actions = r.pictureInPictureArgs.getActions();
|
final List<RemoteAction> actions = r.pictureInPictureArgs.getActions();
|
||||||
// Adjust the source bounds by the insets for the transition down
|
|
||||||
final Rect sourceBounds = new Rect(
|
|
||||||
r.pictureInPictureArgs.getSourceRectHint());
|
|
||||||
mRootWindowContainer.moveActivityToPinnedStack(
|
mRootWindowContainer.moveActivityToPinnedStack(
|
||||||
r, sourceBounds, aspectRatio, "enterPictureInPictureMode");
|
r, "enterPictureInPictureMode");
|
||||||
final ActivityStack stack = r.getRootTask();
|
final ActivityStack stack = r.getRootTask();
|
||||||
stack.setPictureInPictureAspectRatio(aspectRatio);
|
stack.setPictureInPictureAspectRatio(aspectRatio);
|
||||||
stack.setPictureInPictureActions(actions);
|
stack.setPictureInPictureActions(actions);
|
||||||
|
|||||||
@@ -2147,13 +2147,11 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
moveActivityToPinnedStack(r, null /* sourceBounds */, 0f /* aspectRatio */,
|
moveActivityToPinnedStack(r, "moveTopActivityToPinnedStack");
|
||||||
"moveTopActivityToPinnedStack");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void moveActivityToPinnedStack(ActivityRecord r, Rect sourceHintBounds, float aspectRatio,
|
void moveActivityToPinnedStack(ActivityRecord r, String reason) {
|
||||||
String reason) {
|
|
||||||
mService.deferWindowLayout();
|
mService.deferWindowLayout();
|
||||||
|
|
||||||
final TaskDisplayArea taskDisplayArea = r.getDisplayArea();
|
final TaskDisplayArea taskDisplayArea = r.getDisplayArea();
|
||||||
@@ -2176,17 +2174,19 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
|
|||||||
final ActivityStack stack;
|
final ActivityStack stack;
|
||||||
if (singleActivity) {
|
if (singleActivity) {
|
||||||
stack = r.getRootTask();
|
stack = r.getRootTask();
|
||||||
stack.setWindowingMode(WINDOWING_MODE_PINNED);
|
|
||||||
} else {
|
} else {
|
||||||
// In the case of multiple activities, we will create a new task for it and then
|
// In the case of multiple activities, we will create a new task for it and then
|
||||||
// move the PIP activity into the task.
|
// move the PIP activity into the task.
|
||||||
stack = taskDisplayArea.createStack(WINDOWING_MODE_PINNED, r.getActivityType(),
|
stack = taskDisplayArea.createStack(WINDOWING_MODE_UNDEFINED, r.getActivityType(),
|
||||||
ON_TOP, r.info, r.intent, false /* createdByOrganizer */);
|
ON_TOP, r.info, r.intent, false /* createdByOrganizer */);
|
||||||
|
|
||||||
// There are multiple activities in the task and moving the top activity should
|
// There are multiple activities in the task and moving the top activity should
|
||||||
// reveal/leave the other activities in their original task.
|
// reveal/leave the other activities in their original task.
|
||||||
r.reparent(stack, MAX_VALUE, "moveActivityToStack");
|
// On the other hand, ActivityRecord#onParentChanged takes care of setting the
|
||||||
|
// up-to-dated pinned stack information on this newly created stack.
|
||||||
|
r.reparent(stack, MAX_VALUE, reason);
|
||||||
}
|
}
|
||||||
|
stack.setWindowingMode(WINDOWING_MODE_PINNED);
|
||||||
|
|
||||||
// Reset the state that indicates it can enter PiP while pausing after we've moved it
|
// Reset the state that indicates it can enter PiP while pausing after we've moved it
|
||||||
// to the pinned stack
|
// to the pinned stack
|
||||||
|
|||||||
@@ -58,7 +58,6 @@ import android.content.pm.ActivityInfo;
|
|||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Rect;
|
|
||||||
import android.platform.test.annotations.Presubmit;
|
import android.platform.test.annotations.Presubmit;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
@@ -126,9 +125,7 @@ public class RootActivityContainerTests extends ActivityTestsBase {
|
|||||||
ensureStackPlacement(mFullscreenStack, firstActivity, secondActivity);
|
ensureStackPlacement(mFullscreenStack, firstActivity, secondActivity);
|
||||||
|
|
||||||
// Move first activity to pinned stack.
|
// Move first activity to pinned stack.
|
||||||
final Rect sourceBounds = new Rect();
|
mRootWindowContainer.moveActivityToPinnedStack(firstActivity, "initialMove");
|
||||||
mRootWindowContainer.moveActivityToPinnedStack(firstActivity, sourceBounds,
|
|
||||||
0f /*aspectRatio*/, "initialMove");
|
|
||||||
|
|
||||||
final TaskDisplayArea taskDisplayArea = mFullscreenStack.getDisplayArea();
|
final TaskDisplayArea taskDisplayArea = mFullscreenStack.getDisplayArea();
|
||||||
ActivityStack pinnedStack = taskDisplayArea.getRootPinnedTask();
|
ActivityStack pinnedStack = taskDisplayArea.getRootPinnedTask();
|
||||||
@@ -137,8 +134,7 @@ public class RootActivityContainerTests extends ActivityTestsBase {
|
|||||||
ensureStackPlacement(mFullscreenStack, secondActivity);
|
ensureStackPlacement(mFullscreenStack, secondActivity);
|
||||||
|
|
||||||
// Move second activity to pinned stack.
|
// Move second activity to pinned stack.
|
||||||
mRootWindowContainer.moveActivityToPinnedStack(secondActivity, sourceBounds,
|
mRootWindowContainer.moveActivityToPinnedStack(secondActivity, "secondMove");
|
||||||
0f /*aspectRatio*/, "secondMove");
|
|
||||||
|
|
||||||
// Need to get stacks again as a new instance might have been created.
|
// Need to get stacks again as a new instance might have been created.
|
||||||
pinnedStack = taskDisplayArea.getRootPinnedTask();
|
pinnedStack = taskDisplayArea.getRootPinnedTask();
|
||||||
|
|||||||
Reference in New Issue
Block a user