Fix PiP being out of bounds when launched into forced orientation

- Ensure that we use the right bounds when calculating the post-rotation
  bounds (it should always be the target bounds)
- Ensure that we update the controller when the task stack bounds change

Bug: 35402420
Test: android.server.cts.ActivityManagerPinnedStackTests
Test: #testEnterPipToOtherOrientation
Change-Id: Ie0e3fc6a93b4eb6250c60584e80afb029b3c599a
This commit is contained in:
Winson Chung
2017-02-16 18:58:12 -08:00
parent eba6e6c7dc
commit 47f2bf605f
2 changed files with 44 additions and 40 deletions

View File

@@ -230,32 +230,37 @@ class PinnedStackController {
}
/**
* @param preChangeTargetBounds The final bounds of the stack if it is currently animating
* @return the repositioned PIP bounds given it's pre-change bounds, and the new display
* content.
* Updates the display info, calculating and returning the new stack and movement bounds in the
* new orientation of the device if necessary.
*/
Rect onDisplayChanged(Rect preChangeStackBounds, Rect preChangeTargetBounds,
DisplayContent displayContent) {
final Rect postChangeStackBounds = new Rect(preChangeTargetBounds);
final DisplayInfo displayInfo = displayContent.getDisplayInfo();
if (!mDisplayInfo.equals(displayInfo)) {
// Calculate the snap fraction of the current stack along the old movement bounds, and
// then update the stack bounds to the same fraction along the rotated movement bounds.
final Rect preChangeMovementBounds = getMovementBounds(preChangeStackBounds);
final float snapFraction = mSnapAlgorithm.getSnapFraction(preChangeStackBounds,
preChangeMovementBounds);
mDisplayInfo.copyFrom(displayInfo);
final Rect postChangeMovementBounds = getMovementBounds(preChangeStackBounds,
false /* adjustForIme */);
mSnapAlgorithm.applySnapFraction(postChangeStackBounds, postChangeMovementBounds,
snapFraction);
if (mIsMinimized) {
applyMinimizedOffset(postChangeStackBounds, postChangeMovementBounds);
}
notifyMovementBoundsChanged(false /* fromImeAdjustment */);
void onTaskStackBoundsChanged(Rect targetBounds, Rect outBounds) {
final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
if (mDisplayInfo.equals(displayInfo)) {
return;
}
return postChangeStackBounds;
mTmpRect.set(targetBounds);
final Rect postChangeStackBounds = mTmpRect;
// Calculate the snap fraction of the current stack along the old movement bounds
final Rect preChangeMovementBounds = getMovementBounds(postChangeStackBounds);
final float snapFraction = mSnapAlgorithm.getSnapFraction(postChangeStackBounds,
preChangeMovementBounds);
mDisplayInfo.copyFrom(displayInfo);
// Calculate the stack bounds in the new orientation to the same same fraction along the
// rotated movement bounds.
final Rect postChangeMovementBounds = getMovementBounds(postChangeStackBounds,
false /* adjustForIme */);
mSnapAlgorithm.applySnapFraction(postChangeStackBounds, postChangeMovementBounds,
snapFraction);
if (mIsMinimized) {
applyMinimizedOffset(postChangeStackBounds, postChangeMovementBounds);
}
notifyMovementBoundsChanged(false /* fromImeAdjustment */);
outBounds.set(postChangeStackBounds);
}
/**

View File

@@ -262,6 +262,12 @@ public class TaskStack extends WindowContainer<Task> implements DimLayer.DimLaye
if (mDisplayContent != null) {
mDisplayContent.mDimLayerController.updateDimLayer(this);
if (mStackId == PINNED_STACK_ID) {
// Update the bounds based on any changes to the display info
getAnimatingBounds(mTmpRect2);
mDisplayContent.mPinnedStackControllerLocked.onTaskStackBoundsChanged(mTmpRect2,
bounds);
}
mAnimationBackgroundSurface.setBounds(bounds);
}
@@ -391,15 +397,18 @@ public class TaskStack extends WindowContainer<Task> implements DimLayer.DimLaye
return false;
}
if (StackId.tasksAreFloating(mStackId)) {
// Update stack bounds again since the display info has changed since updateDisplayInfo,
// however, for floating tasks, we don't need to apply the new rotation to the bounds,
// we can just update and return them here
setBounds(mBounds);
mBoundsAfterRotation.set(mBounds);
return true;
}
mTmpRect2.set(mBounds);
mDisplayContent.rotateBounds(mRotation, newRotation, mTmpRect2);
switch (mStackId) {
case PINNED_STACK_ID:
Rect targetBounds = new Rect();
getAnimatingBounds(targetBounds);
mTmpRect2 = mDisplayContent.getPinnedStackController().onDisplayChanged(mBounds,
targetBounds, mDisplayContent);
break;
case DOCKED_STACK_ID:
repositionDockedStackAfterRotation(mTmpRect2);
snapDockedStackAfterRotation(mTmpRect2);
@@ -651,7 +660,6 @@ public class TaskStack extends WindowContainer<Task> implements DimLayer.DimLaye
mAnimationBackgroundSurface = new DimLayer(mService, this, mDisplayContent.getDisplayId(),
"animation background stackId=" + mStackId);
final Rect oldBounds = new Rect(mBounds);
Rect bounds = null;
final TaskStack dockedStack = dc.getDockedStackIgnoringVisibility();
if (mStackId == DOCKED_STACK_ID
@@ -675,15 +683,6 @@ public class TaskStack extends WindowContainer<Task> implements DimLayer.DimLaye
}
updateDisplayInfo(bounds);
// Update the pinned stack controller after the display info is updated
if (mStackId == PINNED_STACK_ID) {
Rect targetBounds = new Rect();
getAnimatingBounds(targetBounds);
mDisplayContent.getPinnedStackController().onDisplayChanged(oldBounds, targetBounds,
mDisplayContent);
}
super.onDisplayChanged(dc);
}