Move shade code out of CentralSurfaces

Bug: 249277686
Test: manual
Test: run an fix affected tests
Change-Id: I5024e060f3fdbf4d5b213170bff150867038758a
This commit is contained in:
Justin Weir
2023-05-31 09:49:30 -04:00
parent 771907f97a
commit 6b59087d66
9 changed files with 111 additions and 114 deletions

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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<NotificationGutsManager> 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();

View File

@@ -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
)

View File

@@ -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();

View File

@@ -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).

View File

@@ -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)
}
}

View File

@@ -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);
}
}
}

View File

@@ -431,6 +431,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
mShadeController = spy(new ShadeControllerImpl(
mCommandQueue,
mMainExecutor,
mKeyguardStateController,
mStatusBarStateController,
mStatusBarKeyguardViewManager,