From 12b651b469d7d6664aef23f68cf59782faa95321 Mon Sep 17 00:00:00 2001 From: Jordan Demeulenaere Date: Wed, 14 Jul 2021 11:27:30 +0200 Subject: [PATCH] Remove dependency on WindowManager-Shell in the animation lib Bug: 193569148 Test: atest ActivityLaunchAnimatorTest Change-Id: I40d9546d14085a2ba3fe6e4ee559e43e463ce08a --- packages/SystemUI/animation/Android.bp | 1 - .../animation/ActivityLaunchAnimator.kt | 26 ++++++++----------- .../systemui/statusbar/phone/StatusBar.java | 18 ++++++++++--- .../animation/ActivityLaunchAnimatorTest.kt | 14 +++++----- 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/packages/SystemUI/animation/Android.bp b/packages/SystemUI/animation/Android.bp index 761b1f460bb5c..1b15d20d2c52d 100644 --- a/packages/SystemUI/animation/Android.bp +++ b/packages/SystemUI/animation/Android.bp @@ -36,7 +36,6 @@ android_library { static_libs: [ "PluginCoreLib", - "WindowManager-Shell", ], manifest: "AndroidManifest.xml", diff --git a/packages/SystemUI/animation/src/com/android/systemui/animation/ActivityLaunchAnimator.kt b/packages/SystemUI/animation/src/com/android/systemui/animation/ActivityLaunchAnimator.kt index 8505a6254b285..a50efd731cf60 100644 --- a/packages/SystemUI/animation/src/com/android/systemui/animation/ActivityLaunchAnimator.kt +++ b/packages/SystemUI/animation/src/com/android/systemui/animation/ActivityLaunchAnimator.kt @@ -7,6 +7,7 @@ import android.app.ActivityManager import android.app.ActivityTaskManager import android.app.AppGlobals import android.app.PendingIntent +import android.app.TaskInfo import android.content.Context import android.graphics.Matrix import android.graphics.PorterDuff @@ -30,8 +31,6 @@ import android.view.animation.AnimationUtils import android.view.animation.PathInterpolator import com.android.internal.annotations.VisibleForTesting import com.android.internal.policy.ScreenDecorationsUtils -import com.android.wm.shell.startingsurface.SplashscreenContentDrawer -import com.android.wm.shell.startingsurface.StartingSurface import kotlin.math.roundToInt private const val TAG = "ActivityLaunchAnimator" @@ -41,8 +40,7 @@ private const val TAG = "ActivityLaunchAnimator" * nicely into the starting window. */ class ActivityLaunchAnimator( - private val keyguardHandler: KeyguardHandler, - private val startingSurface: StartingSurface?, + private val callback: Callback, context: Context ) { companion object { @@ -120,7 +118,7 @@ class ActivityLaunchAnimator( Log.d(TAG, "Starting intent with a launch animation") val runner = Runner(controller) - val isOnKeyguard = keyguardHandler.isOnKeyguard() + val isOnKeyguard = callback.isOnKeyguard() // Pass the RemoteAnimationAdapter to the intent starter only if we are not on the keyguard. val animationAdapter = if (!isOnKeyguard) { @@ -163,7 +161,7 @@ class ActivityLaunchAnimator( // Hide the keyguard using the launch animation instead of the default unlock animation. if (isOnKeyguard) { - keyguardHandler.hideKeyguardWithAnimation(runner) + callback.hideKeyguardWithAnimation(runner) } } } @@ -212,7 +210,7 @@ class ActivityLaunchAnimator( fun startPendingIntent(animationAdapter: RemoteAnimationAdapter?): Int } - interface KeyguardHandler { + interface Callback { /** Whether we are currently on the keyguard or not. */ fun isOnKeyguard(): Boolean @@ -221,6 +219,9 @@ class ActivityLaunchAnimator( /** Enable/disable window blur so they don't overlap with the window launch animation **/ fun setBlursDisabledForAppLaunch(disabled: Boolean) + + /* Get the background color of [task]. */ + fun getBackgroundColor(task: TaskInfo): Int } /** @@ -484,12 +485,7 @@ class ActivityLaunchAnimator( // which is usually the same color of the app background. We first fade in this layer // to hide the expanding view, then we fade it out with SRC mode to draw a hole in the // launch container and reveal the opening window. - val windowBackgroundColor = if (startingSurface != null) { - startingSurface.getBackgroundColor(window.taskInfo) - } else { - Log.w(TAG, "No starting surface, defaulting to SystemBGColor") - SplashscreenContentDrawer.getSystemBGColor() - } + val windowBackgroundColor = callback.getBackgroundColor(window.taskInfo) val windowBackgroundLayer = GradientDrawable().apply { setColor(windowBackgroundColor) alpha = 0 @@ -505,7 +501,7 @@ class ActivityLaunchAnimator( animator.addListener(object : AnimatorListenerAdapter() { override fun onAnimationStart(animation: Animator?, isReverse: Boolean) { Log.d(TAG, "Animation started") - keyguardHandler.setBlursDisabledForAppLaunch(true) + callback.setBlursDisabledForAppLaunch(true) controller.onLaunchAnimationStart(isExpandingFullyAbove) // Add the drawable to the launch container overlay. Overlays always draw @@ -516,7 +512,7 @@ class ActivityLaunchAnimator( override fun onAnimationEnd(animation: Animator?) { Log.d(TAG, "Animation ended") - keyguardHandler.setBlursDisabledForAppLaunch(false) + callback.setBlursDisabledForAppLaunch(false) iCallback?.invoke() controller.onLaunchAnimationEnd(isExpandingFullyAbove) launchContainerOverlay.remove(windowBackgroundLayer) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index 6b8686b45528f..db7ead7c1531b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -55,6 +55,7 @@ import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.StatusBarManager; +import android.app.TaskInfo; import android.app.UiModeManager; import android.app.WallpaperInfo; import android.app.WallpaperManager; @@ -247,6 +248,7 @@ import com.android.systemui.volume.VolumeComponent; import com.android.systemui.wmshell.BubblesManager; import com.android.wm.shell.bubbles.Bubbles; import com.android.wm.shell.legacysplitscreen.LegacySplitScreen; +import com.android.wm.shell.startingsurface.SplashscreenContentDrawer; import com.android.wm.shell.startingsurface.StartingSurface; import java.io.FileDescriptor; @@ -269,7 +271,7 @@ public class StatusBar extends SystemUI implements DemoMode, ColorExtractor.OnColorsChangedListener, ConfigurationListener, StatusBarStateController.StateListener, LifecycleOwner, BatteryController.BatteryStateChangeCallback, - ActivityLaunchAnimator.KeyguardHandler { + ActivityLaunchAnimator.Callback { public static final boolean MULTIUSER_DEBUG = false; protected static final int MSG_HIDE_RECENT_APPS = 1020; @@ -1421,9 +1423,7 @@ public class StatusBar extends SystemUI implements DemoMode, private void setUpPresenter() { // Set up the initial notification state. - mActivityLaunchAnimator = new ActivityLaunchAnimator(this, - mStartingSurfaceOptional.orElse(null), - mContext); + mActivityLaunchAnimator = new ActivityLaunchAnimator(this, mContext); mNotificationAnimationProvider = new NotificationLaunchAnimatorControllerProvider( mNotificationShadeWindowViewController, mStackScrollerController.getNotificationListContainer(), @@ -2123,6 +2123,16 @@ public class StatusBar extends SystemUI implements DemoMode, mKeyguardViewMediator.setBlursDisabledForAppLaunch(disabled); } + @Override + public int getBackgroundColor(TaskInfo task) { + if (!mStartingSurfaceOptional.isPresent()) { + Log.w(TAG, "No starting surface, defaulting to SystemBGColor"); + return SplashscreenContentDrawer.getSystemBGColor(); + } + + return mStartingSurfaceOptional.get().getBackgroundColor(task); + } + public boolean isDeviceInVrMode() { return mPresenter.isDeviceInVrMode(); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/animation/ActivityLaunchAnimatorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/animation/ActivityLaunchAnimatorTest.kt index 694b84a0b9499..14f112b8b0713 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/animation/ActivityLaunchAnimatorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/animation/ActivityLaunchAnimatorTest.kt @@ -22,7 +22,6 @@ import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.util.mockito.any import com.android.systemui.util.mockito.eq -import com.android.wm.shell.startingsurface.StartingSurface import junit.framework.Assert.assertFalse import junit.framework.Assert.assertNotNull import junit.framework.Assert.assertNull @@ -47,10 +46,9 @@ import org.mockito.junit.MockitoJUnit @RunWithLooper class ActivityLaunchAnimatorTest : SysuiTestCase() { private val launchContainer = LinearLayout(mContext) - @Mock lateinit var keyguardHandler: ActivityLaunchAnimator.KeyguardHandler + @Mock lateinit var callback: ActivityLaunchAnimator.Callback @Spy private val controller = TestLaunchAnimatorController(launchContainer) @Mock lateinit var iCallback: IRemoteAnimationFinishedCallback - @Mock lateinit var startingSurface: StartingSurface @Mock lateinit var failHandler: Log.TerribleFailureHandler private lateinit var activityLaunchAnimator: ActivityLaunchAnimator @@ -58,7 +56,7 @@ class ActivityLaunchAnimatorTest : SysuiTestCase() { @Before fun setup() { - activityLaunchAnimator = ActivityLaunchAnimator(keyguardHandler, startingSurface, mContext) + activityLaunchAnimator = ActivityLaunchAnimator(callback, mContext) } private fun startIntentWithAnimation( @@ -121,8 +119,8 @@ class ActivityLaunchAnimatorTest : SysuiTestCase() { @Test fun animatesIfActivityIsAlreadyOpenAndIsOnKeyguard() { - `when`(keyguardHandler.isOnKeyguard()).thenReturn(true) - val animator = ActivityLaunchAnimator(keyguardHandler, startingSurface, context) + `when`(callback.isOnKeyguard()).thenReturn(true) + val animator = ActivityLaunchAnimator(callback, context) val willAnimateCaptor = ArgumentCaptor.forClass(Boolean::class.java) var animationAdapter: RemoteAnimationAdapter? = null @@ -134,7 +132,7 @@ class ActivityLaunchAnimatorTest : SysuiTestCase() { waitForIdleSync() verify(controller).onIntentStarted(willAnimateCaptor.capture()) - verify(keyguardHandler).hideKeyguardWithAnimation(any()) + verify(callback).hideKeyguardWithAnimation(any()) assertTrue(willAnimateCaptor.value) assertNull(animationAdapter) @@ -176,7 +174,7 @@ class ActivityLaunchAnimatorTest : SysuiTestCase() { val runner = activityLaunchAnimator.createRunner(controller) runner.onAnimationStart(0, arrayOf(fakeWindow()), emptyArray(), emptyArray(), iCallback) waitForIdleSync() - verify(keyguardHandler).setBlursDisabledForAppLaunch(eq(true)) + verify(callback).setBlursDisabledForAppLaunch(eq(true)) verify(controller).onLaunchAnimationStart(anyBoolean()) }