From ce21971ecf53821b62e4678572747272d17d7669 Mon Sep 17 00:00:00 2001 From: Hongwei Wang Date: Thu, 9 Jun 2022 12:01:07 -0700 Subject: [PATCH] Add flag to explicitly set setCanAffectSystemUiFlags Within the PictureInPictureSurfaceTransaction class, one can explicitly express the intention to call Task#setCanAffectSystemUiFlags(false) and it is typically used if an Activity is entering PiP. Video: http://recall/-/b1EZhgUkQcpML5OwZekLBN/dlG6qSf9pT2f4YlIe2Klb3 Video: http://recall/-/b1EZhgUkQcpML5OwZekLBN/cfXwlpol5vi2AER32rKu2x Bug: 213598210 Test: 1. follow the reproduce steps in the bug. \ 2. make sure PiP from split-screen has no regressions. \ see also the videos. Change-Id: I7c4624a89ff812f874270fe0092617328b557393 --- .../PictureInPictureSurfaceTransaction.java | 23 +++++++++++++++++-- .../server/wm/RecentsAnimationController.java | 14 +++++------ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/core/java/android/window/PictureInPictureSurfaceTransaction.java b/core/java/android/window/PictureInPictureSurfaceTransaction.java index 0a751c38cfff4..3b1fdf5e4c385 100644 --- a/core/java/android/window/PictureInPictureSurfaceTransaction.java +++ b/core/java/android/window/PictureInPictureSurfaceTransaction.java @@ -51,6 +51,8 @@ public final class PictureInPictureSurfaceTransaction implements Parcelable { private final Rect mWindowCrop; + private boolean mShouldDisableCanAffectSystemUiFlags; + private PictureInPictureSurfaceTransaction(Parcel in) { mAlpha = in.readFloat(); mPosition = in.readTypedObject(PointF.CREATOR); @@ -60,6 +62,7 @@ public final class PictureInPictureSurfaceTransaction implements Parcelable { mCornerRadius = in.readFloat(); mShadowRadius = in.readFloat(); mWindowCrop = in.readTypedObject(Rect.CREATOR); + mShouldDisableCanAffectSystemUiFlags = in.readBoolean(); } private PictureInPictureSurfaceTransaction(float alpha, @Nullable PointF position, @@ -84,6 +87,7 @@ public final class PictureInPictureSurfaceTransaction implements Parcelable { this(other.mAlpha, other.mPosition, other.mFloat9, other.mRotation, other.mCornerRadius, other.mShadowRadius, other.mWindowCrop); + mShouldDisableCanAffectSystemUiFlags = other.mShouldDisableCanAffectSystemUiFlags; } /** @return {@link Matrix} from {@link #mFloat9} */ @@ -103,6 +107,16 @@ public final class PictureInPictureSurfaceTransaction implements Parcelable { return mShadowRadius > 0; } + /** Sets the internal {@link #mShouldDisableCanAffectSystemUiFlags}. */ + public void setShouldDisableCanAffectSystemUiFlags(boolean shouldDisable) { + mShouldDisableCanAffectSystemUiFlags = shouldDisable; + } + + /** @return {@code true} if we should disable Task#setCanAffectSystemUiFlags. */ + public boolean getShouldDisableCanAffectSystemUiFlags() { + return mShouldDisableCanAffectSystemUiFlags; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -114,13 +128,16 @@ public final class PictureInPictureSurfaceTransaction implements Parcelable { && Objects.equals(mRotation, that.mRotation) && Objects.equals(mCornerRadius, that.mCornerRadius) && Objects.equals(mShadowRadius, that.mShadowRadius) - && Objects.equals(mWindowCrop, that.mWindowCrop); + && Objects.equals(mWindowCrop, that.mWindowCrop) + && mShouldDisableCanAffectSystemUiFlags + == that.mShouldDisableCanAffectSystemUiFlags; } @Override public int hashCode() { return Objects.hash(mAlpha, mPosition, Arrays.hashCode(mFloat9), - mRotation, mCornerRadius, mShadowRadius, mWindowCrop); + mRotation, mCornerRadius, mShadowRadius, mWindowCrop, + mShouldDisableCanAffectSystemUiFlags); } @Override @@ -137,6 +154,7 @@ public final class PictureInPictureSurfaceTransaction implements Parcelable { out.writeFloat(mCornerRadius); out.writeFloat(mShadowRadius); out.writeTypedObject(mWindowCrop, 0 /* flags */); + out.writeBoolean(mShouldDisableCanAffectSystemUiFlags); } @Override @@ -150,6 +168,7 @@ public final class PictureInPictureSurfaceTransaction implements Parcelable { + " cornerRadius=" + mCornerRadius + " shadowRadius=" + mShadowRadius + " crop=" + mWindowCrop + + " shouldDisableCanAffectSystemUiFlags" + mShouldDisableCanAffectSystemUiFlags + ")"; } diff --git a/services/core/java/com/android/server/wm/RecentsAnimationController.java b/services/core/java/com/android/server/wm/RecentsAnimationController.java index fe0ab2b399097..d2ce048ca88f9 100644 --- a/services/core/java/com/android/server/wm/RecentsAnimationController.java +++ b/services/core/java/com/android/server/wm/RecentsAnimationController.java @@ -1335,16 +1335,16 @@ public class RecentsAnimationController implements DeathRecipient { mDisplayContent.mPinnedTaskController.setEnterPipTransaction( mFinishTransaction); } + // In the case where we are transferring the transform to the task in preparation + // for entering PIP, we disable the task being able to affect sysui flags otherwise + // it may cause a flash + if (mTask.getActivityType() != mTargetActivityType + && mFinishTransaction.getShouldDisableCanAffectSystemUiFlags()) { + mTask.setCanAffectSystemUiFlags(false); + } mFinishTransaction = null; mFinishOverlay = null; pendingTransaction.apply(); - - // In the case where we are transferring the transform to the task in preparation - // for entering PIP, we disable the task being able to affect sysui flags otherwise - // it may cause a flash - if (mTask.getActivityType() != mTargetActivityType) { - mTask.setCanAffectSystemUiFlags(false); - } } else if (!mTask.isAttached()) { // Apply the task's pending transaction in case it is detached and its transaction // is not reachable.