Add API to differentiate PiP content
Added PictureInPictureParams.Builder#setSeamlessResizeEnabled that app
can specify its resize capability. For backward compatibility, this is
default to true and when it's set to false, SystemUI can perform
transition to overcome the artifacts due to resize.
Also included in this change, the primitives like mAutoEnterEnabled and
mSeamlessResizeEnabled would be problematic with the following patterns
from an Activity
```
PicureInPictureParams.Builder builder = new PictureInPictureParams.Builder();
builder.setAutoEnterEnabled(true);
setPictureInPictureParams(builder.build());
enterPictureInPictureMode();
```
with the code snippet above, the PictureInPictureParams#copyOnlySet will
override the mAutoEnterEnabled to false. Fixed by switching the
primitive to Boolean object.
Bug: 175052991
Test: atest PinnedStackTests
Change-Id: I4d52f59b49dcbb8998ed74237bdba93c0ad139e4
diff --git a/core/api/current.txt b/core/api/current.txt
index cf73689..471f4c9 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -6216,6 +6216,7 @@
method public android.app.PictureInPictureParams.Builder setActions(java.util.List<android.app.RemoteAction>);
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 setSeamlessResizeEnabled(boolean);
method public android.app.PictureInPictureParams.Builder setSourceRectHint(android.graphics.Rect);
}
diff --git a/core/api/test-current.txt b/core/api/test-current.txt
index 1253197..d2941c3 100644
--- a/core/api/test-current.txt
+++ b/core/api/test-current.txt
@@ -283,6 +283,7 @@
method public java.util.List<android.app.RemoteAction> getActions();
method public float getAspectRatio();
method public android.graphics.Rect getSourceRectHint();
+ method public boolean isSeamlessResizeEnabled();
}
public class StatusBarManager {
diff --git a/core/java/android/app/PictureInPictureParams.java b/core/java/android/app/PictureInPictureParams.java
index 29c9c67..ea7eab2 100644
--- a/core/java/android/app/PictureInPictureParams.java
+++ b/core/java/android/app/PictureInPictureParams.java
@@ -48,7 +48,9 @@
@Nullable
private Rect mSourceRectHint;
- private boolean mAutoEnterEnabled;
+ private Boolean mAutoEnterEnabled;
+
+ private Boolean mSeamlessResizeEnabled;
/**
* Sets the aspect ratio. This aspect ratio is defined as the desired width / height, and
@@ -113,7 +115,7 @@
*
* If true, {@link Activity#onPictureInPictureRequested()} will never be called.
*
- * This property is false by default.
+ * This property is {@code false} by default.
* @param autoEnterEnabled {@code true} if the system will automatically put the activity
* in picture-in-picture mode.
*
@@ -126,6 +128,23 @@
}
/**
+ * Sets whether the system can seamlessly resize the window while the activity is in
+ * picture-in-picture mode. This should normally be the case for video content and
+ * when it's set to {@code false}, system will perform transitions to overcome the
+ * artifacts due to resize.
+ *
+ * This property is {@code true} by default for backwards compatibility.
+ * @param seamlessResizeEnabled {@code true} if the system can seamlessly resize the window
+ * while activity is in picture-in-picture mode.
+ * @return this builder instance.
+ */
+ @NonNull
+ public Builder setSeamlessResizeEnabled(boolean seamlessResizeEnabled) {
+ mSeamlessResizeEnabled = seamlessResizeEnabled;
+ return this;
+ }
+
+ /**
* @return an immutable {@link PictureInPictureParams} to be used when entering or updating
* the activity in picture-in-picture.
*
@@ -134,7 +153,7 @@
*/
public PictureInPictureParams build() {
PictureInPictureParams params = new PictureInPictureParams(mAspectRatio, mUserActions,
- mSourceRectHint, mAutoEnterEnabled);
+ mSourceRectHint, mAutoEnterEnabled, mSeamlessResizeEnabled);
return params;
}
}
@@ -161,8 +180,16 @@
/**
* Whether the system is allowed to automatically put the activity in picture-in-picture mode.
+ * {@link #isAutoEnterEnabled()} defaults to {@code false} if this is not set.
*/
- private boolean mAutoEnterEnabled;
+ private Boolean mAutoEnterEnabled;
+
+ /**
+ * Whether system can seamlessly resize the window when activity is in picture-in-picture mode.
+ * {@link #isSeamlessResizeEnabled()} defaults to {@code true} if this is not set for
+ * backwards compatibility.
+ */
+ private Boolean mSeamlessResizeEnabled;
/** {@hide} */
PictureInPictureParams() {
@@ -183,15 +210,19 @@
if (in.readInt() != 0) {
mAutoEnterEnabled = in.readBoolean();
}
+ if (in.readInt() != 0) {
+ mSeamlessResizeEnabled = in.readBoolean();
+ }
}
/** {@hide} */
PictureInPictureParams(Rational aspectRatio, List<RemoteAction> actions,
- Rect sourceRectHint, boolean autoEnterEnabled) {
+ Rect sourceRectHint, Boolean autoEnterEnabled, Boolean seamlessResizeEnabled) {
mAspectRatio = aspectRatio;
mUserActions = actions;
mSourceRectHint = sourceRectHint;
mAutoEnterEnabled = autoEnterEnabled;
+ mSeamlessResizeEnabled = seamlessResizeEnabled;
}
/**
@@ -201,7 +232,7 @@
public PictureInPictureParams(PictureInPictureParams other) {
this(other.mAspectRatio, other.mUserActions,
other.hasSourceBoundsHint() ? new Rect(other.getSourceRectHint()) : null,
- other.mAutoEnterEnabled);
+ other.mAutoEnterEnabled, other.mSeamlessResizeEnabled);
}
/**
@@ -218,7 +249,12 @@
if (otherArgs.hasSourceBoundsHint()) {
mSourceRectHint = new Rect(otherArgs.getSourceRectHint());
}
- mAutoEnterEnabled = otherArgs.mAutoEnterEnabled;
+ if (otherArgs.mAutoEnterEnabled != null) {
+ mAutoEnterEnabled = otherArgs.mAutoEnterEnabled;
+ }
+ if (otherArgs.mSeamlessResizeEnabled != null) {
+ mSeamlessResizeEnabled = otherArgs.mSeamlessResizeEnabled;
+ }
}
/**
@@ -295,7 +331,16 @@
* @hide
*/
public boolean isAutoEnterEnabled() {
- return mAutoEnterEnabled;
+ return mAutoEnterEnabled == null ? false : mAutoEnterEnabled;
+ }
+
+ /**
+ * @return whether seamless resize is enabled.
+ * @hide
+ */
+ @TestApi
+ public boolean isSeamlessResizeEnabled() {
+ return mSeamlessResizeEnabled == null ? true : mSeamlessResizeEnabled;
}
/**
@@ -304,7 +349,7 @@
*/
public boolean empty() {
return !hasSourceBoundsHint() && !hasSetActions() && !hasSetAspectRatio()
- && !mAutoEnterEnabled;
+ && mAutoEnterEnabled != null && mSeamlessResizeEnabled != null;
}
@Override
@@ -312,7 +357,8 @@
if (this == o) return true;
if (!(o instanceof PictureInPictureParams)) return false;
PictureInPictureParams that = (PictureInPictureParams) o;
- return mAutoEnterEnabled == that.mAutoEnterEnabled
+ return Objects.equals(mAutoEnterEnabled, that.mAutoEnterEnabled)
+ && Objects.equals(mSeamlessResizeEnabled, that.mSeamlessResizeEnabled)
&& Objects.equals(mAspectRatio, that.mAspectRatio)
&& Objects.equals(mUserActions, that.mUserActions)
&& Objects.equals(mSourceRectHint, that.mSourceRectHint);
@@ -320,7 +366,8 @@
@Override
public int hashCode() {
- return Objects.hash(mAspectRatio, mUserActions, mSourceRectHint, mAutoEnterEnabled);
+ return Objects.hash(mAspectRatio, mUserActions, mSourceRectHint,
+ mAutoEnterEnabled, mSeamlessResizeEnabled);
}
@Override
@@ -349,8 +396,18 @@
} else {
out.writeInt(0);
}
- out.writeInt(1);
- out.writeBoolean(mAutoEnterEnabled);
+ if (mAutoEnterEnabled != null) {
+ out.writeInt(1);
+ out.writeBoolean(mAutoEnterEnabled);
+ } else {
+ out.writeInt(0);
+ }
+ if (mSeamlessResizeEnabled != null) {
+ out.writeInt(1);
+ out.writeBoolean(mSeamlessResizeEnabled);
+ } else {
+ out.writeInt(0);
+ }
}
@Override
@@ -360,6 +417,7 @@
+ " sourceRectHint=" + getSourceRectHint()
+ " hasSetActions=" + hasSetActions()
+ " isAutoPipEnabled=" + isAutoEnterEnabled()
+ + " isSeamlessResizeEnabled=" + isSeamlessResizeEnabled()
+ ")";
}