diff options
| author | Wale Ogunwale <ogunwale@google.com> | 2020-08-11 18:42:28 -0700 |
|---|---|---|
| committer | jorgegil@google.com <jorgegil@google.com> | 2020-09-02 11:29:23 -0700 |
| commit | 9db724816cf2da731379a90fff66b86c3c225886 (patch) | |
| tree | cc7919302282db240a8e9db56ceeb8e8189101ef /core/java/android | |
| parent | ae5e71786ee53b60b97104e740e0327d298cd4c6 (diff) | |
Add support for explicit Auto Pip
Adds a new parameter to PictureInPictureParams that
allows activities to explicitly allow the system to
put them in PIP mode without them having to call
enterPictureInPictureMode().
Test: atest PinnedStackTests#testAutoPipAllowedBypassesExplicitEnterPip
Bug: 163048957
Change-Id: Ib6fda0e231408f2756a4e1b9fda08536889a1be5
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/app/PictureInPictureParams.java | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/core/java/android/app/PictureInPictureParams.java b/core/java/android/app/PictureInPictureParams.java index 67d94dec88c5..18c4d70dd9b0 100644 --- a/core/java/android/app/PictureInPictureParams.java +++ b/core/java/android/app/PictureInPictureParams.java @@ -16,6 +16,7 @@ package android.app; +import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.TestApi; import android.graphics.Rect; @@ -46,6 +47,8 @@ public final class PictureInPictureParams implements Parcelable { @Nullable private Rect mSourceRectHint; + private boolean mAutoEnterAllowed; + /** * Sets the aspect ratio. This aspect ratio is defined as the desired width / height, and * does not change upon device rotation. @@ -103,6 +106,25 @@ public final class PictureInPictureParams implements Parcelable { } /** + * Sets whether the system is allowed to automatically put the activity in + * picture-in-picture mode without needing/waiting for the activity to call + * {@link Activity#enterPictureInPictureMode(PictureInPictureParams)}. + * + * If true, {@link Activity#onPictureInPictureRequested()} will never be called. + * + * This property is false by default. + * @param autoEnterAllowed {@code true} if the system is allowed to automatically put the + * activity in picture-in-picture mode. + * + * @return this builder instance. + */ + @NonNull + public Builder setAutoEnterAllowed(boolean autoEnterAllowed) { + mAutoEnterAllowed = autoEnterAllowed; + return this; + } + + /** * @return an immutable {@link PictureInPictureParams} to be used when entering or updating * the activity in picture-in-picture. * @@ -111,7 +133,7 @@ public final class PictureInPictureParams implements Parcelable { */ public PictureInPictureParams build() { PictureInPictureParams params = new PictureInPictureParams(mAspectRatio, mUserActions, - mSourceRectHint); + mSourceRectHint, mAutoEnterAllowed); return params; } } @@ -136,6 +158,11 @@ public final class PictureInPictureParams implements Parcelable { @Nullable private Rect mSourceRectHint; + /** + * Whether the system is allowed to automatically put the activity in picture-in-picture mode. + */ + private boolean mAutoEnterAllowed; + /** {@hide} */ PictureInPictureParams() { } @@ -152,14 +179,18 @@ public final class PictureInPictureParams implements Parcelable { if (in.readInt() != 0) { mSourceRectHint = Rect.CREATOR.createFromParcel(in); } + if (in.readInt() != 0) { + mAutoEnterAllowed = in.readBoolean(); + } } /** {@hide} */ PictureInPictureParams(Rational aspectRatio, List<RemoteAction> actions, - Rect sourceRectHint) { + Rect sourceRectHint, boolean autoEnterAllowed) { mAspectRatio = aspectRatio; mUserActions = actions; mSourceRectHint = sourceRectHint; + mAutoEnterAllowed = autoEnterAllowed; } /** @@ -176,6 +207,7 @@ public final class PictureInPictureParams implements Parcelable { if (otherArgs.hasSourceBoundsHint()) { mSourceRectHint = new Rect(otherArgs.getSourceRectHint()); } + mAutoEnterAllowed = otherArgs.mAutoEnterAllowed; } /** @@ -248,11 +280,20 @@ public final class PictureInPictureParams implements Parcelable { } /** + * @return whether auto pip allowed. + * @hide + */ + public boolean isAutoEnterAllowed() { + return mAutoEnterAllowed; + } + + /** * @return True if no parameters are set * @hide */ public boolean empty() { - return !hasSourceBoundsHint() && !hasSetActions() && !hasSetAspectRatio(); + return !hasSourceBoundsHint() && !hasSetActions() && !hasSetAspectRatio() + && !mAutoEnterAllowed; } @Override @@ -281,6 +322,8 @@ public final class PictureInPictureParams implements Parcelable { } else { out.writeInt(0); } + out.writeInt(1); + out.writeBoolean(mAutoEnterAllowed); } public static final @android.annotation.NonNull Creator<PictureInPictureParams> CREATOR = |
