diff --git a/core/api/current.txt b/core/api/current.txt index 08eee0a0556ca..ea3830ff2da06 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -6636,6 +6636,7 @@ package android.app { method public android.app.PictureInPictureParams.Builder setActions(java.util.List); method public android.app.PictureInPictureParams.Builder setAspectRatio(android.util.Rational); method @NonNull public android.app.PictureInPictureParams.Builder setAutoEnterEnabled(boolean); + method @NonNull public android.app.PictureInPictureParams.Builder setExpandedAspectRatio(@Nullable android.util.Rational); method @NonNull public android.app.PictureInPictureParams.Builder setSeamlessResizeEnabled(boolean); method public android.app.PictureInPictureParams.Builder setSourceRectHint(android.graphics.Rect); } @@ -11867,6 +11868,7 @@ package android.content.pm { field public static final String FEATURE_DEVICE_ADMIN = "android.software.device_admin"; field public static final String FEATURE_EMBEDDED = "android.hardware.type.embedded"; field public static final String FEATURE_ETHERNET = "android.hardware.ethernet"; + field public static final String FEATURE_EXPANDED_PICTURE_IN_PICTURE = "android.software.expanded_picture_in_picture"; field public static final String FEATURE_FACE = "android.hardware.biometrics.face"; field public static final String FEATURE_FAKETOUCH = "android.hardware.faketouch"; field public static final String FEATURE_FAKETOUCH_MULTITOUCH_DISTINCT = "android.hardware.faketouch.multitouch.distinct"; diff --git a/core/api/test-current.txt b/core/api/test-current.txt index 336ec3c8dae7e..84b393a06af13 100644 --- a/core/api/test-current.txt +++ b/core/api/test-current.txt @@ -352,6 +352,7 @@ package android.app { public final class PictureInPictureParams implements android.os.Parcelable { method public java.util.List getActions(); method public float getAspectRatio(); + method public float getExpandedAspectRatio(); method public android.graphics.Rect getSourceRectHint(); method public boolean isSeamlessResizeEnabled(); } diff --git a/core/java/android/app/PictureInPictureParams.java b/core/java/android/app/PictureInPictureParams.java index 358ce6a83a21b..18343fddf5d3b 100644 --- a/core/java/android/app/PictureInPictureParams.java +++ b/core/java/android/app/PictureInPictureParams.java @@ -18,7 +18,9 @@ package android.app; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.RequiresFeature; import android.annotation.TestApi; +import android.content.pm.PackageManager; import android.graphics.Rect; import android.os.Parcel; import android.os.Parcelable; @@ -42,6 +44,9 @@ public final class PictureInPictureParams implements Parcelable { @Nullable private Rational mAspectRatio; + @Nullable + private Rational mExpandedAspectRatio; + @Nullable private List mUserActions; @@ -66,6 +71,24 @@ public final class PictureInPictureParams implements Parcelable { return this; } + /** + * Sets the aspect ratio for the expanded picture-in-picture mode. The aspect ratio is + * defined as the desired width / height.
+ * The aspect ratio cannot be changed from horizontal to vertical or vertical to horizontal + * while the PIP is shown. Any such changes will be ignored.
+ * + * Setting the expanded ratio shows the activity's support for expanded mode. + * + * @param expandedAspectRatio must not be between 2.39:1 and 1:2.39 (inclusive). If {@code + * null}, expanded picture-in-picture mode is not supported. + * @return this builder instance. + */ + @RequiresFeature(PackageManager.FEATURE_EXPANDED_PICTURE_IN_PICTURE) + public @NonNull Builder setExpandedAspectRatio(@Nullable Rational expandedAspectRatio) { + mExpandedAspectRatio = expandedAspectRatio; + return this; + } + /** * Sets the user actions. If there are more than * {@link Activity#getMaxNumPictureInPictureActions()} actions, then the input list @@ -152,7 +175,8 @@ public final class PictureInPictureParams implements Parcelable { * @see Activity#setPictureInPictureParams(PictureInPictureParams) */ public PictureInPictureParams build() { - PictureInPictureParams params = new PictureInPictureParams(mAspectRatio, mUserActions, + PictureInPictureParams params = new PictureInPictureParams(mAspectRatio, + mExpandedAspectRatio, mUserActions, mSourceRectHint, mAutoEnterEnabled, mSeamlessResizeEnabled); return params; } @@ -164,6 +188,12 @@ public final class PictureInPictureParams implements Parcelable { @Nullable private Rational mAspectRatio; + /** + * The expected aspect ratio of the vertically expanded picture-in-picture window. + */ + @Nullable + private Rational mExpandedAspectRatio; + /** * The set of actions that are associated with this activity when in picture-in-picture. */ @@ -197,9 +227,8 @@ public final class PictureInPictureParams implements Parcelable { /** {@hide} */ PictureInPictureParams(Parcel in) { - if (in.readInt() != 0) { - mAspectRatio = new Rational(in.readInt(), in.readInt()); - } + mAspectRatio = readRationalFromParcel(in); + mExpandedAspectRatio = readRationalFromParcel(in); if (in.readInt() != 0) { mUserActions = new ArrayList<>(); in.readTypedList(mUserActions, RemoteAction.CREATOR); @@ -216,9 +245,11 @@ public final class PictureInPictureParams implements Parcelable { } /** {@hide} */ - PictureInPictureParams(Rational aspectRatio, List actions, - Rect sourceRectHint, Boolean autoEnterEnabled, Boolean seamlessResizeEnabled) { + PictureInPictureParams(Rational aspectRatio, Rational expandedAspectRatio, + List actions, Rect sourceRectHint, Boolean autoEnterEnabled, + Boolean seamlessResizeEnabled) { mAspectRatio = aspectRatio; + mExpandedAspectRatio = expandedAspectRatio; mUserActions = actions; mSourceRectHint = sourceRectHint; mAutoEnterEnabled = autoEnterEnabled; @@ -230,7 +261,7 @@ public final class PictureInPictureParams implements Parcelable { * @hide */ public PictureInPictureParams(PictureInPictureParams other) { - this(other.mAspectRatio, other.mUserActions, + this(other.mAspectRatio, other.mExpandedAspectRatio, other.mUserActions, other.hasSourceBoundsHint() ? new Rect(other.getSourceRectHint()) : null, other.mAutoEnterEnabled, other.mSeamlessResizeEnabled); } @@ -243,6 +274,10 @@ public final class PictureInPictureParams implements Parcelable { if (otherArgs.hasSetAspectRatio()) { mAspectRatio = otherArgs.mAspectRatio; } + + // Copy either way because null can be used to explicitly unset the value + mExpandedAspectRatio = otherArgs.mExpandedAspectRatio; + if (otherArgs.hasSetActions()) { mUserActions = otherArgs.mUserActions; } @@ -282,6 +317,26 @@ public final class PictureInPictureParams implements Parcelable { return mAspectRatio != null; } + /** + * @return the expanded aspect ratio. If none is set, return 0. + * @hide + */ + @TestApi + public float getExpandedAspectRatio() { + if (mExpandedAspectRatio != null) { + return mExpandedAspectRatio.floatValue(); + } + return 0f; + } + + /** + * @return whether the expanded aspect ratio is set + * @hide + */ + public boolean hasSetExpandedAspectRatio() { + return mExpandedAspectRatio != null; + } + /** * @return the set of user actions. * @hide @@ -349,7 +404,8 @@ public final class PictureInPictureParams implements Parcelable { */ public boolean empty() { return !hasSourceBoundsHint() && !hasSetActions() && !hasSetAspectRatio() - && mAutoEnterEnabled != null && mSeamlessResizeEnabled != null; + && !hasSetExpandedAspectRatio() && mAutoEnterEnabled != null + && mSeamlessResizeEnabled != null; } @Override @@ -360,13 +416,14 @@ public final class PictureInPictureParams implements Parcelable { return Objects.equals(mAutoEnterEnabled, that.mAutoEnterEnabled) && Objects.equals(mSeamlessResizeEnabled, that.mSeamlessResizeEnabled) && Objects.equals(mAspectRatio, that.mAspectRatio) + && Objects.equals(mExpandedAspectRatio, that.mExpandedAspectRatio) && Objects.equals(mUserActions, that.mUserActions) && Objects.equals(mSourceRectHint, that.mSourceRectHint); } @Override public int hashCode() { - return Objects.hash(mAspectRatio, mUserActions, mSourceRectHint, + return Objects.hash(mAspectRatio, mExpandedAspectRatio, mUserActions, mSourceRectHint, mAutoEnterEnabled, mSeamlessResizeEnabled); } @@ -377,13 +434,8 @@ public final class PictureInPictureParams implements Parcelable { @Override public void writeToParcel(Parcel out, int flags) { - if (mAspectRatio != null) { - out.writeInt(1); - out.writeInt(mAspectRatio.getNumerator()); - out.writeInt(mAspectRatio.getDenominator()); - } else { - out.writeInt(0); - } + writeRationalToParcel(mAspectRatio, out); + writeRationalToParcel(mExpandedAspectRatio, out); if (mUserActions != null) { out.writeInt(1); out.writeTypedList(mUserActions, 0); @@ -410,10 +462,28 @@ public final class PictureInPictureParams implements Parcelable { } } + private void writeRationalToParcel(Rational rational, Parcel out) { + if (rational != null) { + out.writeInt(1); + out.writeInt(rational.getNumerator()); + out.writeInt(rational.getDenominator()); + } else { + out.writeInt(0); + } + } + + private Rational readRationalFromParcel(Parcel in) { + if (in.readInt() != 0) { + return new Rational(in.readInt(), in.readInt()); + } + return null; + } + @Override public String toString() { return "PictureInPictureParams(" + " aspectRatio=" + getAspectRatioRational() + + " expandedAspectRatio=" + mExpandedAspectRatio + " sourceRectHint=" + getSourceRectHint() + " hasSetActions=" + hasSetActions() + " isAutoPipEnabled=" + isAutoEnterEnabled() diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java index 4279d077cebf9..dc79ee6b09e22 100644 --- a/core/java/android/content/pm/PackageManager.java +++ b/core/java/android/content/pm/PackageManager.java @@ -3795,6 +3795,16 @@ public abstract class PackageManager { @SdkConstant(SdkConstantType.FEATURE) public static final String FEATURE_PICTURE_IN_PICTURE = "android.software.picture_in_picture"; + /** + * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: + * The device supports expanded picture-in-picture multi-window mode. + * + * @see android.app.PictureInPictureParams.Builder#setExpandedAspectRatio + */ + @SdkConstant(SdkConstantType.FEATURE) + public static final String FEATURE_EXPANDED_PICTURE_IN_PICTURE + = "android.software.expanded_picture_in_picture"; + /** * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: * The device supports running activities on secondary displays.