Loading core/java/android/app/Activity.java +17 −0 Original line number Original line Diff line number Diff line Loading @@ -2070,6 +2070,7 @@ public class Activity extends ContextThemeWrapper if (args == null) { if (args == null) { throw new IllegalArgumentException("Expected non-null picture-in-picture args"); throw new IllegalArgumentException("Expected non-null picture-in-picture args"); } } updatePictureInPictureArgsForContentInsets(args); return ActivityManagerNative.getDefault().enterPictureInPictureMode(mToken, args); return ActivityManagerNative.getDefault().enterPictureInPictureMode(mToken, args); } catch (RemoteException e) { } catch (RemoteException e) { return false; return false; Loading @@ -2087,11 +2088,27 @@ public class Activity extends ContextThemeWrapper if (args == null) { if (args == null) { throw new IllegalArgumentException("Expected non-null picture-in-picture args"); throw new IllegalArgumentException("Expected non-null picture-in-picture args"); } } updatePictureInPictureArgsForContentInsets(args); ActivityManagerNative.getDefault().setPictureInPictureArgs(mToken, args); ActivityManagerNative.getDefault().setPictureInPictureArgs(mToken, args); } catch (RemoteException e) { } catch (RemoteException e) { } } } } /** * Updates the provided {@param args} with the last known content insets for this activity, to * be used with the source hint rect for the transition into PiP. */ private void updatePictureInPictureArgsForContentInsets(PictureInPictureArgs args) { if (args != null && args.hasSourceBoundsHint() && getWindow() != null && getWindow().peekDecorView() != null && getWindow().peekDecorView().getViewRootImpl() != null) { args.setSourceRectHintInsets( getWindow().peekDecorView().getViewRootImpl().getLastContentInsets()); } else { args.setSourceRectHintInsets(null); } } void dispatchMovedToDisplay(int displayId, Configuration config) { void dispatchMovedToDisplay(int displayId, Configuration config) { updateDisplay(displayId); updateDisplay(displayId); onMovedToDisplay(displayId, config); onMovedToDisplay(displayId, config); Loading core/java/android/app/PictureInPictureArgs.java +51 −1 Original line number Original line Diff line number Diff line Loading @@ -49,6 +49,13 @@ public final class PictureInPictureArgs implements Parcelable { @Nullable @Nullable private Rect mSourceRectHint; private Rect mSourceRectHint; /** * The content insets that are used with the source hint rect for the transition into PiP where * the insets are removed at the beginning of the transition. */ @Nullable private Rect mSourceRectHintInsets; PictureInPictureArgs(Parcel in) { PictureInPictureArgs(Parcel in) { if (in.readInt() != 0) { if (in.readInt() != 0) { mAspectRatio = in.readFloat(); mAspectRatio = in.readFloat(); Loading @@ -60,6 +67,9 @@ public final class PictureInPictureArgs implements Parcelable { if (in.readInt() != 0) { if (in.readInt() != 0) { mSourceRectHint = Rect.CREATOR.createFromParcel(in); mSourceRectHint = Rect.CREATOR.createFromParcel(in); } } if (in.readInt() != 0) { mSourceRectHintInsets = Rect.CREATOR.createFromParcel(in); } } } /** /** Loading Loading @@ -94,6 +104,9 @@ public final class PictureInPictureArgs implements Parcelable { if (otherArgs.hasSourceBoundsHint()) { if (otherArgs.hasSourceBoundsHint()) { mSourceRectHint = new Rect(otherArgs.getSourceRectHint()); mSourceRectHint = new Rect(otherArgs.getSourceRectHint()); } } if (otherArgs.hasSourceBoundsHintInsets()) { mSourceRectHintInsets = new Rect(otherArgs.getSourceRectHintInsets()); } } } /** /** Loading Loading @@ -167,13 +180,33 @@ public final class PictureInPictureArgs implements Parcelable { } } /** /** * @return the launch bounds * Sets the insets to be used with the source rect hint bounds. * @hide */ public void setSourceRectHintInsets(Rect insets) { if (insets == null) { mSourceRectHintInsets = null; } else { mSourceRectHintInsets = new Rect(insets); } } /** * @return the source rect hint * @hide * @hide */ */ public Rect getSourceRectHint() { public Rect getSourceRectHint() { return mSourceRectHint; return mSourceRectHint; } } /** * @return the source rect hint insets. * @hide */ public Rect getSourceRectHintInsets() { return mSourceRectHintInsets; } /** /** * @return whether there are launch bounds set * @return whether there are launch bounds set * @hide * @hide Loading @@ -182,12 +215,23 @@ public final class PictureInPictureArgs implements Parcelable { return mSourceRectHint != null && !mSourceRectHint.isEmpty(); return mSourceRectHint != null && !mSourceRectHint.isEmpty(); } } /** * @return whether there are source rect hint insets set * @hide */ public boolean hasSourceBoundsHintInsets() { return mSourceRectHintInsets != null; } @Override @Override public PictureInPictureArgs clone() { public PictureInPictureArgs clone() { PictureInPictureArgs args = new PictureInPictureArgs(mAspectRatio, mUserActions); PictureInPictureArgs args = new PictureInPictureArgs(mAspectRatio, mUserActions); if (mSourceRectHint != null) { if (mSourceRectHint != null) { args.setSourceRectHint(mSourceRectHint); args.setSourceRectHint(mSourceRectHint); } } if (mSourceRectHintInsets != null) { args.setSourceRectHintInsets(mSourceRectHintInsets); } return args; return args; } } Loading Loading @@ -216,6 +260,12 @@ public final class PictureInPictureArgs implements Parcelable { } else { } else { out.writeInt(0); out.writeInt(0); } } if (mSourceRectHintInsets != null) { out.writeInt(1); mSourceRectHintInsets.writeToParcel(out, 0); } else { out.writeInt(0); } } } public static final Creator<PictureInPictureArgs> CREATOR = public static final Creator<PictureInPictureArgs> CREATOR = Loading core/java/android/view/ViewRootImpl.java +10 −0 Original line number Original line Diff line number Diff line Loading @@ -1561,6 +1561,16 @@ public final class ViewRootImpl implements ViewParent, host.dispatchApplyWindowInsets(getWindowInsets(true /* forceConstruct */)); host.dispatchApplyWindowInsets(getWindowInsets(true /* forceConstruct */)); } } /** * @return the last content insets for use in adjusting the source hint rect for the * picture-in-picture transition. * * @hide */ public Rect getLastContentInsets() { return mAttachInfo.mContentInsets; } private static boolean shouldUseDisplaySize(final WindowManager.LayoutParams lp) { private static boolean shouldUseDisplaySize(final WindowManager.LayoutParams lp) { return lp.type == TYPE_STATUS_BAR_PANEL return lp.type == TYPE_STATUS_BAR_PANEL || lp.type == TYPE_INPUT_METHOD || lp.type == TYPE_INPUT_METHOD Loading services/core/java/com/android/server/am/ActivityManagerService.java +8 −1 Original line number Original line Diff line number Diff line Loading @@ -7845,7 +7845,14 @@ public class ActivityManagerService extends IActivityManager.Stub r.pictureInPictureArgs.copyOnlySet(args); r.pictureInPictureArgs.copyOnlySet(args); 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(); final Rect sourceBounds = r.pictureInPictureArgs.getSourceRectHint(); // Adjust the source bounds by the insets for the transition down final Rect sourceBounds = new Rect(r.pictureInPictureArgs.getSourceRectHint()); final Rect insets = r.pictureInPictureArgs.getSourceRectHintInsets(); if (insets != null) { sourceBounds.offsetTo(Math.max(0, sourceBounds.left - insets.left), Math.max(0, sourceBounds.top - insets.top)); } mStackSupervisor.moveActivityToPinnedStackLocked(r, sourceBounds, aspectRatio, mStackSupervisor.moveActivityToPinnedStackLocked(r, sourceBounds, aspectRatio, true /* moveHomeStackToFront */, "enterPictureInPictureMode"); true /* moveHomeStackToFront */, "enterPictureInPictureMode"); final PinnedActivityStack stack = mStackSupervisor.getStack(PINNED_STACK_ID); final PinnedActivityStack stack = mStackSupervisor.getStack(PINNED_STACK_ID); Loading
core/java/android/app/Activity.java +17 −0 Original line number Original line Diff line number Diff line Loading @@ -2070,6 +2070,7 @@ public class Activity extends ContextThemeWrapper if (args == null) { if (args == null) { throw new IllegalArgumentException("Expected non-null picture-in-picture args"); throw new IllegalArgumentException("Expected non-null picture-in-picture args"); } } updatePictureInPictureArgsForContentInsets(args); return ActivityManagerNative.getDefault().enterPictureInPictureMode(mToken, args); return ActivityManagerNative.getDefault().enterPictureInPictureMode(mToken, args); } catch (RemoteException e) { } catch (RemoteException e) { return false; return false; Loading @@ -2087,11 +2088,27 @@ public class Activity extends ContextThemeWrapper if (args == null) { if (args == null) { throw new IllegalArgumentException("Expected non-null picture-in-picture args"); throw new IllegalArgumentException("Expected non-null picture-in-picture args"); } } updatePictureInPictureArgsForContentInsets(args); ActivityManagerNative.getDefault().setPictureInPictureArgs(mToken, args); ActivityManagerNative.getDefault().setPictureInPictureArgs(mToken, args); } catch (RemoteException e) { } catch (RemoteException e) { } } } } /** * Updates the provided {@param args} with the last known content insets for this activity, to * be used with the source hint rect for the transition into PiP. */ private void updatePictureInPictureArgsForContentInsets(PictureInPictureArgs args) { if (args != null && args.hasSourceBoundsHint() && getWindow() != null && getWindow().peekDecorView() != null && getWindow().peekDecorView().getViewRootImpl() != null) { args.setSourceRectHintInsets( getWindow().peekDecorView().getViewRootImpl().getLastContentInsets()); } else { args.setSourceRectHintInsets(null); } } void dispatchMovedToDisplay(int displayId, Configuration config) { void dispatchMovedToDisplay(int displayId, Configuration config) { updateDisplay(displayId); updateDisplay(displayId); onMovedToDisplay(displayId, config); onMovedToDisplay(displayId, config); Loading
core/java/android/app/PictureInPictureArgs.java +51 −1 Original line number Original line Diff line number Diff line Loading @@ -49,6 +49,13 @@ public final class PictureInPictureArgs implements Parcelable { @Nullable @Nullable private Rect mSourceRectHint; private Rect mSourceRectHint; /** * The content insets that are used with the source hint rect for the transition into PiP where * the insets are removed at the beginning of the transition. */ @Nullable private Rect mSourceRectHintInsets; PictureInPictureArgs(Parcel in) { PictureInPictureArgs(Parcel in) { if (in.readInt() != 0) { if (in.readInt() != 0) { mAspectRatio = in.readFloat(); mAspectRatio = in.readFloat(); Loading @@ -60,6 +67,9 @@ public final class PictureInPictureArgs implements Parcelable { if (in.readInt() != 0) { if (in.readInt() != 0) { mSourceRectHint = Rect.CREATOR.createFromParcel(in); mSourceRectHint = Rect.CREATOR.createFromParcel(in); } } if (in.readInt() != 0) { mSourceRectHintInsets = Rect.CREATOR.createFromParcel(in); } } } /** /** Loading Loading @@ -94,6 +104,9 @@ public final class PictureInPictureArgs implements Parcelable { if (otherArgs.hasSourceBoundsHint()) { if (otherArgs.hasSourceBoundsHint()) { mSourceRectHint = new Rect(otherArgs.getSourceRectHint()); mSourceRectHint = new Rect(otherArgs.getSourceRectHint()); } } if (otherArgs.hasSourceBoundsHintInsets()) { mSourceRectHintInsets = new Rect(otherArgs.getSourceRectHintInsets()); } } } /** /** Loading Loading @@ -167,13 +180,33 @@ public final class PictureInPictureArgs implements Parcelable { } } /** /** * @return the launch bounds * Sets the insets to be used with the source rect hint bounds. * @hide */ public void setSourceRectHintInsets(Rect insets) { if (insets == null) { mSourceRectHintInsets = null; } else { mSourceRectHintInsets = new Rect(insets); } } /** * @return the source rect hint * @hide * @hide */ */ public Rect getSourceRectHint() { public Rect getSourceRectHint() { return mSourceRectHint; return mSourceRectHint; } } /** * @return the source rect hint insets. * @hide */ public Rect getSourceRectHintInsets() { return mSourceRectHintInsets; } /** /** * @return whether there are launch bounds set * @return whether there are launch bounds set * @hide * @hide Loading @@ -182,12 +215,23 @@ public final class PictureInPictureArgs implements Parcelable { return mSourceRectHint != null && !mSourceRectHint.isEmpty(); return mSourceRectHint != null && !mSourceRectHint.isEmpty(); } } /** * @return whether there are source rect hint insets set * @hide */ public boolean hasSourceBoundsHintInsets() { return mSourceRectHintInsets != null; } @Override @Override public PictureInPictureArgs clone() { public PictureInPictureArgs clone() { PictureInPictureArgs args = new PictureInPictureArgs(mAspectRatio, mUserActions); PictureInPictureArgs args = new PictureInPictureArgs(mAspectRatio, mUserActions); if (mSourceRectHint != null) { if (mSourceRectHint != null) { args.setSourceRectHint(mSourceRectHint); args.setSourceRectHint(mSourceRectHint); } } if (mSourceRectHintInsets != null) { args.setSourceRectHintInsets(mSourceRectHintInsets); } return args; return args; } } Loading Loading @@ -216,6 +260,12 @@ public final class PictureInPictureArgs implements Parcelable { } else { } else { out.writeInt(0); out.writeInt(0); } } if (mSourceRectHintInsets != null) { out.writeInt(1); mSourceRectHintInsets.writeToParcel(out, 0); } else { out.writeInt(0); } } } public static final Creator<PictureInPictureArgs> CREATOR = public static final Creator<PictureInPictureArgs> CREATOR = Loading
core/java/android/view/ViewRootImpl.java +10 −0 Original line number Original line Diff line number Diff line Loading @@ -1561,6 +1561,16 @@ public final class ViewRootImpl implements ViewParent, host.dispatchApplyWindowInsets(getWindowInsets(true /* forceConstruct */)); host.dispatchApplyWindowInsets(getWindowInsets(true /* forceConstruct */)); } } /** * @return the last content insets for use in adjusting the source hint rect for the * picture-in-picture transition. * * @hide */ public Rect getLastContentInsets() { return mAttachInfo.mContentInsets; } private static boolean shouldUseDisplaySize(final WindowManager.LayoutParams lp) { private static boolean shouldUseDisplaySize(final WindowManager.LayoutParams lp) { return lp.type == TYPE_STATUS_BAR_PANEL return lp.type == TYPE_STATUS_BAR_PANEL || lp.type == TYPE_INPUT_METHOD || lp.type == TYPE_INPUT_METHOD Loading
services/core/java/com/android/server/am/ActivityManagerService.java +8 −1 Original line number Original line Diff line number Diff line Loading @@ -7845,7 +7845,14 @@ public class ActivityManagerService extends IActivityManager.Stub r.pictureInPictureArgs.copyOnlySet(args); r.pictureInPictureArgs.copyOnlySet(args); 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(); final Rect sourceBounds = r.pictureInPictureArgs.getSourceRectHint(); // Adjust the source bounds by the insets for the transition down final Rect sourceBounds = new Rect(r.pictureInPictureArgs.getSourceRectHint()); final Rect insets = r.pictureInPictureArgs.getSourceRectHintInsets(); if (insets != null) { sourceBounds.offsetTo(Math.max(0, sourceBounds.left - insets.left), Math.max(0, sourceBounds.top - insets.top)); } mStackSupervisor.moveActivityToPinnedStackLocked(r, sourceBounds, aspectRatio, mStackSupervisor.moveActivityToPinnedStackLocked(r, sourceBounds, aspectRatio, true /* moveHomeStackToFront */, "enterPictureInPictureMode"); true /* moveHomeStackToFront */, "enterPictureInPictureMode"); final PinnedActivityStack stack = mStackSupervisor.getStack(PINNED_STACK_ID); final PinnedActivityStack stack = mStackSupervisor.getStack(PINNED_STACK_ID);