Add rounded corners attribute to window animations
Windows now can have rounded corners that match the display shape,
this CL introduces a new xml attribute called hasRoundedCorners that
enables this feature when declared on an animation xml.
Bug: 111514493
Test: winscope
Test: atest WindowAnimationSpecTest
Change-Id: Ie7651bab00c6e9e0ab7ab50cdb14142c8b2b954b
diff --git a/core/java/android/view/animation/Animation.java b/core/java/android/view/animation/Animation.java
index e095094..3b60aee 100644
--- a/core/java/android/view/animation/Animation.java
+++ b/core/java/android/view/animation/Animation.java
@@ -207,6 +207,7 @@
private float mScaleFactor = 1f;
private boolean mShowWallpaper;
+ private boolean mHasRoundedCorners;
private boolean mMore = true;
private boolean mOneMoreTime = true;
@@ -263,6 +264,8 @@
a.getBoolean(com.android.internal.R.styleable.Animation_detachWallpaper, false));
setShowWallpaper(
a.getBoolean(com.android.internal.R.styleable.Animation_showWallpaper, false));
+ setHasRoundedCorners(
+ a.getBoolean(com.android.internal.R.styleable.Animation_hasRoundedCorners, false));
final int resID = a.getResourceId(com.android.internal.R.styleable.Animation_interpolator, 0);
@@ -678,6 +681,19 @@
}
/**
+ * If this is a window animation, the window will have rounded corners matching the display
+ * corner radius.
+ *
+ * @param hasRoundedCorners Whether the window should have rounded corners or not.
+ * @attr ref android.R.styleable#Animation_hasRoundedCorners
+ * @see com.android.internal.policy.ScreenDecorationsUtils#getWindowCornerRadius(Resources)
+ * @hide
+ */
+ public void setHasRoundedCorners(boolean hasRoundedCorners) {
+ mHasRoundedCorners = hasRoundedCorners;
+ }
+
+ /**
* Gets the acceleration curve type for this animation.
*
* @return the {@link Interpolator} associated to this animation
@@ -804,6 +820,16 @@
}
/**
+ * @return if a window animation should have rounded corners or not.
+ *
+ * @attr ref android.R.styleable#Animation_hasRoundedCorners
+ * @hide
+ */
+ public boolean hasRoundedCorners() {
+ return mHasRoundedCorners;
+ }
+
+ /**
* <p>Indicates whether or not this animation will affect the transformation
* matrix. For instance, a fade animation will not affect the matrix whereas
* a scale animation will.</p>
diff --git a/core/res/res/anim-ldrtl/cross_profile_apps_thumbnail_enter.xml b/core/res/res/anim-ldrtl/cross_profile_apps_thumbnail_enter.xml
index 6f3dc8c..5add19b 100644
--- a/core/res/res/anim-ldrtl/cross_profile_apps_thumbnail_enter.xml
+++ b/core/res/res/anim-ldrtl/cross_profile_apps_thumbnail_enter.xml
@@ -18,7 +18,9 @@
-->
<!-- This should be kept in sync with task_open_enter.xml -->
<set xmlns:android="http://schemas.android.com/apk/res/android"
- android:shareInterpolator="false" android:zAdjustment="top">
+ android:hasRoundedCorners="true"
+ android:shareInterpolator="false"
+ android:zAdjustment="top">
<alpha
android:fromAlpha="1"
diff --git a/core/res/res/anim-ldrtl/task_close_enter.xml b/core/res/res/anim-ldrtl/task_close_enter.xml
index 7abada3..e00141a 100644
--- a/core/res/res/anim-ldrtl/task_close_enter.xml
+++ b/core/res/res/anim-ldrtl/task_close_enter.xml
@@ -16,6 +16,7 @@
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
android:zAdjustment="top"
+ android:hasRoundedCorners="true"
android:showWallpaper="true">
<alpha
diff --git a/core/res/res/anim-ldrtl/task_close_exit.xml b/core/res/res/anim-ldrtl/task_close_exit.xml
index a017820..71a44ae 100644
--- a/core/res/res/anim-ldrtl/task_close_exit.xml
+++ b/core/res/res/anim-ldrtl/task_close_exit.xml
@@ -16,6 +16,7 @@
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
+ android:hasRoundedCorners="true"
android:showWallpaper="true">
<alpha
diff --git a/core/res/res/anim-ldrtl/task_open_enter.xml b/core/res/res/anim-ldrtl/task_open_enter.xml
index 0433664..7815f7d 100644
--- a/core/res/res/anim-ldrtl/task_open_enter.xml
+++ b/core/res/res/anim-ldrtl/task_open_enter.xml
@@ -18,6 +18,7 @@
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
android:zAdjustment="top"
+ android:hasRoundedCorners="true"
android:showWallpaper="true">
<alpha
diff --git a/core/res/res/anim-ldrtl/task_open_enter_cross_profile_apps.xml b/core/res/res/anim-ldrtl/task_open_enter_cross_profile_apps.xml
index 45ca80e..5fccd6df 100644
--- a/core/res/res/anim-ldrtl/task_open_enter_cross_profile_apps.xml
+++ b/core/res/res/anim-ldrtl/task_open_enter_cross_profile_apps.xml
@@ -18,6 +18,7 @@
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
android:zAdjustment="top"
+ android:hasRoundedCorners="true"
android:showWallpaper="true">
<alpha
diff --git a/core/res/res/anim-ldrtl/task_open_exit.xml b/core/res/res/anim-ldrtl/task_open_exit.xml
index f50494d..025e1bd 100644
--- a/core/res/res/anim-ldrtl/task_open_exit.xml
+++ b/core/res/res/anim-ldrtl/task_open_exit.xml
@@ -16,6 +16,7 @@
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
+ android:hasRoundedCorners="true"
android:showWallpaper="true">
<alpha
diff --git a/core/res/res/anim/cross_profile_apps_thumbnail_enter.xml b/core/res/res/anim/cross_profile_apps_thumbnail_enter.xml
index 4c2559f..2cfeecf 100644
--- a/core/res/res/anim/cross_profile_apps_thumbnail_enter.xml
+++ b/core/res/res/anim/cross_profile_apps_thumbnail_enter.xml
@@ -18,7 +18,9 @@
-->
<!-- This should be kept in sync with task_open_enter.xml -->
<set xmlns:android="http://schemas.android.com/apk/res/android"
- android:shareInterpolator="false" android:zAdjustment="top">
+ android:shareInterpolator="false"
+ android:hasRoundedCorners="true"
+ android:zAdjustment="top">
<alpha
android:fromAlpha="1"
diff --git a/core/res/res/anim/task_close_enter.xml b/core/res/res/anim/task_close_enter.xml
index b059aa9..487ff5c 100644
--- a/core/res/res/anim/task_close_enter.xml
+++ b/core/res/res/anim/task_close_enter.xml
@@ -18,6 +18,7 @@
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
android:zAdjustment="top"
+ android:hasRoundedCorners="true"
android:showWallpaper="true">
<alpha
diff --git a/core/res/res/anim/task_close_exit.xml b/core/res/res/anim/task_close_exit.xml
index c9ade22..afc3256c 100644
--- a/core/res/res/anim/task_close_exit.xml
+++ b/core/res/res/anim/task_close_exit.xml
@@ -18,6 +18,7 @@
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
+ android:hasRoundedCorners="true"
android:showWallpaper="true">
<alpha
diff --git a/core/res/res/anim/task_open_enter.xml b/core/res/res/anim/task_open_enter.xml
index 5c61859..0aafc1c 100644
--- a/core/res/res/anim/task_open_enter.xml
+++ b/core/res/res/anim/task_open_enter.xml
@@ -20,6 +20,7 @@
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
android:zAdjustment="top"
+ android:hasRoundedCorners="true"
android:showWallpaper="true">
<alpha
diff --git a/core/res/res/anim/task_open_enter_cross_profile_apps.xml b/core/res/res/anim/task_open_enter_cross_profile_apps.xml
index 6441047..702f7ba 100644
--- a/core/res/res/anim/task_open_enter_cross_profile_apps.xml
+++ b/core/res/res/anim/task_open_enter_cross_profile_apps.xml
@@ -20,6 +20,7 @@
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
android:zAdjustment="top"
+ android:hasRoundedCorners="true"
android:showWallpaper="true">
<alpha
diff --git a/core/res/res/anim/task_open_exit.xml b/core/res/res/anim/task_open_exit.xml
index 9394c57..691317d 100644
--- a/core/res/res/anim/task_open_exit.xml
+++ b/core/res/res/anim/task_open_exit.xml
@@ -18,6 +18,7 @@
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
+ android:hasRoundedCorners="true"
android:showWallpaper="true">
<alpha
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 088669d..743496f 100644
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -6488,6 +6488,9 @@
<!-- Special option for window animations: show the wallpaper behind when running this
animation. -->
<attr name="showWallpaper" format="boolean" />
+ <!-- Special option for window animations: whether window should have rounded corners.
+ @see ScreenDecorationsUtils#getWindowCornerRadius(Resources) -->
+ <attr name="hasRoundedCorners" format="boolean" />
</declare-styleable>
<declare-styleable name="AnimationSet">
diff --git a/services/core/java/com/android/server/wm/AppWindowThumbnail.java b/services/core/java/com/android/server/wm/AppWindowThumbnail.java
index 5519729..bbbf11d 100644
--- a/services/core/java/com/android/server/wm/AppWindowThumbnail.java
+++ b/services/core/java/com/android/server/wm/AppWindowThumbnail.java
@@ -118,7 +118,8 @@
anim.scaleCurrentDuration(mAppToken.mWmService.getTransitionAnimationScaleLocked());
mSurfaceAnimator.startAnimation(t, new LocalAnimationAdapter(
new WindowAnimationSpec(anim, position,
- mAppToken.getDisplayContent().mAppTransition.canSkipFirstFrame()),
+ mAppToken.getDisplayContent().mAppTransition.canSkipFirstFrame(),
+ mAppToken.mWmService.mWindowCornerRadius),
mAppToken.mWmService.mSurfaceAnimationRunner), false /* hidden */);
}
diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java
index 88c8b95..f5592e0 100644
--- a/services/core/java/com/android/server/wm/AppWindowToken.java
+++ b/services/core/java/com/android/server/wm/AppWindowToken.java
@@ -2526,7 +2526,8 @@
new WindowAnimationSpec(a, mTmpPoint, mTmpRect,
getDisplayContent().mAppTransition.canSkipFirstFrame(),
appStackClipMode,
- true /* isAppAnimation */),
+ true /* isAppAnimation */,
+ mWmService.mWindowCornerRadius),
mWmService.mSurfaceAnimationRunner);
if (a.getZAdjustment() == Animation.ZORDER_TOP) {
mNeedsZBoost = true;
diff --git a/services/core/java/com/android/server/wm/WindowAnimationSpec.java b/services/core/java/com/android/server/wm/WindowAnimationSpec.java
index 98c77ac..57311e1 100644
--- a/services/core/java/com/android/server/wm/WindowAnimationSpec.java
+++ b/services/core/java/com/android/server/wm/WindowAnimationSpec.java
@@ -17,10 +17,10 @@
package com.android.server.wm;
import static com.android.server.wm.AnimationAdapter.STATUS_BAR_TRANSITION_DURATION;
-import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM;
-import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
import static com.android.server.wm.AnimationSpecProto.WINDOW;
import static com.android.server.wm.WindowAnimationSpecProto.ANIMATION;
+import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM;
+import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
import android.graphics.Point;
import android.graphics.Rect;
@@ -51,18 +51,22 @@
private final Rect mStackBounds = new Rect();
private int mStackClipMode;
private final Rect mTmpRect = new Rect();
+ private final float mWindowCornerRadius;
- public WindowAnimationSpec(Animation animation, Point position, boolean canSkipFirstFrame) {
+ public WindowAnimationSpec(Animation animation, Point position, boolean canSkipFirstFrame,
+ float windowCornerRadius) {
this(animation, position, null /* stackBounds */, canSkipFirstFrame, STACK_CLIP_NONE,
- false /* isAppAnimation */);
+ false /* isAppAnimation */, windowCornerRadius);
}
public WindowAnimationSpec(Animation animation, Point position, Rect stackBounds,
- boolean canSkipFirstFrame, int stackClipMode, boolean isAppAnimation) {
+ boolean canSkipFirstFrame, int stackClipMode, boolean isAppAnimation,
+ float windowCornerRadius) {
mAnimation = animation;
if (position != null) {
mPosition.set(position.x, position.y);
}
+ mWindowCornerRadius = windowCornerRadius;
mCanSkipFirstFrame = canSkipFirstFrame;
mIsAppAnimation = isAppAnimation;
mStackClipMode = stackClipMode;
@@ -101,6 +105,9 @@
mTmpRect.intersect(tmp.transformation.getClipRect());
t.setWindowCrop(leash, mTmpRect);
}
+ if (mAnimation.hasRoundedCorners() && mWindowCornerRadius > 0) {
+ t.setCornerRadius(leash, mWindowCornerRadius);
+ }
}
@Override
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index e19c7c6..aa4f54f 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -234,6 +234,7 @@
import com.android.internal.os.IResultReceiver;
import com.android.internal.policy.IKeyguardDismissCallback;
import com.android.internal.policy.IShortcutService;
+import com.android.internal.policy.ScreenDecorationsUtils;
import com.android.internal.util.DumpUtils;
import com.android.internal.util.FastPrintWriter;
import com.android.internal.util.LatencyTracker;
@@ -751,24 +752,27 @@
final DisplayManager mDisplayManager;
final ActivityTaskManagerService mAtmService;
- // Indicates whether this device supports wide color gamut / HDR rendering
+ /** Corner radius that windows should have in order to match the display. */
+ final float mWindowCornerRadius;
+
+ /** Indicates whether this device supports wide color gamut / HDR rendering */
private boolean mHasWideColorGamutSupport;
private boolean mHasHdrSupport;
- // Who is holding the screen on.
+ /** Who is holding the screen on. */
private Session mHoldingScreenOn;
private PowerManager.WakeLock mHoldingScreenWakeLock;
- // Whether or not a layout can cause a wake up when theater mode is enabled.
+ /** Whether or not a layout can cause a wake up when theater mode is enabled. */
boolean mAllowTheaterModeWakeFromLayout;
final TaskPositioningController mTaskPositioningController;
final DragDropController mDragDropController;
- // For frozen screen animations.
+ /** For frozen screen animations. */
private int mExitAnimId, mEnterAnimId;
- // The display that the rotation animation is applying to.
+ /** The display that the rotation animation is applying to. */
private int mFrozenDisplayId;
/** Skip repeated AppWindowTokens initialization. Note that AppWindowsToken's version of this
@@ -975,7 +979,7 @@
mInputManager = inputManager; // Must be before createDisplayContentLocked.
mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class);
mDisplayWindowSettings = new DisplayWindowSettings(this);
-
+ mWindowCornerRadius = ScreenDecorationsUtils.getWindowCornerRadius(context.getResources());
mTransactionFactory = transactionFactory;
mTransaction = mTransactionFactory.make();
diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java
index 706901b..805fc91 100644
--- a/services/core/java/com/android/server/wm/WindowState.java
+++ b/services/core/java/com/android/server/wm/WindowState.java
@@ -4458,7 +4458,8 @@
anim.restrictDuration(MAX_ANIMATION_DURATION);
anim.scaleCurrentDuration(mWmService.getWindowAnimationScaleLocked());
final AnimationAdapter adapter = new LocalAnimationAdapter(
- new WindowAnimationSpec(anim, mSurfacePosition, false /* canSkipFirstFrame */),
+ new WindowAnimationSpec(anim, mSurfacePosition, false /* canSkipFirstFrame */,
+ mWmService.mWindowCornerRadius),
mWmService.mSurfaceAnimationRunner);
startAnimation(mPendingTransaction, adapter);
commitPendingTransaction();
diff --git a/services/tests/wmtests/src/com/android/server/wm/SurfaceAnimationRunnerTest.java b/services/tests/wmtests/src/com/android/server/wm/SurfaceAnimationRunnerTest.java
index 6cce9f0..c483489 100644
--- a/services/tests/wmtests/src/com/android/server/wm/SurfaceAnimationRunnerTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/SurfaceAnimationRunnerTest.java
@@ -213,7 +213,8 @@
final Animation a = new TranslateAnimation(-10, 10, 0, 0);
a.initialize(0, 0, 0, 0);
a.setDuration(50);
- return new WindowAnimationSpec(a, new Point(0, 0), false /* canSkipFirstFrame */);
+ return new WindowAnimationSpec(a, new Point(0, 0), false /* canSkipFirstFrame */,
+ 0 /* windowCornerRadius */);
}
/**
diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowAnimationSpecTest.java b/services/tests/wmtests/src/com/android/server/wm/WindowAnimationSpecTest.java
index 9a825e0..897f0a2 100644
--- a/services/tests/wmtests/src/com/android/server/wm/WindowAnimationSpecTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/WindowAnimationSpecTest.java
@@ -24,6 +24,8 @@
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.when;
import android.graphics.Point;
import android.graphics.Rect;
@@ -56,7 +58,7 @@
Animation a = createClipRectAnimation(windowCrop, windowCrop);
WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null,
mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_NONE,
- true /* isAppAnimation */);
+ true /* isAppAnimation */, 0 /* windowCornerRadius */);
windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
verify(mTransaction).setWindowCrop(eq(mSurfaceControl),
argThat(rect -> rect.equals(windowCrop)));
@@ -66,7 +68,7 @@
public void testApply_clipAfter() {
WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(mAnimation, null,
mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_AFTER_ANIM,
- true /* isAppAnimation */);
+ true /* isAppAnimation */, 0 /* windowCornerRadius */);
windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
verify(mTransaction).setWindowCrop(eq(mSurfaceControl), argThat(Rect::isEmpty));
}
@@ -76,8 +78,7 @@
// Stack bounds is (0, 0, 10, 10) position is (20, 40)
WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(mAnimation,
new Point(20, 40), mStackBounds, false /* canSkipFirstFrame */,
- STACK_CLIP_AFTER_ANIM,
- true /* isAppAnimation */);
+ STACK_CLIP_AFTER_ANIM, true /* isAppAnimation */, 0 /* windowCornerRadius */);
windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
verify(mTransaction).setWindowCrop(eq(mSurfaceControl), argThat(Rect::isEmpty));
}
@@ -87,7 +88,7 @@
// Stack bounds is (0, 0, 10, 10) animation clip is (0, 0, 0, 0)
WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(mAnimation, null,
mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM,
- true /* isAppAnimation */);
+ true /* isAppAnimation */, 0 /* windowCornerRadius */);
windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
verify(mTransaction).setWindowCrop(eq(mSurfaceControl),
argThat(rect -> rect.equals(mStackBounds)));
@@ -101,19 +102,32 @@
a.initialize(0, 0, 0, 0);
WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null,
null, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM,
- true /* isAppAnimation */);
+ true /* isAppAnimation */, 0 /* windowCornerRadius */);
windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
verify(mTransaction).setWindowCrop(eq(mSurfaceControl), argThat(Rect::isEmpty));
}
@Test
+ public void testApply_setCornerRadius() {
+ final float windowCornerRadius = 30f;
+ WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(mAnimation, null,
+ mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM,
+ true /* isAppAnimation */, windowCornerRadius);
+ windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
+ verify(mTransaction, never()).setCornerRadius(eq(mSurfaceControl), eq(windowCornerRadius));
+ when(mAnimation.hasRoundedCorners()).thenReturn(true);
+ windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
+ verify(mTransaction).setCornerRadius(eq(mSurfaceControl), eq(windowCornerRadius));
+ }
+
+ @Test
public void testApply_clipBeforeSmallerAnimationClip() {
// Stack bounds is (0, 0, 10, 10) animation clip is (0, 0, 5, 5)
Rect windowCrop = new Rect(0, 0, 5, 5);
Animation a = createClipRectAnimation(windowCrop, windowCrop);
WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null,
mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM,
- true /* isAppAnimation */);
+ true /* isAppAnimation */, 0 /* windowCornerRadius */);
windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
verify(mTransaction).setWindowCrop(eq(mSurfaceControl),
argThat(rect -> rect.equals(windowCrop)));
@@ -126,7 +140,7 @@
Animation a = createClipRectAnimation(windowCrop, windowCrop);
WindowAnimationSpec windowAnimationSpec = new WindowAnimationSpec(a, null,
mStackBounds, false /* canSkipFirstFrame */, STACK_CLIP_BEFORE_ANIM,
- true /* isAppAnimation */);
+ true /* isAppAnimation */, 0 /* windowCornerRadius */);
windowAnimationSpec.apply(mTransaction, mSurfaceControl, 0);
verify(mTransaction).setWindowCrop(eq(mSurfaceControl),
argThat(rect -> rect.equals(mStackBounds)));