From 6b59087d661b8d305879e5d054a9dad0d1a269b1 Mon Sep 17 00:00:00 2001 From: Justin Weir Date: Wed, 31 May 2023 09:49:30 -0400 Subject: [PATCH] Move shade code out of CentralSurfaces Bug: 249277686 Test: manual Test: run an fix affected tests Change-Id: I5024e060f3fdbf4d5b213170bff150867038758a --- .../systemui/plugins/ActivityStarter.java | 3 + .../systemui/shade/ShadeController.java | 10 ++- .../systemui/shade/ShadeControllerImpl.java | 39 ++++++++++- .../statusbar/phone/ActivityStarterImpl.kt | 40 +++++++++-- .../statusbar/phone/CentralSurfaces.java | 11 ---- .../statusbar/phone/CentralSurfacesImpl.java | 66 ------------------- .../StatusBarLaunchAnimatorController.kt | 23 ++++--- .../StatusBarNotificationActivityStarter.java | 32 ++++----- .../phone/CentralSurfacesImplTest.java | 1 + 9 files changed, 111 insertions(+), 114 deletions(-) diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/ActivityStarter.java b/packages/SystemUI/plugin/src/com/android/systemui/plugins/ActivityStarter.java index 2baeaf67df93d..9cc87fde122f8 100644 --- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/ActivityStarter.java +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/ActivityStarter.java @@ -133,6 +133,9 @@ public interface ActivityStarter { boolean willAnimateOnKeyguard, @Nullable String customMessage); + /** Whether we should animate an activity launch. */ + boolean shouldAnimateLaunch(boolean isActivityIntent); + interface Callback { void onActivityStarted(int resultCode); } diff --git a/packages/SystemUI/src/com/android/systemui/shade/ShadeController.java b/packages/SystemUI/src/com/android/systemui/shade/ShadeController.java index d0a3cbbf0b024..af5770f509907 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/ShadeController.java +++ b/packages/SystemUI/src/com/android/systemui/shade/ShadeController.java @@ -115,6 +115,9 @@ public interface ShadeController { */ void collapseShade(boolean animate); + /** Calls #collapseShade if already on the main thread. If not, posts a call to it. */ + void collapseOnMainThread(); + /** Makes shade expanded but not visible. */ void makeExpandedInvisible(); @@ -127,8 +130,11 @@ public interface ShadeController { /** Handle status bar touch event. */ void onStatusBarTouch(MotionEvent event); - /** Called when the shade finishes collapsing. */ - void onClosingFinished(); + /** Called when a launch animation was cancelled. */ + void onLaunchAnimationCancelled(boolean isLaunchForActivity); + + /** Called when a launch animation ends. */ + void onLaunchAnimationEnd(boolean launchIsFullScreen); /** Sets the listener for when the visibility of the shade changes. */ void setVisibilityListener(ShadeVisibilityListener listener); diff --git a/packages/SystemUI/src/com/android/systemui/shade/ShadeControllerImpl.java b/packages/SystemUI/src/com/android/systemui/shade/ShadeControllerImpl.java index d00dab6330146..055fbbe32b3fe 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/ShadeControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/shade/ShadeControllerImpl.java @@ -17,6 +17,7 @@ package com.android.systemui.shade; import android.content.ComponentCallbacks2; +import android.os.Looper; import android.util.Log; import android.view.MotionEvent; import android.view.ViewTreeObserver; @@ -25,6 +26,7 @@ import android.view.WindowManagerGlobal; import com.android.systemui.assist.AssistManager; import com.android.systemui.dagger.SysUISingleton; +import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.statusbar.CommandQueue; import com.android.systemui.statusbar.NotificationPresenter; @@ -38,6 +40,7 @@ import com.android.systemui.statusbar.window.StatusBarWindowController; import dagger.Lazy; import java.util.ArrayList; +import java.util.concurrent.Executor; import javax.inject.Inject; @@ -51,6 +54,7 @@ public final class ShadeControllerImpl implements ShadeController { private final int mDisplayId; private final CommandQueue mCommandQueue; + private final Executor mMainExecutor; private final KeyguardStateController mKeyguardStateController; private final NotificationShadeWindowController mNotificationShadeWindowController; private final StatusBarStateController mStatusBarStateController; @@ -72,6 +76,7 @@ public final class ShadeControllerImpl implements ShadeController { @Inject public ShadeControllerImpl( CommandQueue commandQueue, + @Main Executor mainExecutor, KeyguardStateController keyguardStateController, StatusBarStateController statusBarStateController, StatusBarKeyguardViewManager statusBarKeyguardViewManager, @@ -82,6 +87,7 @@ public final class ShadeControllerImpl implements ShadeController { Lazy gutsManager ) { mCommandQueue = commandQueue; + mMainExecutor = mainExecutor; mStatusBarStateController = statusBarStateController; mStatusBarWindowController = statusBarWindowController; mGutsManager = gutsManager; @@ -226,6 +232,15 @@ public final class ShadeControllerImpl implements ShadeController { } } + @Override + public void collapseOnMainThread() { + if (Looper.getMainLooper().isCurrentThread()) { + collapseShade(); + } else { + mMainExecutor.execute(this::collapseShade); + } + } + @Override public void onStatusBarTouch(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { @@ -235,8 +250,7 @@ public final class ShadeControllerImpl implements ShadeController { } } - @Override - public void onClosingFinished() { + private void onClosingFinished() { runPostCollapseRunnables(); if (!mPresenter.isPresenterFullyCollapsed()) { // if we set it not to be focusable when collapsing, we have to undo it when we aborted @@ -245,6 +259,27 @@ public final class ShadeControllerImpl implements ShadeController { } } + @Override + public void onLaunchAnimationCancelled(boolean isLaunchForActivity) { + if (mPresenter.isPresenterFullyCollapsed() + && !mPresenter.isCollapsing() + && isLaunchForActivity) { + onClosingFinished(); + } else { + collapseShade(true /* animate */); + } + } + + @Override + public void onLaunchAnimationEnd(boolean launchIsFullScreen) { + if (!mPresenter.isCollapsing()) { + onClosingFinished(); + } + if (launchIsFullScreen) { + instantCollapseShade(); + } + } + @Override public void instantCollapseShade() { mNotificationPanelViewController.instantCollapse(); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ActivityStarterImpl.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ActivityStarterImpl.kt index 5ad5d841fad5b..119532e58001e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ActivityStarterImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ActivityStarterImpl.kt @@ -388,6 +388,35 @@ constructor( mainExecutor.executeDelayed(runnable, delay.toLong()) } + /** + * Whether we should animate an activity launch. + * + * Note: This method must be called *before* dismissing the keyguard. + */ + private fun shouldAnimateLaunch( + isActivityIntent: Boolean, + showOverLockscreen: Boolean, + ): Boolean { + // TODO(b/184121838): Support launch animations when occluded. + if (keyguardStateController.isOccluded) { + return false + } + + // Always animate if we are not showing the keyguard or if we animate over the lockscreen + // (without unlocking it). + if (showOverLockscreen || !keyguardStateController.isShowing) { + return true + } + + // We don't animate non-activity launches as they can break the animation. + // TODO(b/184121838): Support non activity launches on the lockscreen. + return isActivityIntent + } + + override fun shouldAnimateLaunch(isActivityIntent: Boolean): Boolean { + return shouldAnimateLaunch(isActivityIntent, false) + } + /** * Encapsulates the activity logic for activity starter. * @@ -419,7 +448,7 @@ constructor( val animate = animationController != null && !willLaunchResolverActivity && - centralSurfaces?.shouldAnimateLaunch(true /* isActivityIntent */) == true + shouldAnimateLaunch(isActivityIntent = true) val animController = wrapAnimationController( animationController = animationController, @@ -538,7 +567,7 @@ constructor( val animate = !willLaunchResolverActivity && animationController != null && - centralSurfaces?.shouldAnimateLaunch(intent.isActivity) == true + shouldAnimateLaunch(intent.isActivity) // If we animate, don't collapse the shade and defer the keyguard dismiss (in case we // run the animation on the keyguard). The animation will take care of (instantly) @@ -595,7 +624,7 @@ constructor( Log.w(TAG, "Sending intent failed: $e") if (!collapse) { // executeRunnableDismissingKeyguard did not collapse for us already. - centralSurfaces?.collapsePanelOnMainThread() + shadeControllerLazy.get().collapseOnMainThread() } // TODO: Dismiss Keyguard. } @@ -637,7 +666,7 @@ constructor( val animate = animationController != null && - centralSurfaces?.shouldAnimateLaunch( + shouldAnimateLaunch( /* isActivityIntent= */ true, showOverLockscreenWhenLocked ) == true @@ -867,7 +896,8 @@ constructor( if (dismissShade) { return StatusBarLaunchAnimatorController( animationController, - it, + it.shadeViewController, + shadeControllerLazy.get(), notifShadeWindowControllerLazy.get(), isLaunchForActivity ) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfaces.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfaces.java index 118e961acd24e..70c6e9af5c043 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfaces.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfaces.java @@ -191,8 +191,6 @@ public interface CentralSurfaces extends Dumpable, LifecycleOwner { void animateExpandSettingsPanel(@Nullable String subpanel); - void collapsePanelOnMainThread(); - void togglePanel(); void start(); @@ -230,15 +228,6 @@ public interface CentralSurfaces extends Dumpable, LifecycleOwner { boolean isOccluded(); - //TODO: These can / should probably be moved to NotificationPresenter or ShadeController - void onLaunchAnimationCancelled(boolean isLaunchForActivity); - - void onLaunchAnimationEnd(boolean launchIsFullScreen); - - boolean shouldAnimateLaunch(boolean isActivityIntent, boolean showOverLockscreen); - - boolean shouldAnimateLaunch(boolean isActivityIntent); - boolean isDeviceInVrMode(); NotificationPresenter getPresenter(); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java index c220fd2aafe2f..b93a5ff32dcd2 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java @@ -69,7 +69,6 @@ import android.net.Uri; import android.os.Binder; import android.os.Bundle; import android.os.Handler; -import android.os.Looper; import android.os.PowerManager; import android.os.RemoteException; import android.os.ServiceManager; @@ -1823,58 +1822,6 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces { return mKeyguardStateController.isOccluded(); } - /** A launch animation was cancelled. */ - //TODO: These can / should probably be moved to NotificationPresenter or ShadeController - @Override - public void onLaunchAnimationCancelled(boolean isLaunchForActivity) { - if (mPresenter.isPresenterFullyCollapsed() && !mPresenter.isCollapsing() - && isLaunchForActivity) { - mShadeController.onClosingFinished(); - } else { - mShadeController.collapseShade(true /* animate */); - } - } - - /** A launch animation ended. */ - @Override - public void onLaunchAnimationEnd(boolean launchIsFullScreen) { - if (!mPresenter.isCollapsing()) { - mShadeController.onClosingFinished(); - } - if (launchIsFullScreen) { - mShadeController.instantCollapseShade(); - } - } - - /** - * Whether we should animate an activity launch. - * - * Note: This method must be called *before* dismissing the keyguard. - */ - @Override - public boolean shouldAnimateLaunch(boolean isActivityIntent, boolean showOverLockscreen) { - // TODO(b/184121838): Support launch animations when occluded. - if (isOccluded()) { - return false; - } - - // Always animate if we are not showing the keyguard or if we animate over the lockscreen - // (without unlocking it). - if (showOverLockscreen || !mKeyguardStateController.isShowing()) { - return true; - } - - // We don't animate non-activity launches as they can break the animation. - // TODO(b/184121838): Support non activity launches on the lockscreen. - return isActivityIntent; - } - - /** Whether we should animate an activity launch. */ - @Override - public boolean shouldAnimateLaunch(boolean isActivityIntent) { - return shouldAnimateLaunch(isActivityIntent, false /* showOverLockscreen */); - } - @Override public boolean isDeviceInVrMode() { return mPresenter.isDeviceInVrMode(); @@ -2962,19 +2909,6 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces { } } - /** - * Collapse the panel directly if we are on the main thread, post the collapsing on the main - * thread if we are not. - */ - @Override - public void collapsePanelOnMainThread() { - if (Looper.getMainLooper().isCurrentThread()) { - mShadeController.collapseShade(); - } else { - mContext.getMainExecutor().execute(mShadeController::collapseShade); - } - } - /** * Updates the light reveal effect to reflect the reason we're waking or sleeping (for example, * from the power button). diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarLaunchAnimatorController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarLaunchAnimatorController.kt index 00ac3f4cdc119..b67ec581f8a26 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarLaunchAnimatorController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarLaunchAnimatorController.kt @@ -3,6 +3,8 @@ package com.android.systemui.statusbar.phone import android.view.View import com.android.systemui.animation.ActivityLaunchAnimator import com.android.systemui.animation.LaunchAnimator +import com.android.systemui.shade.ShadeController +import com.android.systemui.shade.ShadeViewController import com.android.systemui.statusbar.NotificationShadeWindowController /** @@ -11,7 +13,8 @@ import com.android.systemui.statusbar.NotificationShadeWindowController */ class StatusBarLaunchAnimatorController( private val delegate: ActivityLaunchAnimator.Controller, - private val centralSurfaces: CentralSurfaces, + private val shadeViewController: ShadeViewController, + private val shadeController: ShadeController, private val notificationShadeWindowController: NotificationShadeWindowController, private val isLaunchForActivity: Boolean = true ) : ActivityLaunchAnimator.Controller by delegate { @@ -23,25 +26,25 @@ class StatusBarLaunchAnimatorController( override fun onIntentStarted(willAnimate: Boolean) { delegate.onIntentStarted(willAnimate) if (willAnimate) { - centralSurfaces.shadeViewController.setIsLaunchAnimationRunning(true) + shadeViewController.setIsLaunchAnimationRunning(true) } else { - centralSurfaces.collapsePanelOnMainThread() + shadeController.collapseOnMainThread() } } override fun onLaunchAnimationStart(isExpandingFullyAbove: Boolean) { delegate.onLaunchAnimationStart(isExpandingFullyAbove) - centralSurfaces.shadeViewController.setIsLaunchAnimationRunning(true) + shadeViewController.setIsLaunchAnimationRunning(true) if (!isExpandingFullyAbove) { - centralSurfaces.shadeViewController.collapseWithDuration( + shadeViewController.collapseWithDuration( ActivityLaunchAnimator.TIMINGS.totalDuration.toInt()) } } override fun onLaunchAnimationEnd(isExpandingFullyAbove: Boolean) { delegate.onLaunchAnimationEnd(isExpandingFullyAbove) - centralSurfaces.shadeViewController.setIsLaunchAnimationRunning(false) - centralSurfaces.onLaunchAnimationEnd(isExpandingFullyAbove) + shadeViewController.setIsLaunchAnimationRunning(false) + shadeController.onLaunchAnimationEnd(isExpandingFullyAbove) } override fun onLaunchAnimationProgress( @@ -50,12 +53,12 @@ class StatusBarLaunchAnimatorController( linearProgress: Float ) { delegate.onLaunchAnimationProgress(state, progress, linearProgress) - centralSurfaces.shadeViewController.applyLaunchAnimationProgress(linearProgress) + shadeViewController.applyLaunchAnimationProgress(linearProgress) } override fun onLaunchAnimationCancelled(newKeyguardOccludedState: Boolean?) { delegate.onLaunchAnimationCancelled() - centralSurfaces.shadeViewController.setIsLaunchAnimationRunning(false) - centralSurfaces.onLaunchAnimationCancelled(isLaunchForActivity) + shadeViewController.setIsLaunchAnimationRunning(false) + shadeController.onLaunchAnimationCancelled(isLaunchForActivity) } } \ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java index 28ec1ac5e5931..f79a08173bf24 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java @@ -122,7 +122,7 @@ class StatusBarNotificationActivityStarter implements NotificationActivityStarte private final CentralSurfaces mCentralSurfaces; private final NotificationPresenter mPresenter; - private final ShadeViewController mNotificationPanel; + private final ShadeViewController mShadeViewController; private final NotificationShadeWindowController mNotificationShadeWindowController; private final ActivityLaunchAnimator mActivityLaunchAnimator; private final NotificationLaunchAnimatorControllerProvider mNotificationAnimationProvider; @@ -158,7 +158,7 @@ class StatusBarNotificationActivityStarter implements NotificationActivityStarte OnUserInteractionCallback onUserInteractionCallback, CentralSurfaces centralSurfaces, NotificationPresenter presenter, - ShadeViewController panel, + ShadeViewController shadeViewController, NotificationShadeWindowController notificationShadeWindowController, ActivityLaunchAnimator activityLaunchAnimator, NotificationLaunchAnimatorControllerProvider notificationAnimationProvider, @@ -193,7 +193,7 @@ class StatusBarNotificationActivityStarter implements NotificationActivityStarte // TODO: use KeyguardStateController#isOccluded to remove this dependency mCentralSurfaces = centralSurfaces; mPresenter = presenter; - mNotificationPanel = panel; + mShadeViewController = shadeViewController; mActivityLaunchAnimator = activityLaunchAnimator; mNotificationAnimationProvider = notificationAnimationProvider; mUserTracker = userTracker; @@ -237,7 +237,7 @@ class StatusBarNotificationActivityStarter implements NotificationActivityStarte && mActivityIntentHelper.wouldPendingLaunchResolverActivity(intent, mLockscreenUserManager.getCurrentUserId()); final boolean animate = !willLaunchResolverActivity - && mCentralSurfaces.shouldAnimateLaunch(isActivityIntent); + && mActivityStarter.shouldAnimateLaunch(isActivityIntent); boolean showOverLockscreen = mKeyguardStateController.isShowing() && intent != null && mActivityIntentHelper.wouldPendingShowOverLockscreen(intent, mLockscreenUserManager.getCurrentUserId()); @@ -288,7 +288,7 @@ class StatusBarNotificationActivityStarter implements NotificationActivityStarte } // Always defer the keyguard dismiss when animating. - return animate || !mNotificationPanel.isFullyCollapsed(); + return animate || !mShadeViewController.isFullyCollapsed(); } private void handleNotificationClickAfterPanelCollapsed( @@ -323,7 +323,7 @@ class StatusBarNotificationActivityStarter implements NotificationActivityStarte removeHunAfterClick(row); // Show work challenge, do not run PendingIntent and // remove notification - collapseOnMainThread(); + mShadeController.collapseOnMainThread(); return; } } @@ -440,7 +440,8 @@ class StatusBarNotificationActivityStarter implements NotificationActivityStarte ActivityLaunchAnimator.Controller animationController = new StatusBarLaunchAnimatorController( mNotificationAnimationProvider.getAnimatorController(row, null), - mCentralSurfaces, + mShadeViewController, + mShadeController, mNotificationShadeWindowController, isActivityIntent); mActivityLaunchAnimator.startPendingIntentWithAnimation( @@ -472,7 +473,7 @@ class StatusBarNotificationActivityStarter implements NotificationActivityStarte @Override public void startNotificationGutsIntent(final Intent intent, final int appUid, ExpandableNotificationRow row) { - boolean animate = mCentralSurfaces.shouldAnimateLaunch(true /* isActivityIntent */); + boolean animate = mActivityStarter.shouldAnimateLaunch(true /* isActivityIntent */); ActivityStarter.OnDismissAction onDismissAction = new ActivityStarter.OnDismissAction() { @Override public boolean onDismiss() { @@ -480,7 +481,8 @@ class StatusBarNotificationActivityStarter implements NotificationActivityStarte ActivityLaunchAnimator.Controller animationController = new StatusBarLaunchAnimatorController( mNotificationAnimationProvider.getAnimatorController(row), - mCentralSurfaces, + mShadeViewController, + mShadeController, mNotificationShadeWindowController, true /* isActivityIntent */); @@ -507,7 +509,7 @@ class StatusBarNotificationActivityStarter implements NotificationActivityStarte @Override public void startHistoryIntent(View view, boolean showHistory) { - boolean animate = mCentralSurfaces.shouldAnimateLaunch(true /* isActivityIntent */); + boolean animate = mActivityStarter.shouldAnimateLaunch(true /* isActivityIntent */); ActivityStarter.OnDismissAction onDismissAction = new ActivityStarter.OnDismissAction() { @Override public boolean onDismiss() { @@ -529,7 +531,8 @@ class StatusBarNotificationActivityStarter implements NotificationActivityStarte viewController == null ? null : new StatusBarLaunchAnimatorController( viewController, - mCentralSurfaces, + mShadeViewController, + mShadeController, mNotificationShadeWindowController, true /* isActivityIntent */); @@ -630,11 +633,4 @@ class StatusBarNotificationActivityStarter implements NotificationActivityStarte return true; } - private void collapseOnMainThread() { - if (Looper.getMainLooper().isCurrentThread()) { - mShadeController.collapseShade(); - } else { - mMainThreadHandler.post(mShadeController::collapseShade); - } - } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CentralSurfacesImplTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CentralSurfacesImplTest.java index 4ed113fe13581..707f4e305208b 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CentralSurfacesImplTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CentralSurfacesImplTest.java @@ -431,6 +431,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase { mShadeController = spy(new ShadeControllerImpl( mCommandQueue, + mMainExecutor, mKeyguardStateController, mStatusBarStateController, mStatusBarKeyguardViewManager,