Adjust PiP source rect hint for window bounds

The source rect hint specified by the app is normally a result of
View#getGlobalVisibleRect (or equivalent) that does not count the window
offset in scenarios like the app is placed in the middle of display by
the system when
    - app specifies sensorLandscape
    - display is actually in portrait mode (on large screens)

Fixed this by adjust the source rect hint on ActivityRecord whenever the
internal PictureInPictureParams is updated.

Video: http://recall/-/aaaaaabFQoRHlzixHdtY/dr7uy1qxB1RGjZVvElo7kr
Bug: 235599028
Test: Verify entering PiP animation working as intended for \
      app specifies sensorLandscape when auto-enter-pip and \
      make-launch-into-pip (aka. content-pip).
Test: atest WmTests:ActivityRecorderTests \
            WmTests:ActivityStarterTests
Change-Id: Id991adbae45a7b61d09105a9aee9cbfecd6b66be
This commit is contained in:
Hongwei Wang
2022-07-07 13:38:04 -07:00
parent 18dfc2fb12
commit ccfa7d8b50
3 changed files with 17 additions and 2 deletions

View File

@@ -1149,7 +1149,6 @@ public class ActivityOptions extends ComponentOptions {
opts.mLaunchIntoPipParams = new PictureInPictureParams.Builder(pictureInPictureParams)
.setIsLaunchIntoPip(true)
.build();
opts.mLaunchBounds = new Rect(pictureInPictureParams.getSourceRectHint());
return opts;
}

View File

@@ -1993,6 +1993,9 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
if (options.getLaunchIntoPipParams() != null) {
pictureInPictureArgs = options.getLaunchIntoPipParams();
if (sourceRecord != null) {
adjustPictureInPictureParamsIfNeeded(sourceRecord.getBounds());
}
}
mOverrideTaskTransition = options.getOverrideTaskTransition();
@@ -9765,6 +9768,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
void setPictureInPictureParams(PictureInPictureParams p) {
pictureInPictureArgs.copyOnlySet(p);
adjustPictureInPictureParamsIfNeeded(getBounds());
getTask().getRootTask().onPictureInPictureParamsChanged();
}
@@ -9816,6 +9820,18 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
return new Point(windowLayout.minWidth, windowLayout.minHeight);
}
/**
* Adjust the source rect hint in {@link #pictureInPictureArgs} by window bounds since
* it is relative to its root view (see also b/235599028).
* It is caller's responsibility to make sure this is called exactly once when we update
* {@link #pictureInPictureArgs} to avoid double offset.
*/
private void adjustPictureInPictureParamsIfNeeded(Rect windowBounds) {
if (pictureInPictureArgs != null && pictureInPictureArgs.hasSourceBoundsHint()) {
pictureInPictureArgs.getSourceRectHint().offset(windowBounds.left, windowBounds.top);
}
}
static class Builder {
private final ActivityTaskManagerService mAtmService;
private WindowProcessController mCallerApp;

View File

@@ -2118,7 +2118,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
// entering content-pip animation.
mWindowManager.mTaskSnapshotController.recordTaskSnapshot(
task, false /* allowSnapshotHome */);
rootTask.setBounds(r.getOptions().getLaunchBounds());
rootTask.setBounds(r.pictureInPictureArgs.getSourceRectHint());
}
rootTask.setDeferTaskAppear(false);