Move shade code out of CentralSurfaces
Bug: 249277686
Test: manual
Test: run an fix affected tests
Change-Id: I5024e060f3fdbf4d5b213170bff150867038758a
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 2baeaf6..9cc87fd 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 @@
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 d0a3cbb..af5770f 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 @@
*/
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 @@
/** 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 d00dab6..055fbbe 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 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 dagger.Lazy;
import java.util.ArrayList;
+import java.util.concurrent.Executor;
import javax.inject.Inject;
@@ -51,6 +54,7 @@
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 @@
@Inject
public ShadeControllerImpl(
CommandQueue commandQueue,
+ @Main Executor mainExecutor,
KeyguardStateController keyguardStateController,
StatusBarStateController statusBarStateController,
StatusBarKeyguardViewManager statusBarKeyguardViewManager,
@@ -82,6 +87,7 @@
Lazy<NotificationGutsManager> gutsManager
) {
mCommandQueue = commandQueue;
+ mMainExecutor = mainExecutor;
mStatusBarStateController = statusBarStateController;
mStatusBarWindowController = statusBarWindowController;
mGutsManager = gutsManager;
@@ -227,6 +233,15 @@
}
@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) {
if (mExpandedVisible) {
@@ -235,8 +250,7 @@
}
}
- @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
@@ -246,6 +260,27 @@
}
@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();
runPostCollapseRunnables();
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 5ad5d84..119532e 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ActivityStarterImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ActivityStarterImpl.kt
@@ -389,6 +389,35 @@
}
/**
+ * 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.
*
* Logic is duplicated in {@link CentralSurfacesImpl}
@@ -419,7 +448,7 @@
val animate =
animationController != null &&
!willLaunchResolverActivity &&
- centralSurfaces?.shouldAnimateLaunch(true /* isActivityIntent */) == true
+ shouldAnimateLaunch(isActivityIntent = true)
val animController =
wrapAnimationController(
animationController = animationController,
@@ -538,7 +567,7 @@
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 @@
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 @@
val animate =
animationController != null &&
- centralSurfaces?.shouldAnimateLaunch(
+ shouldAnimateLaunch(
/* isActivityIntent= */ true,
showOverLockscreenWhenLocked
) == true
@@ -867,7 +896,8 @@
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 118e961..70c6e9a 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 @@
void animateExpandSettingsPanel(@Nullable String subpanel);
- void collapsePanelOnMainThread();
-
void togglePanel();
void start();
@@ -230,15 +228,6 @@
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 c220fd2..b93a5ff 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.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 @@
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();
@@ -2963,19 +2910,6 @@
}
/**
- * 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).
* @param wakingUp Whether we're updating because we're waking up (true) or going to sleep
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 00ac3f4..b67ec58 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 @@
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 @@
*/
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 @@
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 @@
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 28ec1ac..f79a081 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 @@
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 @@
OnUserInteractionCallback onUserInteractionCallback,
CentralSurfaces centralSurfaces,
NotificationPresenter presenter,
- ShadeViewController panel,
+ ShadeViewController shadeViewController,
NotificationShadeWindowController notificationShadeWindowController,
ActivityLaunchAnimator activityLaunchAnimator,
NotificationLaunchAnimatorControllerProvider notificationAnimationProvider,
@@ -193,7 +193,7 @@
// 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 @@
&& 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 @@
}
// Always defer the keyguard dismiss when animating.
- return animate || !mNotificationPanel.isFullyCollapsed();
+ return animate || !mShadeViewController.isFullyCollapsed();
}
private void handleNotificationClickAfterPanelCollapsed(
@@ -323,7 +323,7 @@
removeHunAfterClick(row);
// Show work challenge, do not run PendingIntent and
// remove notification
- collapseOnMainThread();
+ mShadeController.collapseOnMainThread();
return;
}
}
@@ -440,7 +440,8 @@
ActivityLaunchAnimator.Controller animationController =
new StatusBarLaunchAnimatorController(
mNotificationAnimationProvider.getAnimatorController(row, null),
- mCentralSurfaces,
+ mShadeViewController,
+ mShadeController,
mNotificationShadeWindowController,
isActivityIntent);
mActivityLaunchAnimator.startPendingIntentWithAnimation(
@@ -472,7 +473,7 @@
@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 @@
ActivityLaunchAnimator.Controller animationController =
new StatusBarLaunchAnimatorController(
mNotificationAnimationProvider.getAnimatorController(row),
- mCentralSurfaces,
+ mShadeViewController,
+ mShadeController,
mNotificationShadeWindowController,
true /* isActivityIntent */);
@@ -507,7 +509,7 @@
@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 @@
viewController == null ? null
: new StatusBarLaunchAnimatorController(
viewController,
- mCentralSurfaces,
+ mShadeViewController,
+ mShadeController,
mNotificationShadeWindowController,
true /* isActivityIntent */);
@@ -630,11 +633,4 @@
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 4ed113f..707f4e3 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 @@
mShadeController = spy(new ShadeControllerImpl(
mCommandQueue,
+ mMainExecutor,
mKeyguardStateController,
mStatusBarStateController,
mStatusBarKeyguardViewManager,