From acf75b2ecba32d41643af87b74ff7cdc41d4f41e Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Tue, 10 Jan 2023 12:12:58 -0800 Subject: [PATCH] [Bouncer] Remove KeyguardBouncer.java and all of its references. Bug: 240299776 Test: Build app and open bouncer. Change-Id: I0607a020b660d4d2d3f86e7905a335f144026540 Merged-In: I0607a020b660d4d2d3f86e7905a335f144026540 --- .../dagger/KeyguardBouncerComponent.java | 4 +- .../dagger/KeyguardBouncerModule.java | 4 +- .../biometrics/UdfpsKeyguardViewController.kt | 29 - .../DreamOverlayContainerViewController.java | 13 - .../repository/KeyguardBouncerRepository.kt | 1 - .../constants/KeyguardBouncerConstants.kt | 1 + .../NotificationPanelViewController.java | 5 +- .../statusbar/phone/KeyguardBouncer.java | 708 ------------------ .../phone/StatusBarKeyguardViewManager.java | 216 +----- .../UdfpsKeyguardViewControllerBaseTest.java | 4 - .../UdfpsKeyguardViewControllerTest.java | 16 +- ...eamOverlayContainerViewControllerTest.java | 16 +- .../statusbar/phone/KeyguardBouncerTest.java | 526 ------------- .../StatusBarKeyguardViewManagerTest.java | 6 - .../StatusBarKeyguardViewManagerTest_Old.java | 581 -------------- 15 files changed, 53 insertions(+), 2077 deletions(-) delete mode 100644 packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBouncer.java delete mode 100644 packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardBouncerTest.java delete mode 100644 packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest_Old.java diff --git a/packages/SystemUI/src/com/android/keyguard/dagger/KeyguardBouncerComponent.java b/packages/SystemUI/src/com/android/keyguard/dagger/KeyguardBouncerComponent.java index 0cbf8bc07edf9..5ad21df1e6524 100644 --- a/packages/SystemUI/src/com/android/keyguard/dagger/KeyguardBouncerComponent.java +++ b/packages/SystemUI/src/com/android/keyguard/dagger/KeyguardBouncerComponent.java @@ -20,13 +20,13 @@ import android.view.ViewGroup; import com.android.keyguard.KeyguardHostViewController; import com.android.systemui.dagger.qualifiers.RootView; -import com.android.systemui.statusbar.phone.KeyguardBouncer; +import com.android.systemui.keyguard.domain.interactor.PrimaryBouncerInteractor; import dagger.BindsInstance; import dagger.Subcomponent; /** - * Dagger Subcomponent for the {@link KeyguardBouncer}. + * Dagger Subcomponent for the {@link PrimaryBouncerInteractor}. */ @Subcomponent(modules = {KeyguardBouncerModule.class}) @KeyguardBouncerScope diff --git a/packages/SystemUI/src/com/android/keyguard/dagger/KeyguardBouncerModule.java b/packages/SystemUI/src/com/android/keyguard/dagger/KeyguardBouncerModule.java index ef067b89f9c72..cb7a0a9b1653e 100644 --- a/packages/SystemUI/src/com/android/keyguard/dagger/KeyguardBouncerModule.java +++ b/packages/SystemUI/src/com/android/keyguard/dagger/KeyguardBouncerModule.java @@ -29,7 +29,7 @@ import com.android.keyguard.KeyguardSecurityViewFlipper; import com.android.systemui.R; import com.android.systemui.biometrics.SideFpsController; import com.android.systemui.dagger.qualifiers.RootView; -import com.android.systemui.statusbar.phone.KeyguardBouncer; +import com.android.systemui.keyguard.domain.interactor.PrimaryBouncerInteractor; import java.util.Optional; @@ -39,7 +39,7 @@ import dagger.Module; import dagger.Provides; /** - * Module to create and access view related to the {@link KeyguardBouncer}. + * Module to create and access view related to the {@link PrimaryBouncerInteractor}. */ @Module public interface KeyguardBouncerModule { diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsKeyguardViewController.kt b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsKeyguardViewController.kt index 63a1b76b8103b..d072ec7cd9437 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsKeyguardViewController.kt +++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsKeyguardViewController.kt @@ -32,7 +32,6 @@ import com.android.systemui.dump.DumpManager import com.android.systemui.flags.FeatureFlags import com.android.systemui.flags.Flags import com.android.systemui.keyguard.domain.interactor.AlternateBouncerInteractor -import com.android.systemui.keyguard.domain.interactor.PrimaryBouncerCallbackInteractor.PrimaryBouncerExpansionCallback import com.android.systemui.keyguard.domain.interactor.PrimaryBouncerInteractor import com.android.systemui.keyguard.shared.constants.KeyguardBouncerConstants import com.android.systemui.lifecycle.repeatWhenAttached @@ -149,21 +148,6 @@ constructor( } } - private val mPrimaryBouncerExpansionCallback: PrimaryBouncerExpansionCallback = - object : PrimaryBouncerExpansionCallback { - override fun onExpansionChanged(expansion: Float) { - inputBouncerHiddenAmount = expansion - updateAlpha() - updatePauseAuth() - } - - override fun onVisibilityChanged(isVisible: Boolean) { - updateBouncerHiddenAmount() - updateAlpha() - updatePauseAuth() - } - } - private val configurationListener: ConfigurationController.ConfigurationListener = object : ConfigurationController.ConfigurationListener { override fun onUiModeChanged() { @@ -315,14 +299,6 @@ constructor( statusBarState = statusBarStateController.state qsExpansion = keyguardViewManager.qsExpansion keyguardViewManager.addCallback(statusBarKeyguardViewManagerCallback) - if (!isModernBouncerEnabled) { - val bouncer = keyguardViewManager.primaryBouncer - bouncer?.expansion?.let { - mPrimaryBouncerExpansionCallback.onExpansionChanged(it) - bouncer.addBouncerExpansionCallback(mPrimaryBouncerExpansionCallback) - } - updateBouncerHiddenAmount() - } configurationController.addCallback(configurationListener) shadeExpansionStateManager.addExpansionListener(shadeExpansionListener) updateScaleFactor() @@ -352,11 +328,6 @@ constructor( } activityLaunchAnimator.removeListener(activityLaunchAnimatorListener) keyguardViewManager.removeCallback(statusBarKeyguardViewManagerCallback) - if (!isModernBouncerEnabled) { - keyguardViewManager.primaryBouncer?.removeBouncerExpansionCallback( - mPrimaryBouncerExpansionCallback - ) - } } override fun dump(pw: PrintWriter, args: Array) { diff --git a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayContainerViewController.java b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayContainerViewController.java index 33c8379d2e5cc..c2dcdd0eed171 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayContainerViewController.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayContainerViewController.java @@ -40,8 +40,6 @@ import com.android.systemui.dreams.dagger.DreamOverlayModule; import com.android.systemui.keyguard.domain.interactor.PrimaryBouncerCallbackInteractor; import com.android.systemui.keyguard.domain.interactor.PrimaryBouncerCallbackInteractor.PrimaryBouncerExpansionCallback; import com.android.systemui.statusbar.BlurUtils; -import com.android.systemui.statusbar.phone.KeyguardBouncer; -import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; import com.android.systemui.util.ViewController; import com.android.systemui.util.concurrency.DelayableExecutor; @@ -56,7 +54,6 @@ import javax.inject.Named; @DreamOverlayComponent.DreamOverlayScope public class DreamOverlayContainerViewController extends ViewController { private final DreamOverlayStatusBarViewController mStatusBarViewController; - private final StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; private final BlurUtils mBlurUtils; private final DreamOverlayAnimationsController mDreamOverlayAnimationsController; private final DreamOverlayStateController mStateController; @@ -133,7 +130,6 @@ public class DreamOverlayContainerViewController extends ViewController mExpansionCallbacks = new ArrayList<>(); - private final KeyguardUpdateMonitor mKeyguardUpdateMonitor; - private final KeyguardStateController mKeyguardStateController; - private final KeyguardSecurityModel mKeyguardSecurityModel; - private final KeyguardBouncerComponent.Factory mKeyguardBouncerComponentFactory; - private final KeyguardUpdateMonitorCallback mUpdateMonitorCallback = - new KeyguardUpdateMonitorCallback() { - @Override - public void onStrongAuthStateChanged(int userId) { - mBouncerPromptReason = mCallback.getBouncerPromptReason(); - } - - @Override - public void onLockedOutStateChanged(BiometricSourceType type) { - if (type == BiometricSourceType.FINGERPRINT) { - mBouncerPromptReason = mCallback.getBouncerPromptReason(); - } - } - - @Override - public void onNonStrongBiometricAllowedChanged(int userId) { - mBouncerPromptReason = mCallback.getBouncerPromptReason(); - } - }; - private final Runnable mRemoveViewRunnable = this::removeView; - private final KeyguardBypassController mKeyguardBypassController; - private KeyguardHostViewController mKeyguardViewController; - private final ListenerSet mResetCallbacks = new ListenerSet<>(); - private final Runnable mResetRunnable = ()-> { - if (mKeyguardViewController != null) { - mKeyguardViewController.resetSecurityContainer(); - for (KeyguardResetCallback callback : mResetCallbacks) { - callback.onKeyguardReset(); - } - } - }; - - private int mStatusBarHeight; - private float mExpansion = EXPANSION_HIDDEN; - private boolean mShowingSoon; - private int mBouncerPromptReason; - private boolean mIsAnimatingAway; - private boolean mIsScrimmed; - private boolean mInitialized; - - private KeyguardBouncer(Context context, ViewMediatorCallback callback, - ViewGroup container, - DismissCallbackRegistry dismissCallbackRegistry, FalsingCollector falsingCollector, - PrimaryBouncerExpansionCallback expansionCallback, - KeyguardStateController keyguardStateController, - KeyguardUpdateMonitor keyguardUpdateMonitor, - KeyguardBypassController keyguardBypassController, @Main Handler handler, - KeyguardSecurityModel keyguardSecurityModel, - KeyguardBouncerComponent.Factory keyguardBouncerComponentFactory) { - mContext = context; - mCallback = callback; - mContainer = container; - mKeyguardUpdateMonitor = keyguardUpdateMonitor; - mFalsingCollector = falsingCollector; - mDismissCallbackRegistry = dismissCallbackRegistry; - mHandler = handler; - mKeyguardStateController = keyguardStateController; - mKeyguardSecurityModel = keyguardSecurityModel; - mKeyguardBouncerComponentFactory = keyguardBouncerComponentFactory; - mKeyguardUpdateMonitor.registerCallback(mUpdateMonitorCallback); - mKeyguardBypassController = keyguardBypassController; - mExpansionCallbacks.add(expansionCallback); - } - - /** - * Get the KeyguardBouncer expansion - * @return 1=HIDDEN, 0=SHOWING, in between 0 and 1 means the bouncer is in transition. - */ - public float getExpansion() { - return mExpansion; - } - - /** - * Enable/disable only the back button - */ - public void setBackButtonEnabled(boolean enabled) { - int vis = mContainer.getSystemUiVisibility(); - if (enabled) { - vis &= ~View.STATUS_BAR_DISABLE_BACK; - } else { - vis |= View.STATUS_BAR_DISABLE_BACK; - } - mContainer.setSystemUiVisibility(vis); - } - - public void show(boolean resetSecuritySelection) { - show(resetSecuritySelection, true /* scrimmed */); - } - - /** - * Shows the bouncer. - * - * @param resetSecuritySelection Cleans keyguard view - * @param isScrimmed true when the bouncer show show scrimmed, false when the user will be - * dragging it and translation should be deferred. - */ - public void show(boolean resetSecuritySelection, boolean isScrimmed) { - final int keyguardUserId = KeyguardUpdateMonitor.getCurrentUser(); - if (keyguardUserId == UserHandle.USER_SYSTEM && UserManager.isSplitSystemUser()) { - // In split system user mode, we never unlock system user. - return; - } - - try { - Trace.beginSection("KeyguardBouncer#show"); - - ensureView(); - mIsScrimmed = isScrimmed; - - // On the keyguard, we want to show the bouncer when the user drags up, but it's - // not correct to end the falsing session. We still need to verify if those touches - // are valid. - // Later, at the end of the animation, when the bouncer is at the top of the screen, - // onFullyShown() will be called and FalsingManager will stop recording touches. - if (isScrimmed) { - setExpansion(EXPANSION_VISIBLE); - } - - if (resetSecuritySelection) { - // showPrimarySecurityScreen() updates the current security method. This is needed - // in case we are already showing and the current security method changed. - showPrimarySecurityScreen(); - } - - if (mContainer.getVisibility() == View.VISIBLE || mShowingSoon) { - // Calls to reset must resume the ViewControllers when in fullscreen mode - if (needsFullscreenBouncer()) { - mKeyguardViewController.onResume(); - } - return; - } - - final int activeUserId = KeyguardUpdateMonitor.getCurrentUser(); - final boolean isSystemUser = - UserManager.isSplitSystemUser() && activeUserId == UserHandle.USER_SYSTEM; - final boolean allowDismissKeyguard = !isSystemUser && activeUserId == keyguardUserId; - - // If allowed, try to dismiss the Keyguard. If no security auth (password/pin/pattern) - // is set, this will dismiss the whole Keyguard. Otherwise, show the bouncer. - if (allowDismissKeyguard && mKeyguardViewController.dismiss(activeUserId)) { - return; - } - - // This condition may indicate an error on Android, so log it. - if (!allowDismissKeyguard) { - Log.w(TAG, "User can't dismiss keyguard: " + activeUserId + " != " - + keyguardUserId); - } - - mShowingSoon = true; - - // Split up the work over multiple frames. - DejankUtils.removeCallbacks(mResetRunnable); - if (mKeyguardStateController.isFaceAuthEnabled() - && !mKeyguardUpdateMonitor.getCachedIsUnlockWithFingerprintPossible( - KeyguardUpdateMonitor.getCurrentUser()) - && !needsFullscreenBouncer() - && mKeyguardUpdateMonitor.isUnlockingWithBiometricAllowed( - BiometricSourceType.FACE) - && !mKeyguardBypassController.getBypassEnabled()) { - mHandler.postDelayed(mShowRunnable, BOUNCER_FACE_DELAY); - } else { - DejankUtils.postAfterTraversal(mShowRunnable); - } - - mKeyguardStateController.notifyBouncerShowing(true /* showing */); - dispatchStartingToShow(); - } finally { - Trace.endSection(); - } - } - - public boolean isScrimmed() { - return mIsScrimmed; - } - - /** - * This method must be called at the end of the bouncer animation when - * the translation is performed manually by the user, otherwise FalsingManager - * will never be notified and its internal state will be out of sync. - */ - private void onFullyShown() { - mFalsingCollector.onBouncerShown(); - if (mKeyguardViewController == null) { - Log.e(TAG, "onFullyShown when view was null"); - } else { - mKeyguardViewController.onResume(); - mContainer.announceForAccessibility( - mKeyguardViewController.getAccessibilityTitleForCurrentMode()); - } - } - - /** - * @see #onFullyShown() - */ - private void onFullyHidden() { - - } - - private void setVisibility(@View.Visibility int visibility) { - mContainer.setVisibility(visibility); - if (mKeyguardViewController != null) { - mKeyguardViewController.onBouncerVisibilityChanged(visibility); - } - dispatchVisibilityChanged(); - } - - private final Runnable mShowRunnable = new Runnable() { - @Override - public void run() { - setVisibility(View.VISIBLE); - showPromptReason(mBouncerPromptReason); - final CharSequence customMessage = mCallback.consumeCustomMessage(); - if (customMessage != null) { - mKeyguardViewController.showErrorMessage(customMessage); - } - mKeyguardViewController.appear(mStatusBarHeight); - mShowingSoon = false; - if (mExpansion == EXPANSION_VISIBLE) { - mKeyguardViewController.onResume(); - mKeyguardViewController.resetSecurityContainer(); - showPromptReason(mBouncerPromptReason); - } - } - }; - - /** - * Show a string explaining why the security view needs to be solved. - * - * @param reason a flag indicating which string should be shown, see - * {@link KeyguardSecurityView#PROMPT_REASON_NONE} - * and {@link KeyguardSecurityView#PROMPT_REASON_RESTART} - */ - public void showPromptReason(int reason) { - if (mKeyguardViewController != null) { - mKeyguardViewController.showPromptReason(reason); - } else { - Log.w(TAG, "Trying to show prompt reason on empty bouncer"); - } - } - - public void showMessage(String message, ColorStateList colorState) { - if (mKeyguardViewController != null) { - mKeyguardViewController.showMessage(message, colorState); - } else { - Log.w(TAG, "Trying to show message on empty bouncer"); - } - } - - private void cancelShowRunnable() { - DejankUtils.removeCallbacks(mShowRunnable); - mHandler.removeCallbacks(mShowRunnable); - mShowingSoon = false; - } - - public void showWithDismissAction(OnDismissAction r, Runnable cancelAction) { - ensureView(); - setDismissAction(r, cancelAction); - show(false /* resetSecuritySelection */); - } - - /** - * Set the actions to run when the keyguard is dismissed or when the dismiss is cancelled. Those - * actions will still be run even if this bouncer is not shown, for instance when authenticating - * with an alternate authenticator like the UDFPS. - */ - public void setDismissAction(OnDismissAction r, Runnable cancelAction) { - mKeyguardViewController.setOnDismissAction(r, cancelAction); - } - - public void hide(boolean destroyView) { - Trace.beginSection("KeyguardBouncer#hide"); - if (isShowing()) { - SysUiStatsLog.write(SysUiStatsLog.KEYGUARD_BOUNCER_STATE_CHANGED, - SysUiStatsLog.KEYGUARD_BOUNCER_STATE_CHANGED__STATE__HIDDEN); - mDismissCallbackRegistry.notifyDismissCancelled(); - } - mIsScrimmed = false; - mFalsingCollector.onBouncerHidden(); - mKeyguardStateController.notifyBouncerShowing(false /* showing */); - cancelShowRunnable(); - if (mKeyguardViewController != null) { - mKeyguardViewController.cancelDismissAction(); - mKeyguardViewController.cleanUp(); - } - mIsAnimatingAway = false; - setVisibility(View.INVISIBLE); - if (destroyView) { - - // We have a ViewFlipper that unregisters a broadcast when being detached, which may - // be slow because of AM lock contention during unlocking. We can delay it a bit. - mHandler.postDelayed(mRemoveViewRunnable, 50); - } - Trace.endSection(); - } - - /** - * See {@link StatusBarKeyguardViewManager#startPreHideAnimation}. - */ - public void startPreHideAnimation(Runnable runnable) { - mIsAnimatingAway = true; - if (mKeyguardViewController != null) { - mKeyguardViewController.startDisappearAnimation(runnable); - } else if (runnable != null) { - runnable.run(); - } - } - - /** - * Reset the state of the view. - */ - public void reset() { - cancelShowRunnable(); - inflateView(); - mFalsingCollector.onBouncerHidden(); - } - - public void onScreenTurnedOff() { - if (mKeyguardViewController != null && mContainer.getVisibility() == View.VISIBLE) { - mKeyguardViewController.onPause(); - } - } - - public boolean isShowing() { - return (mShowingSoon || mContainer.getVisibility() == View.VISIBLE) - && mExpansion == EXPANSION_VISIBLE && !isAnimatingAway(); - } - - /** - * {@link #show(boolean)} was called but we're not showing yet, or being dragged. - */ - public boolean inTransit() { - return mShowingSoon || mExpansion != EXPANSION_HIDDEN && mExpansion != EXPANSION_VISIBLE; - } - - /** - * @return {@code true} when bouncer's pre-hide animation already started but isn't completely - * hidden yet, {@code false} otherwise. - */ - public boolean isAnimatingAway() { - return mIsAnimatingAway; - } - - public void prepare() { - boolean wasInitialized = mInitialized; - ensureView(); - if (wasInitialized) { - showPrimarySecurityScreen(); - } - mBouncerPromptReason = mCallback.getBouncerPromptReason(); - } - - private void showPrimarySecurityScreen() { - mKeyguardViewController.showPrimarySecurityScreen(); - } - - /** - * Current notification panel expansion - * @param fraction 0 when notification panel is collapsed and 1 when expanded. - * @see StatusBarKeyguardViewManager#onPanelExpansionChanged - */ - public void setExpansion(float fraction) { - float oldExpansion = mExpansion; - boolean expansionChanged = mExpansion != fraction; - mExpansion = fraction; - if (mKeyguardViewController != null && !mIsAnimatingAway) { - mKeyguardViewController.setExpansion(fraction); - } - - if (fraction == EXPANSION_VISIBLE && oldExpansion != EXPANSION_VISIBLE) { - onFullyShown(); - dispatchFullyShown(); - } else if (fraction == EXPANSION_HIDDEN && oldExpansion != EXPANSION_HIDDEN) { - DejankUtils.postAfterTraversal(mResetRunnable); - /* - * There are cases where #hide() was not invoked, such as when - * NotificationPanelViewController controls the hide animation. Make sure the state gets - * updated by calling #hide() directly. - */ - hide(false /* destroyView */); - dispatchFullyHidden(); - } else if (fraction != EXPANSION_VISIBLE && oldExpansion == EXPANSION_VISIBLE) { - dispatchStartingToHide(); - if (mKeyguardViewController != null) { - mKeyguardViewController.onStartingToHide(); - } - } - - if (expansionChanged) { - dispatchExpansionChanged(); - } - } - - public boolean willDismissWithAction() { - return mKeyguardViewController != null && mKeyguardViewController.hasDismissActions(); - } - - public int getTop() { - if (mKeyguardViewController == null) { - return 0; - } - - return mKeyguardViewController.getTop(); - } - - protected void ensureView() { - // Removal of the view might be deferred to reduce unlock latency, - // in this case we need to force the removal, otherwise we'll - // end up in an unpredictable state. - boolean forceRemoval = mHandler.hasCallbacks(mRemoveViewRunnable); - if (!mInitialized || forceRemoval) { - inflateView(); - } - } - - protected void inflateView() { - removeView(); - mHandler.removeCallbacks(mRemoveViewRunnable); - - KeyguardBouncerComponent component = mKeyguardBouncerComponentFactory.create(mContainer); - mKeyguardViewController = component.getKeyguardHostViewController(); - mKeyguardViewController.init(); - - mStatusBarHeight = SystemBarUtils.getStatusBarHeight(mContext); - setVisibility(View.INVISIBLE); - - final WindowInsets rootInsets = mContainer.getRootWindowInsets(); - if (rootInsets != null) { - mContainer.dispatchApplyWindowInsets(rootInsets); - } - mInitialized = true; - } - - protected void removeView() { - mContainer.removeAllViews(); - mInitialized = false; - } - - /** - * @return True if and only if the security method should be shown before showing the - * notifications on Keyguard, like SIM PIN/PUK. - */ - public boolean needsFullscreenBouncer() { - SecurityMode mode = mKeyguardSecurityModel.getSecurityMode( - KeyguardUpdateMonitor.getCurrentUser()); - return mode == SecurityMode.SimPin || mode == SecurityMode.SimPuk; - } - - /** - * Like {@link #needsFullscreenBouncer}, but uses the currently visible security method, which - * makes this method much faster. - */ - public boolean isFullscreenBouncer() { - if (mKeyguardViewController != null) { - SecurityMode mode = mKeyguardViewController.getCurrentSecurityMode(); - return mode == SecurityMode.SimPin || mode == SecurityMode.SimPuk; - } - return false; - } - - /** - * WARNING: This method might cause Binder calls. - */ - public boolean isSecure() { - return mKeyguardSecurityModel.getSecurityMode( - KeyguardUpdateMonitor.getCurrentUser()) != SecurityMode.None; - } - - public boolean shouldDismissOnMenuPressed() { - return mKeyguardViewController.shouldEnableMenuKey(); - } - - public boolean interceptMediaKey(KeyEvent event) { - ensureView(); - return mKeyguardViewController.interceptMediaKey(event); - } - - /** - * @return true if the pre IME back event should be handled - */ - public boolean dispatchBackKeyEventPreIme() { - ensureView(); - return mKeyguardViewController.dispatchBackKeyEventPreIme(); - } - - public void notifyKeyguardAuthenticated(boolean strongAuth) { - ensureView(); - mKeyguardViewController.finish(strongAuth, KeyguardUpdateMonitor.getCurrentUser()); - } - - private void dispatchFullyShown() { - for (PrimaryBouncerExpansionCallback callback : mExpansionCallbacks) { - callback.onFullyShown(); - } - } - - private void dispatchStartingToHide() { - for (PrimaryBouncerExpansionCallback callback : mExpansionCallbacks) { - callback.onStartingToHide(); - } - } - - private void dispatchStartingToShow() { - for (PrimaryBouncerExpansionCallback callback : mExpansionCallbacks) { - callback.onStartingToShow(); - } - } - - private void dispatchFullyHidden() { - for (PrimaryBouncerExpansionCallback callback : mExpansionCallbacks) { - callback.onFullyHidden(); - } - } - - private void dispatchExpansionChanged() { - for (PrimaryBouncerExpansionCallback callback : mExpansionCallbacks) { - callback.onExpansionChanged(mExpansion); - } - } - - private void dispatchVisibilityChanged() { - for (PrimaryBouncerExpansionCallback callback : mExpansionCallbacks) { - callback.onVisibilityChanged(mContainer.getVisibility() == View.VISIBLE); - } - } - - /** - * Apply keyguard configuration from the currently active resources. This can be called when the - * device configuration changes, to re-apply some resources that are qualified on the device - * configuration. - */ - public void updateResources() { - if (mKeyguardViewController != null) { - mKeyguardViewController.updateResources(); - } - } - - public void dump(PrintWriter pw) { - pw.println("KeyguardBouncer"); - pw.println(" isShowing(): " + isShowing()); - pw.println(" mStatusBarHeight: " + mStatusBarHeight); - pw.println(" mExpansion: " + mExpansion); - pw.println(" mKeyguardViewController; " + mKeyguardViewController); - pw.println(" mShowingSoon: " + mShowingSoon); - pw.println(" mBouncerPromptReason: " + mBouncerPromptReason); - pw.println(" mIsAnimatingAway: " + mIsAnimatingAway); - pw.println(" mInitialized: " + mInitialized); - } - - /** Update keyguard position based on a tapped X coordinate. */ - public void updateKeyguardPosition(float x) { - if (mKeyguardViewController != null) { - mKeyguardViewController.updateKeyguardPosition(x); - } - } - - public void addKeyguardResetCallback(KeyguardResetCallback callback) { - mResetCallbacks.addIfAbsent(callback); - } - - public void removeKeyguardResetCallback(KeyguardResetCallback callback) { - mResetCallbacks.remove(callback); - } - - /** - * Adds a callback to listen to bouncer expansion updates. - */ - public void addBouncerExpansionCallback(PrimaryBouncerExpansionCallback callback) { - if (!mExpansionCallbacks.contains(callback)) { - mExpansionCallbacks.add(callback); - } - } - - /** - * Removes a previously added callback. If the callback was never added, this methood - * does nothing. - */ - public void removeBouncerExpansionCallback(PrimaryBouncerExpansionCallback callback) { - mExpansionCallbacks.remove(callback); - } - - /** Create a {@link KeyguardBouncer} once a container and bouncer callback are available. */ - public static class Factory { - private final Context mContext; - private final ViewMediatorCallback mCallback; - private final DismissCallbackRegistry mDismissCallbackRegistry; - private final FalsingCollector mFalsingCollector; - private final KeyguardStateController mKeyguardStateController; - private final KeyguardUpdateMonitor mKeyguardUpdateMonitor; - private final KeyguardBypassController mKeyguardBypassController; - private final Handler mHandler; - private final KeyguardSecurityModel mKeyguardSecurityModel; - private final KeyguardBouncerComponent.Factory mKeyguardBouncerComponentFactory; - - @Inject - public Factory(Context context, ViewMediatorCallback callback, - DismissCallbackRegistry dismissCallbackRegistry, FalsingCollector falsingCollector, - KeyguardStateController keyguardStateController, - KeyguardUpdateMonitor keyguardUpdateMonitor, - KeyguardBypassController keyguardBypassController, @Main Handler handler, - KeyguardSecurityModel keyguardSecurityModel, - KeyguardBouncerComponent.Factory keyguardBouncerComponentFactory) { - mContext = context; - mCallback = callback; - mDismissCallbackRegistry = dismissCallbackRegistry; - mFalsingCollector = falsingCollector; - mKeyguardStateController = keyguardStateController; - mKeyguardUpdateMonitor = keyguardUpdateMonitor; - mKeyguardBypassController = keyguardBypassController; - mHandler = handler; - mKeyguardSecurityModel = keyguardSecurityModel; - mKeyguardBouncerComponentFactory = keyguardBouncerComponentFactory; - } - - /** - * Construct a KeyguardBouncer that will exist in the given container. - */ - public KeyguardBouncer create(ViewGroup container, - PrimaryBouncerExpansionCallback expansionCallback) { - return new KeyguardBouncer(mContext, mCallback, container, - mDismissCallbackRegistry, mFalsingCollector, expansionCallback, - mKeyguardStateController, mKeyguardUpdateMonitor, - mKeyguardBypassController, mHandler, mKeyguardSecurityModel, - mKeyguardBouncerComponentFactory); - } - } -} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java index 8e22bf4a8df40..fd465710d4ea9 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java @@ -129,7 +129,6 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb private final ConfigurationController mConfigurationController; private final NavigationModeController mNavigationModeController; private final NotificationShadeWindowController mNotificationShadeWindowController; - private final KeyguardBouncer.Factory mKeyguardBouncerFactory; private final KeyguardMessageAreaController.Factory mKeyguardMessageAreaFactory; private final DreamOverlayStateController mDreamOverlayStateController; @Nullable @@ -206,28 +205,28 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb Log.d(TAG, "onBackInvokedCallback() called, invoking onBackPressed()"); } onBackPressed(); - if (shouldPlayBackAnimation()) { + if (shouldPlayBackAnimation() && mPrimaryBouncerView.getDelegate() != null) { mPrimaryBouncerView.getDelegate().getBackCallback().onBackInvoked(); } } @Override public void onBackProgressed(BackEvent event) { - if (shouldPlayBackAnimation()) { + if (shouldPlayBackAnimation() && mPrimaryBouncerView.getDelegate() != null) { mPrimaryBouncerView.getDelegate().getBackCallback().onBackProgressed(event); } } @Override public void onBackCancelled() { - if (shouldPlayBackAnimation()) { + if (shouldPlayBackAnimation() && mPrimaryBouncerView.getDelegate() != null) { mPrimaryBouncerView.getDelegate().getBackCallback().onBackCancelled(); } } @Override public void onBackStarted(BackEvent event) { - if (shouldPlayBackAnimation()) { + if (shouldPlayBackAnimation() && mPrimaryBouncerView.getDelegate() != null) { mPrimaryBouncerView.getDelegate().getBackCallback().onBackStarted(event); } } @@ -256,7 +255,6 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb private View mNotificationContainer; - @Nullable protected KeyguardBouncer mPrimaryBouncer; protected boolean mRemoteInputActive; private boolean mGlobalActionsVisible = false; private boolean mLastGlobalActionsVisible = false; @@ -281,7 +279,6 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb private boolean mLastScreenOffAnimationPlaying; private float mQsExpansion; final Set mCallbacks = new HashSet<>(); - private boolean mIsModernBouncerEnabled; private boolean mIsUnoccludeTransitionFlagEnabled; private boolean mIsModernAlternateBouncerEnabled; private boolean mIsBackAnimationEnabled; @@ -329,7 +326,6 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb NotificationShadeWindowController notificationShadeWindowController, KeyguardStateController keyguardStateController, NotificationMediaManager notificationMediaManager, - KeyguardBouncer.Factory keyguardBouncerFactory, KeyguardMessageAreaController.Factory keyguardMessageAreaFactory, Optional sysUIUnfoldComponent, Lazy shadeController, @@ -352,7 +348,6 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb mKeyguardUpdateManager = keyguardUpdateMonitor; mStatusBarStateController = sysuiStatusBarStateController; mDockManager = dockManager; - mKeyguardBouncerFactory = keyguardBouncerFactory; mKeyguardMessageAreaFactory = keyguardMessageAreaFactory; mShadeController = shadeController; mLatencyTracker = latencyTracker; @@ -362,7 +357,6 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb mPrimaryBouncerView = primaryBouncerView; mFoldAodAnimationController = sysUIUnfoldComponent .map(SysUIUnfoldComponent::getFoldAodAnimationController).orElse(null); - mIsModernBouncerEnabled = featureFlags.isEnabled(Flags.MODERN_BOUNCER); mIsUnoccludeTransitionFlagEnabled = featureFlags.isEnabled(Flags.UNOCCLUSION_TRANSITION); mIsModernAlternateBouncerEnabled = featureFlags.isEnabled(Flags.MODERN_ALTERNATE_BOUNCER); mAlternateBouncerInteractor = alternateBouncerInteractor; @@ -381,11 +375,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb mBiometricUnlockController = biometricUnlockController; ViewGroup container = mCentralSurfaces.getBouncerContainer(); - if (mIsModernBouncerEnabled) { - mPrimaryBouncerCallbackInteractor.addBouncerExpansionCallback(mExpansionCallback); - } else { - mPrimaryBouncer = mKeyguardBouncerFactory.create(container, mExpansionCallback); - } + mPrimaryBouncerCallbackInteractor.addBouncerExpansionCallback(mExpansionCallback); mNotificationPanelViewController = notificationPanelViewController; if (shadeExpansionStateManager != null) { shadeExpansionStateManager.addExpansionListener(this); @@ -552,11 +542,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb * show if any subsequent events are to be handled. */ if (beginShowingBouncer(event)) { - if (mPrimaryBouncer != null) { - mPrimaryBouncer.show(false /* resetSecuritySelection */, false /* scrimmed */); - } else { - mPrimaryBouncerInteractor.show(/* isScrimmed= */false); - } + mPrimaryBouncerInteractor.show(/* isScrimmed= */false); } if (!primaryBouncerIsOrWillBeShowing()) { @@ -564,17 +550,9 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb } if (mKeyguardStateController.isShowing()) { - if (mPrimaryBouncer != null) { - mPrimaryBouncer.setExpansion(fraction); - } else { - mPrimaryBouncerInteractor.setPanelExpansion(fraction); - } + mPrimaryBouncerInteractor.setPanelExpansion(fraction); } else { - if (mPrimaryBouncer != null) { - mPrimaryBouncer.setExpansion(EXPANSION_HIDDEN); - } else { - mPrimaryBouncerInteractor.setPanelExpansion(EXPANSION_HIDDEN); - } + mPrimaryBouncerInteractor.setPanelExpansion(EXPANSION_HIDDEN); } } @@ -604,24 +582,17 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb /** * Shows the notification keyguard or the bouncer depending on - * {@link KeyguardBouncer#needsFullscreenBouncer()}. + * {@link #needsFullscreenBouncer()}. */ protected void showBouncerOrKeyguard(boolean hideBouncerWhenShowing) { if (needsFullscreenBouncer() && !mDozing) { // The keyguard might be showing (already). So we need to hide it. mCentralSurfaces.hideKeyguard(); - if (mPrimaryBouncer != null) { - mPrimaryBouncer.show(true /* resetSecuritySelection */); - } else { - mPrimaryBouncerInteractor.show(true); - } + mPrimaryBouncerInteractor.show(true); } else { mCentralSurfaces.showKeyguard(); if (hideBouncerWhenShowing) { hideBouncer(false /* destroyView */); - if (mPrimaryBouncer != null) { - mPrimaryBouncer.prepare(); - } } } updateStates(); @@ -648,11 +619,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb */ @VisibleForTesting void hideBouncer(boolean destroyView) { - if (mPrimaryBouncer != null) { - mPrimaryBouncer.hide(destroyView); - } else { - mPrimaryBouncerInteractor.hide(); - } + mPrimaryBouncerInteractor.hide(); if (mKeyguardStateController.isShowing()) { // If we were showing the bouncer and then aborting, we need to also clear out any // potential actions unless we actually unlocked. @@ -671,11 +638,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb hideAlternateBouncer(false); if (mKeyguardStateController.isShowing() && !isBouncerShowing()) { - if (mPrimaryBouncer != null) { - mPrimaryBouncer.show(false /* resetSecuritySelection */, scrimmed); - } else { - mPrimaryBouncerInteractor.show(scrimmed); - } + mPrimaryBouncerInteractor.show(scrimmed); } updateStates(); } @@ -708,13 +671,8 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb // instead of the bouncer. if (mAlternateBouncerInteractor.canShowAlternateBouncerForFingerprint()) { if (!afterKeyguardGone) { - if (mPrimaryBouncer != null) { - mPrimaryBouncer.setDismissAction(mAfterKeyguardGoneAction, - mKeyguardGoneCancelAction); - } else { - mPrimaryBouncerInteractor.setDismissAction(mAfterKeyguardGoneAction, - mKeyguardGoneCancelAction); - } + mPrimaryBouncerInteractor.setDismissAction(mAfterKeyguardGoneAction, + mKeyguardGoneCancelAction); mAfterKeyguardGoneAction = null; mKeyguardGoneCancelAction = null; } @@ -726,22 +684,13 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb if (afterKeyguardGone) { // we'll handle the dismiss action after keyguard is gone, so just show the // bouncer - if (mPrimaryBouncer != null) { - mPrimaryBouncer.show(false /* resetSecuritySelection */); - } else { - mPrimaryBouncerInteractor.show(/* isScrimmed= */true); - } + mPrimaryBouncerInteractor.show(/* isScrimmed= */true); } else { // after authentication success, run dismiss action with the option to defer // hiding the keyguard based on the return value of the OnDismissAction - if (mPrimaryBouncer != null) { - mPrimaryBouncer.showWithDismissAction(mAfterKeyguardGoneAction, - mKeyguardGoneCancelAction); - } else { - mPrimaryBouncerInteractor.setDismissAction( - mAfterKeyguardGoneAction, mKeyguardGoneCancelAction); - mPrimaryBouncerInteractor.show(/* isScrimmed= */true); - } + mPrimaryBouncerInteractor.setDismissAction( + mAfterKeyguardGoneAction, mKeyguardGoneCancelAction); + mPrimaryBouncerInteractor.show(/* isScrimmed= */true); // bouncer will handle the dismiss action, so we no longer need to track it here mAfterKeyguardGoneAction = null; mKeyguardGoneCancelAction = null; @@ -841,11 +790,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb @Override public void onFinishedGoingToSleep() { - if (mPrimaryBouncer != null) { - mPrimaryBouncer.onScreenTurnedOff(); - } else { - mPrimaryBouncerInteractor.onScreenTurnedOff(); - } + mPrimaryBouncerInteractor.onScreenTurnedOff(); } @Override @@ -939,11 +884,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb @Override public void startPreHideAnimation(Runnable finishRunnable) { if (primaryBouncerIsShowing()) { - if (mPrimaryBouncer != null) { - mPrimaryBouncer.startPreHideAnimation(finishRunnable); - } else { - mPrimaryBouncerInteractor.startDisappearAnimation(finishRunnable); - } + mPrimaryBouncerInteractor.startDisappearAnimation(finishRunnable); mNotificationPanelViewController.startBouncerPreHideAnimation(); // We update the state (which will show the keyguard) only if an animation will run on @@ -1051,17 +992,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb } public void onThemeChanged() { - if (mIsModernBouncerEnabled) { - updateResources(); - return; - } - boolean wasShowing = primaryBouncerIsShowing(); - boolean wasScrimmed = primaryBouncerIsScrimmed(); - - hideBouncer(true /* destroyView */); - mPrimaryBouncer.prepare(); - - if (wasShowing) showPrimaryBouncer(wasScrimmed); + updateResources(); } public void onKeyguardFadedAway() { @@ -1106,10 +1037,6 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb * WARNING: This method might cause Binder calls. */ public boolean isSecure() { - if (mPrimaryBouncer != null) { - return mPrimaryBouncer.isSecure(); - } - return mKeyguardSecurityModel.getSecurityMode( KeyguardUpdateMonitor.getCurrentUser()) != KeyguardSecurityModel.SecurityMode.None; } @@ -1164,10 +1091,8 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb } public boolean isFullscreenBouncer() { - if (mPrimaryBouncerView.getDelegate() != null) { - return mPrimaryBouncerView.getDelegate().isFullScreenBouncer(); - } - return mPrimaryBouncer != null && mPrimaryBouncer.isFullscreenBouncer(); + return mPrimaryBouncerView.getDelegate() != null + && mPrimaryBouncerView.getDelegate().isFullScreenBouncer(); } /** @@ -1223,17 +1148,9 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb != (mLastBouncerDismissible || !mLastShowing || mLastRemoteInputActive) || mFirstUpdate) { if (primaryBouncerDismissible || !showing || remoteInputActive) { - if (mPrimaryBouncer != null) { - mPrimaryBouncer.setBackButtonEnabled(true); - } else { - mPrimaryBouncerInteractor.setBackButtonEnabled(true); - } + mPrimaryBouncerInteractor.setBackButtonEnabled(true); } else { - if (mPrimaryBouncer != null) { - mPrimaryBouncer.setBackButtonEnabled(false); - } else { - mPrimaryBouncerInteractor.setBackButtonEnabled(false); - } + mPrimaryBouncerInteractor.setBackButtonEnabled(false); } } @@ -1327,27 +1244,21 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb } public boolean shouldDismissOnMenuPressed() { - if (mPrimaryBouncerView.getDelegate() != null) { - return mPrimaryBouncerView.getDelegate().shouldDismissOnMenuPressed(); - } - return mPrimaryBouncer != null && mPrimaryBouncer.shouldDismissOnMenuPressed(); + return mPrimaryBouncerView.getDelegate() != null + && mPrimaryBouncerView.getDelegate().shouldDismissOnMenuPressed(); } public boolean interceptMediaKey(KeyEvent event) { - if (mPrimaryBouncerView.getDelegate() != null) { - return mPrimaryBouncerView.getDelegate().interceptMediaKey(event); - } - return mPrimaryBouncer != null && mPrimaryBouncer.interceptMediaKey(event); + return mPrimaryBouncerView.getDelegate() != null + && mPrimaryBouncerView.getDelegate().interceptMediaKey(event); } /** * @return true if the pre IME back event should be handled */ public boolean dispatchBackKeyEventPreIme() { - if (mPrimaryBouncerView.getDelegate() != null) { - return mPrimaryBouncerView.getDelegate().dispatchBackKeyEventPreIme(); - } - return mPrimaryBouncer != null && mPrimaryBouncer.dispatchBackKeyEventPreIme(); + return mPrimaryBouncerView.getDelegate() != null + && mPrimaryBouncerView.getDelegate().dispatchBackKeyEventPreIme(); } public void readyForKeyguardDone() { @@ -1393,11 +1304,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb * fingerprint. */ public void notifyKeyguardAuthenticated(boolean strongAuth) { - if (mPrimaryBouncer != null) { - mPrimaryBouncer.notifyKeyguardAuthenticated(strongAuth); - } else { - mPrimaryBouncerInteractor.notifyKeyguardAuthenticated(strongAuth); - } + mPrimaryBouncerInteractor.notifyKeyguardAuthenticated(strongAuth); if (mAlternateBouncerInteractor.isVisibleState()) { hideAlternateBouncer(false); @@ -1412,11 +1319,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb mKeyguardMessageAreaController.setMessage(message); } } else { - if (mPrimaryBouncer != null) { - mPrimaryBouncer.showMessage(message, colorState); - } else { - mPrimaryBouncerInteractor.showMessage(message, colorState); - } + mPrimaryBouncerInteractor.showMessage(message, colorState); } } @@ -1472,11 +1375,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb * configuration. */ public void updateResources() { - if (mPrimaryBouncer != null) { - mPrimaryBouncer.updateResources(); - } else { - mPrimaryBouncerInteractor.updateResources(); - } + mPrimaryBouncerInteractor.updateResources(); } public void dump(PrintWriter pw) { @@ -1494,11 +1393,6 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb pw.println(" " + callback); } - if (mPrimaryBouncer != null) { - pw.println("PrimaryBouncer:"); - mPrimaryBouncer.dump(pw); - } - if (mOccludingAppBiometricUI != null) { pw.println("mOccludingAppBiometricUI:"); mOccludingAppBiometricUI.dump(pw); @@ -1548,11 +1442,6 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb } } - @Nullable - public KeyguardBouncer getPrimaryBouncer() { - return mPrimaryBouncer; - } - /** * For any touches on the NPVC, show the primary bouncer if the alternate bouncer is currently * showing. @@ -1571,11 +1460,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb /** Update keyguard position based on a tapped X coordinate. */ public void updateKeyguardPosition(float x) { - if (mPrimaryBouncer != null) { - mPrimaryBouncer.updateKeyguardPosition(x); - } else { - mPrimaryBouncerInteractor.setKeyguardPosition(x); - } + mPrimaryBouncerInteractor.setKeyguardPosition(x); } private static class DismissWithActionRequest { @@ -1615,56 +1500,35 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb * Returns if bouncer expansion is between 0 and 1 non-inclusive. */ public boolean isPrimaryBouncerInTransit() { - if (mPrimaryBouncer != null) { - return mPrimaryBouncer.inTransit(); - } else { - return mPrimaryBouncerInteractor.isInTransit(); - } + return mPrimaryBouncerInteractor.isInTransit(); } /** * Returns if bouncer is showing */ public boolean primaryBouncerIsShowing() { - if (mPrimaryBouncer != null) { - return mPrimaryBouncer.isShowing(); - } else { - return mPrimaryBouncerInteractor.isFullyShowing(); - } + return mPrimaryBouncerInteractor.isFullyShowing(); } /** * Returns if bouncer is scrimmed */ public boolean primaryBouncerIsScrimmed() { - if (mPrimaryBouncer != null) { - return mPrimaryBouncer.isScrimmed(); - } else { - return mPrimaryBouncerInteractor.isScrimmed(); - } + return mPrimaryBouncerInteractor.isScrimmed(); } /** * Returns if bouncer is animating away */ public boolean bouncerIsAnimatingAway() { - if (mPrimaryBouncer != null) { - return mPrimaryBouncer.isAnimatingAway(); - } else { - return mPrimaryBouncerInteractor.isAnimatingAway(); - } - + return mPrimaryBouncerInteractor.isAnimatingAway(); } /** * Returns if bouncer will dismiss with action */ public boolean primaryBouncerWillDismissWithAction() { - if (mPrimaryBouncer != null) { - return mPrimaryBouncer.willDismissWithAction(); - } else { - return mPrimaryBouncerInteractor.willDismissWithAction(); - } + return mPrimaryBouncerInteractor.willDismissWithAction(); } /** diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsKeyguardViewControllerBaseTest.java b/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsKeyguardViewControllerBaseTest.java index 9c32c38e665cf..498cc2926a718 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsKeyguardViewControllerBaseTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsKeyguardViewControllerBaseTest.java @@ -37,7 +37,6 @@ import com.android.systemui.shade.ShadeExpansionChangeEvent; import com.android.systemui.shade.ShadeExpansionListener; import com.android.systemui.shade.ShadeExpansionStateManager; import com.android.systemui.statusbar.LockscreenShadeTransitionController; -import com.android.systemui.statusbar.phone.KeyguardBouncer; import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; import com.android.systemui.statusbar.phone.SystemUIDialogManager; import com.android.systemui.statusbar.phone.UnlockedScreenOffAnimationController; @@ -71,7 +70,6 @@ public class UdfpsKeyguardViewControllerBaseTest extends SysuiTestCase { protected @Mock SystemUIDialogManager mDialogManager; protected @Mock UdfpsController mUdfpsController; protected @Mock ActivityLaunchAnimator mActivityLaunchAnimator; - protected @Mock KeyguardBouncer mBouncer; protected @Mock PrimaryBouncerInteractor mPrimaryBouncerInteractor; protected @Mock AlternateBouncerInteractor mAlternateBouncerInteractor; @@ -152,8 +150,6 @@ public class UdfpsKeyguardViewControllerBaseTest extends SysuiTestCase { mFeatureFlags.set(Flags.MODERN_BOUNCER, useModernBouncer); mFeatureFlags.set(Flags.MODERN_ALTERNATE_BOUNCER, useModernBouncer); mFeatureFlags.set(Flags.UDFPS_NEW_TOUCH_DETECTION, useExpandedOverlay); - when(mStatusBarKeyguardViewManager.getPrimaryBouncer()).thenReturn( - useModernBouncer ? null : mBouncer); UdfpsKeyguardViewController controller = new UdfpsKeyguardViewController( mView, mStatusBarStateController, diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsKeyguardViewControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsKeyguardViewControllerTest.java index 7715f7fc5dc90..f437a8f009f81 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsKeyguardViewControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/UdfpsKeyguardViewControllerTest.java @@ -32,24 +32,17 @@ import android.view.MotionEvent; import androidx.test.filters.SmallTest; -import com.android.systemui.keyguard.domain.interactor.PrimaryBouncerCallbackInteractor.PrimaryBouncerExpansionCallback; import com.android.systemui.shade.ShadeExpansionListener; import com.android.systemui.statusbar.StatusBarState; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; @SmallTest @RunWith(AndroidTestingRunner.class) @TestableLooper.RunWithLooper(setAsMainLooper = true) public class UdfpsKeyguardViewControllerTest extends UdfpsKeyguardViewControllerBaseTest { - private @Captor ArgumentCaptor - mBouncerExpansionCallbackCaptor; - private PrimaryBouncerExpansionCallback mBouncerExpansionCallback; - @Override public UdfpsKeyguardViewController createUdfpsKeyguardViewController() { return createUdfpsKeyguardViewController(/* useModernBouncer */ false, @@ -62,11 +55,9 @@ public class UdfpsKeyguardViewControllerTest extends UdfpsKeyguardViewController captureStatusBarStateListeners(); sendStatusBarStateChanged(StatusBarState.KEYGUARD); - captureBouncerExpansionCallback(); when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(true); when(mStatusBarKeyguardViewManager.primaryBouncerIsOrWillBeShowing()).thenReturn(true); - mBouncerExpansionCallback.onVisibilityChanged(true); - + when(mView.getUnpausedAlpha()).thenReturn(0); assertTrue(mController.shouldPauseAuth()); } @@ -304,11 +295,6 @@ public class UdfpsKeyguardViewControllerTest extends UdfpsKeyguardViewController verify(mView, atLeastOnce()).setPauseAuth(false); } - private void captureBouncerExpansionCallback() { - verify(mBouncer).addBouncerExpansionCallback(mBouncerExpansionCallbackCaptor.capture()); - mBouncerExpansionCallback = mBouncerExpansionCallbackCaptor.getValue(); - } - @Test // TODO(b/259264861): Tracking Bug public void testUdfpsExpandedOverlayOn() { diff --git a/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayContainerViewControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayContainerViewControllerTest.java index ff883eb16bdec..3d9afacfadc90 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayContainerViewControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayContainerViewControllerTest.java @@ -39,8 +39,6 @@ import com.android.systemui.dreams.complication.ComplicationHostViewController; import com.android.systemui.keyguard.domain.interactor.PrimaryBouncerCallbackInteractor; import com.android.systemui.keyguard.domain.interactor.PrimaryBouncerCallbackInteractor.PrimaryBouncerExpansionCallback; import com.android.systemui.statusbar.BlurUtils; -import com.android.systemui.statusbar.phone.KeyguardBouncer; -import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; import org.junit.Before; import org.junit.Test; @@ -80,12 +78,6 @@ public class DreamOverlayContainerViewControllerTest extends SysuiTestCase { @Mock BlurUtils mBlurUtils; - @Mock - StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; - - @Mock - KeyguardBouncer mBouncer; - @Mock ViewRootImpl mViewRoot; @@ -106,7 +98,6 @@ public class DreamOverlayContainerViewControllerTest extends SysuiTestCase { when(mDreamOverlayContainerView.getResources()).thenReturn(mResources); when(mDreamOverlayContainerView.getViewTreeObserver()).thenReturn(mViewTreeObserver); - when(mStatusBarKeyguardViewManager.getPrimaryBouncer()).thenReturn(mBouncer); when(mDreamOverlayContainerView.getViewRootImpl()).thenReturn(mViewRoot); mController = new DreamOverlayContainerViewController( @@ -114,7 +105,6 @@ public class DreamOverlayContainerViewControllerTest extends SysuiTestCase { mComplicationHostViewController, mDreamOverlayContentView, mDreamOverlayStatusBarViewController, - mStatusBarKeyguardViewManager, mBlurUtils, mHandler, mResources, @@ -170,7 +160,8 @@ public class DreamOverlayContainerViewControllerTest extends SysuiTestCase { final ArgumentCaptor bouncerExpansionCaptor = ArgumentCaptor.forClass(PrimaryBouncerExpansionCallback.class); mController.onViewAttached(); - verify(mBouncer).addBouncerExpansionCallback(bouncerExpansionCaptor.capture()); + verify(mPrimaryBouncerCallbackInteractor).addBouncerExpansionCallback( + bouncerExpansionCaptor.capture()); bouncerExpansionCaptor.getValue().onExpansionChanged(0.5f); verify(mBlurUtils, never()).applyBlur(eq(mViewRoot), anyInt(), eq(false)); @@ -181,7 +172,8 @@ public class DreamOverlayContainerViewControllerTest extends SysuiTestCase { final ArgumentCaptor bouncerExpansionCaptor = ArgumentCaptor.forClass(PrimaryBouncerExpansionCallback.class); mController.onViewAttached(); - verify(mBouncer).addBouncerExpansionCallback(bouncerExpansionCaptor.capture()); + verify(mPrimaryBouncerCallbackInteractor).addBouncerExpansionCallback( + bouncerExpansionCaptor.capture()); final float blurRadius = 1337f; when(mBlurUtils.blurRadiusOfRatio(anyFloat())).thenReturn(blurRadius); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardBouncerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardBouncerTest.java deleted file mode 100644 index 2f495355df407..0000000000000 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardBouncerTest.java +++ /dev/null @@ -1,526 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package com.android.systemui.statusbar.phone; - -import static com.android.systemui.keyguard.shared.constants.KeyguardBouncerConstants.EXPANSION_HIDDEN; -import static com.android.systemui.keyguard.shared.constants.KeyguardBouncerConstants.EXPANSION_VISIBLE; - -import static com.google.common.truth.Truth.assertThat; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyFloat; -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.reset; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; - -import android.content.res.ColorStateList; -import android.graphics.Color; -import android.hardware.biometrics.BiometricSourceType; -import android.os.Handler; -import android.testing.AndroidTestingRunner; -import android.testing.TestableLooper; -import android.view.View; -import android.view.ViewGroup; -import android.widget.FrameLayout; - -import androidx.test.filters.SmallTest; - -import com.android.keyguard.KeyguardHostViewController; -import com.android.keyguard.KeyguardSecurityModel; -import com.android.keyguard.KeyguardUpdateMonitor; -import com.android.keyguard.ViewMediatorCallback; -import com.android.keyguard.dagger.KeyguardBouncerComponent; -import com.android.systemui.DejankUtils; -import com.android.systemui.SysuiTestCase; -import com.android.systemui.classifier.FalsingCollector; -import com.android.systemui.keyguard.DismissCallbackRegistry; -import com.android.systemui.keyguard.domain.interactor.PrimaryBouncerCallbackInteractor.PrimaryBouncerExpansionCallback; -import com.android.systemui.plugins.ActivityStarter.OnDismissAction; -import com.android.systemui.statusbar.policy.KeyguardStateController; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; - -@SmallTest -@RunWith(AndroidTestingRunner.class) -@TestableLooper.RunWithLooper -public class KeyguardBouncerTest extends SysuiTestCase { - - @Mock - private FalsingCollector mFalsingCollector; - @Mock - private ViewMediatorCallback mViewMediatorCallback; - @Mock - private DismissCallbackRegistry mDismissCallbackRegistry; - @Mock - private KeyguardHostViewController mKeyguardHostViewController; - @Mock - private PrimaryBouncerExpansionCallback mExpansionCallback; - @Mock - private KeyguardUpdateMonitor mKeyguardUpdateMonitor; - @Mock - private KeyguardStateController mKeyguardStateController; - @Mock - private KeyguardBypassController mKeyguardBypassController; - @Mock - private Handler mHandler; - @Mock - private KeyguardSecurityModel mKeyguardSecurityModel; - @Mock - private KeyguardBouncerComponent.Factory mKeyguardBouncerComponentFactory; - @Mock - private KeyguardBouncerComponent mKeyguardBouncerComponent; - private ViewGroup mContainer; - @Rule - public MockitoRule mRule = MockitoJUnit.rule(); - private Integer mRootVisibility = View.INVISIBLE; - private KeyguardBouncer mBouncer; - - @Before - public void setup() { - allowTestableLooperAsMainThread(); - when(mKeyguardSecurityModel.getSecurityMode(anyInt())) - .thenReturn(KeyguardSecurityModel.SecurityMode.None); - DejankUtils.setImmediate(true); - - mContainer = spy(new FrameLayout(getContext())); - when(mKeyguardBouncerComponentFactory.create(mContainer)).thenReturn( - mKeyguardBouncerComponent); - when(mKeyguardBouncerComponent.getKeyguardHostViewController()) - .thenReturn(mKeyguardHostViewController); - - mBouncer = new KeyguardBouncer.Factory(getContext(), mViewMediatorCallback, - mDismissCallbackRegistry, mFalsingCollector, - mKeyguardStateController, mKeyguardUpdateMonitor, - mKeyguardBypassController, mHandler, mKeyguardSecurityModel, - mKeyguardBouncerComponentFactory) - .create(mContainer, mExpansionCallback); - } - - @Test - public void testInflateView_doesntCrash() { - mBouncer.inflateView(); - } - - @Test - public void testShow_notifiesFalsingManager() { - mBouncer.show(true); - verify(mFalsingCollector).onBouncerShown(); - - mBouncer.show(true, false); - verifyNoMoreInteractions(mFalsingCollector); - } - - /** - * Regression test: Invisible bouncer when occluded. - */ - @Test - public void testShow_bouncerIsVisible() { - // Expand notification panel as if we were in the keyguard. - mBouncer.ensureView(); - mBouncer.setExpansion(1); - - reset(mKeyguardHostViewController); - - mBouncer.show(true); - verify(mKeyguardHostViewController).setExpansion(0); - } - - @Test - public void testShow_notifiesVisibility() { - mBouncer.show(true); - verify(mKeyguardStateController).notifyBouncerShowing(eq(true)); - verify(mExpansionCallback).onStartingToShow(); - - // Not called again when visible - reset(mViewMediatorCallback); - mBouncer.show(true); - verifyNoMoreInteractions(mViewMediatorCallback); - } - - @Test - public void testShow_triesToDismissKeyguard() { - mBouncer.show(true); - verify(mKeyguardHostViewController).dismiss(anyInt()); - } - - @Test - public void testShow_resetsSecuritySelection() { - mBouncer.show(false); - verify(mKeyguardHostViewController, never()).showPrimarySecurityScreen(); - - mBouncer.hide(false); - mBouncer.show(true); - verify(mKeyguardHostViewController).showPrimarySecurityScreen(); - } - - @Test - public void testShow_animatesKeyguardView() { - mBouncer.show(true); - verify(mKeyguardHostViewController).appear(anyInt()); - } - - @Test - public void testShow_showsErrorMessage() { - final String errorMessage = "an error message"; - when(mViewMediatorCallback.consumeCustomMessage()).thenReturn(errorMessage); - mBouncer.show(true); - verify(mKeyguardHostViewController).showErrorMessage(eq(errorMessage)); - } - - @Test - public void testSetExpansion_notifiesFalsingManager() { - mBouncer.ensureView(); - mBouncer.setExpansion(0.5f); - - mBouncer.setExpansion(EXPANSION_HIDDEN); - verify(mFalsingCollector).onBouncerHidden(); - verify(mExpansionCallback).onFullyHidden(); - - mBouncer.setExpansion(EXPANSION_VISIBLE); - verify(mFalsingCollector).onBouncerShown(); - verify(mExpansionCallback).onFullyShown(); - - verify(mExpansionCallback, never()).onStartingToHide(); - verify(mKeyguardHostViewController, never()).onStartingToHide(); - mBouncer.setExpansion(0.9f); - verify(mExpansionCallback).onStartingToHide(); - verify(mKeyguardHostViewController).onStartingToHide(); - } - - @Test - public void testSetExpansion_notifiesKeyguardView() { - mBouncer.ensureView(); - mBouncer.setExpansion(0.1f); - - mBouncer.setExpansion(0); - verify(mKeyguardHostViewController).onResume(); - verify(mContainer).announceForAccessibility(any()); - } - - @Test - public void show_notifiesKeyguardViewController() { - mBouncer.ensureView(); - - mBouncer.show(/* resetSecuritySelection= */ false); - - verify(mKeyguardHostViewController).onBouncerVisibilityChanged(View.VISIBLE); - } - - @Test - public void testHide_notifiesFalsingManager() { - mBouncer.hide(false); - verify(mFalsingCollector).onBouncerHidden(); - } - - @Test - public void testHide_notifiesVisibility() { - mBouncer.hide(false); - verify(mKeyguardStateController).notifyBouncerShowing(eq(false)); - } - - @Test - public void testHide_notifiesDismissCallbackIfVisible() { - mBouncer.hide(false); - verifyZeroInteractions(mDismissCallbackRegistry); - mBouncer.show(false); - mBouncer.hide(false); - verify(mDismissCallbackRegistry).notifyDismissCancelled(); - } - - @Test - public void testHide_notShowingAnymore() { - mBouncer.ensureView(); - mBouncer.show(false /* resetSecuritySelection */); - mBouncer.hide(false /* destroyViews */); - Assert.assertFalse("Not showing", mBouncer.isShowing()); - } - - @Test - public void testShowPromptReason_propagates() { - mBouncer.ensureView(); - mBouncer.showPromptReason(1); - verify(mKeyguardHostViewController).showPromptReason(eq(1)); - } - - @Test - public void testShowMessage_propagates() { - final String message = "a message"; - mBouncer.ensureView(); - mBouncer.showMessage(message, ColorStateList.valueOf(Color.GREEN)); - verify(mKeyguardHostViewController).showMessage( - eq(message), eq(ColorStateList.valueOf(Color.GREEN))); - } - - @Test - public void testShowOnDismissAction_showsBouncer() { - final OnDismissAction dismissAction = () -> false; - final Runnable cancelAction = () -> {}; - mBouncer.showWithDismissAction(dismissAction, cancelAction); - verify(mKeyguardHostViewController).setOnDismissAction(dismissAction, cancelAction); - Assert.assertTrue("Should be showing", mBouncer.isShowing()); - } - - @Test - public void testStartPreHideAnimation_notifiesView() { - final boolean[] ran = {false}; - final Runnable r = () -> ran[0] = true; - mBouncer.startPreHideAnimation(r); - Assert.assertTrue("Callback should have been invoked", ran[0]); - - ran[0] = false; - mBouncer.ensureView(); - mBouncer.startPreHideAnimation(r); - verify(mKeyguardHostViewController).startDisappearAnimation(r); - Assert.assertFalse("Callback should have been deferred", ran[0]); - } - - @Test - public void testIsShowing_animated() { - Assert.assertFalse("Show wasn't invoked yet", mBouncer.isShowing()); - mBouncer.show(true /* reset */); - Assert.assertTrue("Should be showing", mBouncer.isShowing()); - } - - @Test - public void testIsShowing_forSwipeUp() { - mBouncer.setExpansion(1f); - mBouncer.show(true /* reset */, false /* animated */); - Assert.assertFalse("Should only be showing after collapsing notification panel", - mBouncer.isShowing()); - mBouncer.setExpansion(0f); - Assert.assertTrue("Should be showing", mBouncer.isShowing()); - } - - @Test - public void testSetExpansion() { - mBouncer.ensureView(); - mBouncer.setExpansion(0.5f); - verify(mKeyguardHostViewController).setExpansion(0.5f); - } - - @Test - public void testIsFullscreenBouncer_asksKeyguardView() { - mBouncer.ensureView(); - mBouncer.isFullscreenBouncer(); - verify(mKeyguardHostViewController).getCurrentSecurityMode(); - } - - @Test - public void testIsHiding_preHideOrHide() { - Assert.assertFalse("Should not be hiding on initial state", mBouncer.isAnimatingAway()); - mBouncer.startPreHideAnimation(null /* runnable */); - Assert.assertTrue("Should be hiding during pre-hide", mBouncer.isAnimatingAway()); - mBouncer.hide(false /* destroyView */); - Assert.assertFalse("Should be hidden after hide()", mBouncer.isAnimatingAway()); - } - - @Test - public void testIsHiding_skipsTranslation() { - mBouncer.show(false /* reset */); - reset(mKeyguardHostViewController); - mBouncer.startPreHideAnimation(null /* runnable */); - mBouncer.setExpansion(0.5f); - verify(mKeyguardHostViewController, never()).setExpansion(anyFloat()); - } - - @Test - public void testIsSecure() { - mBouncer.ensureView(); - for (KeyguardSecurityModel.SecurityMode mode : KeyguardSecurityModel.SecurityMode.values()){ - reset(mKeyguardSecurityModel); - when(mKeyguardSecurityModel.getSecurityMode(anyInt())).thenReturn(mode); - Assert.assertEquals("Security doesn't match for mode: " + mode, - mBouncer.isSecure(), mode != KeyguardSecurityModel.SecurityMode.None); - } - } - - @Test - public void testIsShowingScrimmed_true() { - doAnswer(invocation -> { - assertThat(mBouncer.isScrimmed()).isTrue(); - return null; - }).when(mExpansionCallback).onFullyShown(); - mBouncer.show(false /* resetSecuritySelection */, true /* animate */); - assertThat(mBouncer.isScrimmed()).isTrue(); - mBouncer.hide(false /* destroyView */); - assertThat(mBouncer.isScrimmed()).isFalse(); - } - - @Test - public void testIsShowingScrimmed_false() { - doAnswer(invocation -> { - assertThat(mBouncer.isScrimmed()).isFalse(); - return null; - }).when(mExpansionCallback).onFullyShown(); - mBouncer.show(false /* resetSecuritySelection */, false /* animate */); - assertThat(mBouncer.isScrimmed()).isFalse(); - } - - @Test - public void testWillDismissWithAction() { - mBouncer.ensureView(); - Assert.assertFalse("Action not set yet", mBouncer.willDismissWithAction()); - when(mKeyguardHostViewController.hasDismissActions()).thenReturn(true); - Assert.assertTrue("Action should exist", mBouncer.willDismissWithAction()); - } - - @Test - public void testShow_delaysIfFaceAuthIsRunning() { - when(mKeyguardUpdateMonitor.isUnlockingWithBiometricAllowed(BiometricSourceType.FACE)) - .thenReturn(true); - when(mKeyguardStateController.isFaceAuthEnabled()).thenReturn(true); - mBouncer.show(true /* reset */); - - ArgumentCaptor showRunnable = ArgumentCaptor.forClass(Runnable.class); - verify(mHandler).postDelayed(showRunnable.capture(), - eq(KeyguardBouncer.BOUNCER_FACE_DELAY)); - - mBouncer.hide(false /* destroyView */); - verify(mHandler).removeCallbacks(eq(showRunnable.getValue())); - } - - @Test - public void testShow_doesNotDelaysIfFaceAuthIsNotAllowed() { - when(mKeyguardStateController.isFaceAuthEnabled()).thenReturn(true); - when(mKeyguardUpdateMonitor.isUnlockingWithBiometricAllowed(BiometricSourceType.FACE)) - .thenReturn(false); - mBouncer.show(true /* reset */); - - verify(mHandler, never()).postDelayed(any(), anyLong()); - } - - @Test - public void testShow_delaysIfFaceAuthIsRunning_unlessBypassEnabled() { - when(mKeyguardStateController.isFaceAuthEnabled()).thenReturn(true); - when(mKeyguardBypassController.getBypassEnabled()).thenReturn(true); - mBouncer.show(true /* reset */); - - verify(mHandler, never()).postDelayed(any(), anyLong()); - } - - @Test - public void testShow_delaysIfFaceAuthIsRunning_unlessFingerprintEnrolled() { - when(mKeyguardStateController.isFaceAuthEnabled()).thenReturn(true); - when(mKeyguardUpdateMonitor.getCachedIsUnlockWithFingerprintPossible(0)) - .thenReturn(true); - mBouncer.show(true /* reset */); - - verify(mHandler, never()).postDelayed(any(), anyLong()); - } - - @Test - public void testRegisterUpdateMonitorCallback() { - verify(mKeyguardUpdateMonitor).registerCallback(any()); - } - - @Test - public void testInTransit_whenTranslation() { - mBouncer.show(true); - mBouncer.setExpansion(EXPANSION_HIDDEN); - assertThat(mBouncer.inTransit()).isFalse(); - mBouncer.setExpansion(0.5f); - assertThat(mBouncer.inTransit()).isTrue(); - mBouncer.setExpansion(EXPANSION_VISIBLE); - assertThat(mBouncer.inTransit()).isFalse(); - } - - @Test - public void testUpdateResources_delegatesToRootView() { - mBouncer.ensureView(); - mBouncer.updateResources(); - - // This is mocked, so won't pick up on the call to updateResources via - // mKeyguardViewController.init(), only updateResources above. - verify(mKeyguardHostViewController).updateResources(); - } - - @Test - public void testUpdateKeyguardPosition_delegatesToRootView() { - mBouncer.ensureView(); - mBouncer.updateKeyguardPosition(1.0f); - - verify(mKeyguardHostViewController).updateKeyguardPosition(1.0f); - } - - @Test - public void testExpansion_notifiesCallback() { - mBouncer.ensureView(); - mBouncer.setExpansion(0.5f); - - final PrimaryBouncerExpansionCallback callback = - mock(PrimaryBouncerExpansionCallback.class); - mBouncer.addBouncerExpansionCallback(callback); - - mBouncer.setExpansion(EXPANSION_HIDDEN); - verify(callback).onFullyHidden(); - verify(callback).onExpansionChanged(EXPANSION_HIDDEN); - - Mockito.clearInvocations(callback); - mBouncer.setExpansion(EXPANSION_VISIBLE); - verify(callback).onFullyShown(); - verify(callback).onExpansionChanged(EXPANSION_VISIBLE); - - Mockito.clearInvocations(callback); - float bouncerHideAmount = 0.9f; - // Ensure the callback only triggers once despite multiple calls to setExpansion - // with the same value. - mBouncer.setExpansion(bouncerHideAmount); - mBouncer.setExpansion(bouncerHideAmount); - verify(callback, times(1)).onStartingToHide(); - verify(callback, times(1)).onExpansionChanged(bouncerHideAmount); - - Mockito.clearInvocations(callback); - mBouncer.removeBouncerExpansionCallback(callback); - bouncerHideAmount = 0.5f; - mBouncer.setExpansion(bouncerHideAmount); - verify(callback, never()).onExpansionChanged(bouncerHideAmount); - } - - @Test - public void testOnResumeCalledForFullscreenBouncerOnSecondShow() { - // GIVEN a security mode which requires fullscreen bouncer - when(mKeyguardSecurityModel.getSecurityMode(anyInt())) - .thenReturn(KeyguardSecurityModel.SecurityMode.SimPin); - mBouncer.show(true); - - // WHEN a second call to show occurs, the bouncer will already by visible - reset(mKeyguardHostViewController); - mBouncer.show(true); - - // THEN ensure the ViewController is told to resume - verify(mKeyguardHostViewController).onResume(); - } -} diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java index 1ba0a36fb05dc..d8446f4721b31 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java @@ -16,7 +16,6 @@ package com.android.systemui.statusbar.phone; -import static com.android.systemui.flags.Flags.MODERN_BOUNCER; import static com.android.systemui.keyguard.shared.constants.KeyguardBouncerConstants.EXPANSION_HIDDEN; import static com.android.systemui.keyguard.shared.constants.KeyguardBouncerConstants.EXPANSION_VISIBLE; @@ -109,7 +108,6 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase { @Mock private KeyguardUpdateMonitor mKeyguardUpdateMonitor; @Mock private View mNotificationContainer; @Mock private KeyguardBypassController mBypassController; - @Mock private KeyguardBouncer.Factory mKeyguardBouncerFactory; @Mock private KeyguardMessageAreaController.Factory mKeyguardMessageAreaFactory; @Mock private KeyguardMessageAreaController mKeyguardMessageAreaController; @Mock private KeyguardMessageArea mKeyguardMessageArea; @@ -153,8 +151,6 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase { .isEnabled(Flags.WM_ENABLE_PREDICTIVE_BACK_BOUNCER_ANIM)) .thenReturn(true); - when(mFeatureFlags.isEnabled(MODERN_BOUNCER)).thenReturn(true); - mStatusBarKeyguardViewManager = new StatusBarKeyguardViewManager( getContext(), @@ -169,7 +165,6 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase { mock(NotificationShadeWindowController.class), mKeyguardStateController, mock(NotificationMediaManager.class), - mKeyguardBouncerFactory, mKeyguardMessageAreaFactory, Optional.of(mSysUiUnfoldComponent), () -> mShadeController, @@ -660,7 +655,6 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase { mock(NotificationShadeWindowController.class), mKeyguardStateController, mock(NotificationMediaManager.class), - mKeyguardBouncerFactory, mKeyguardMessageAreaFactory, Optional.of(mSysUiUnfoldComponent), () -> mShadeController, diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest_Old.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest_Old.java deleted file mode 100644 index 55ab6812da911..0000000000000 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest_Old.java +++ /dev/null @@ -1,581 +0,0 @@ -/* - * Copyright (C) 2018 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.systemui.statusbar.phone; - -import static com.android.systemui.flags.Flags.MODERN_BOUNCER; -import static com.android.systemui.keyguard.shared.constants.KeyguardBouncerConstants.EXPANSION_HIDDEN; -import static com.android.systemui.keyguard.shared.constants.KeyguardBouncerConstants.EXPANSION_VISIBLE; - -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyBoolean; -import static org.mockito.ArgumentMatchers.anyFloat; -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.clearInvocations; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.reset; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import android.testing.AndroidTestingRunner; -import android.testing.TestableLooper; -import android.view.View; -import android.view.ViewGroup; -import android.view.ViewRootImpl; -import android.window.OnBackInvokedCallback; -import android.window.OnBackInvokedDispatcher; -import android.window.WindowOnBackInvokedDispatcher; - -import androidx.test.filters.SmallTest; - -import com.android.internal.util.LatencyTracker; -import com.android.internal.widget.LockPatternUtils; -import com.android.keyguard.KeyguardMessageArea; -import com.android.keyguard.KeyguardMessageAreaController; -import com.android.keyguard.KeyguardSecurityModel; -import com.android.keyguard.KeyguardUpdateMonitor; -import com.android.keyguard.ViewMediatorCallback; -import com.android.systemui.SysuiTestCase; -import com.android.systemui.dock.DockManager; -import com.android.systemui.dreams.DreamOverlayStateController; -import com.android.systemui.flags.FeatureFlags; -import com.android.systemui.keyguard.data.BouncerView; -import com.android.systemui.keyguard.data.BouncerViewDelegate; -import com.android.systemui.keyguard.domain.interactor.AlternateBouncerInteractor; -import com.android.systemui.keyguard.domain.interactor.PrimaryBouncerCallbackInteractor; -import com.android.systemui.keyguard.domain.interactor.PrimaryBouncerCallbackInteractor.PrimaryBouncerExpansionCallback; -import com.android.systemui.keyguard.domain.interactor.PrimaryBouncerInteractor; -import com.android.systemui.navigationbar.NavigationModeController; -import com.android.systemui.plugins.ActivityStarter.OnDismissAction; -import com.android.systemui.shade.NotificationPanelViewController; -import com.android.systemui.shade.ShadeController; -import com.android.systemui.shade.ShadeExpansionChangeEvent; -import com.android.systemui.shade.ShadeExpansionStateManager; -import com.android.systemui.statusbar.NotificationMediaManager; -import com.android.systemui.statusbar.NotificationShadeWindowController; -import com.android.systemui.statusbar.StatusBarState; -import com.android.systemui.statusbar.SysuiStatusBarStateController; -import com.android.systemui.statusbar.policy.ConfigurationController; -import com.android.systemui.unfold.SysUIUnfoldComponent; - -import com.google.common.truth.Truth; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; - -import java.util.Optional; - -/** - * StatusBarKeyguardViewManager Test with deprecated KeyguardBouncer.java. - * TODO: Delete when deleting {@link KeyguardBouncer} - */ -@SmallTest -@RunWith(AndroidTestingRunner.class) -@TestableLooper.RunWithLooper -public class StatusBarKeyguardViewManagerTest_Old extends SysuiTestCase { - private static final ShadeExpansionChangeEvent EXPANSION_EVENT = - expansionEvent(/* fraction= */ 0.5f, /* expanded= */ false, /* tracking= */ true); - - @Mock private ViewMediatorCallback mViewMediatorCallback; - @Mock private LockPatternUtils mLockPatternUtils; - @Mock private CentralSurfaces mCentralSurfaces; - @Mock private ViewGroup mContainer; - @Mock private NotificationPanelViewController mNotificationPanelView; - @Mock private BiometricUnlockController mBiometricUnlockController; - @Mock private SysuiStatusBarStateController mStatusBarStateController; - @Mock private KeyguardUpdateMonitor mKeyguardUpdateMonitor; - @Mock private View mNotificationContainer; - @Mock private KeyguardBypassController mBypassController; - @Mock private KeyguardBouncer.Factory mKeyguardBouncerFactory; - @Mock private KeyguardMessageAreaController.Factory mKeyguardMessageAreaFactory; - @Mock private KeyguardMessageAreaController mKeyguardMessageAreaController; - @Mock private KeyguardBouncer mPrimaryBouncer; - @Mock private KeyguardMessageArea mKeyguardMessageArea; - @Mock private ShadeController mShadeController; - @Mock private SysUIUnfoldComponent mSysUiUnfoldComponent; - @Mock private DreamOverlayStateController mDreamOverlayStateController; - @Mock private LatencyTracker mLatencyTracker; - @Mock private FeatureFlags mFeatureFlags; - @Mock private KeyguardSecurityModel mKeyguardSecurityModel; - @Mock private PrimaryBouncerCallbackInteractor mPrimaryBouncerCallbackInteractor; - @Mock private PrimaryBouncerInteractor mPrimaryBouncerInteractor; - @Mock private AlternateBouncerInteractor mAlternateBouncerInteractor; - @Mock private BouncerView mBouncerView; - @Mock private BouncerViewDelegate mBouncerViewDelegate; - - private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; - private PrimaryBouncerCallbackInteractor.PrimaryBouncerExpansionCallback - mBouncerExpansionCallback; - private FakeKeyguardStateController mKeyguardStateController = - spy(new FakeKeyguardStateController()); - - @Mock private ViewRootImpl mViewRootImpl; - @Mock private WindowOnBackInvokedDispatcher mOnBackInvokedDispatcher; - @Captor - private ArgumentCaptor mOnBackInvokedCallback; - - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - when(mKeyguardBouncerFactory.create( - any(ViewGroup.class), - any(PrimaryBouncerExpansionCallback.class))) - .thenReturn(mPrimaryBouncer); - when(mCentralSurfaces.getBouncerContainer()).thenReturn(mContainer); - when(mContainer.findViewById(anyInt())).thenReturn(mKeyguardMessageArea); - when(mKeyguardMessageAreaFactory.create(any(KeyguardMessageArea.class))) - .thenReturn(mKeyguardMessageAreaController); - when(mBouncerView.getDelegate()).thenReturn(mBouncerViewDelegate); - - mStatusBarKeyguardViewManager = - new StatusBarKeyguardViewManager( - getContext(), - mViewMediatorCallback, - mLockPatternUtils, - mStatusBarStateController, - mock(ConfigurationController.class), - mKeyguardUpdateMonitor, - mDreamOverlayStateController, - mock(NavigationModeController.class), - mock(DockManager.class), - mock(NotificationShadeWindowController.class), - mKeyguardStateController, - mock(NotificationMediaManager.class), - mKeyguardBouncerFactory, - mKeyguardMessageAreaFactory, - Optional.of(mSysUiUnfoldComponent), - () -> mShadeController, - mLatencyTracker, - mKeyguardSecurityModel, - mFeatureFlags, - mPrimaryBouncerCallbackInteractor, - mPrimaryBouncerInteractor, - mBouncerView, - mAlternateBouncerInteractor) { - @Override - public ViewRootImpl getViewRootImpl() { - return mViewRootImpl; - } - }; - when(mViewRootImpl.getOnBackInvokedDispatcher()) - .thenReturn(mOnBackInvokedDispatcher); - mStatusBarKeyguardViewManager.registerCentralSurfaces( - mCentralSurfaces, - mNotificationPanelView, - new ShadeExpansionStateManager(), - mBiometricUnlockController, - mNotificationContainer, - mBypassController); - mStatusBarKeyguardViewManager.show(null); - ArgumentCaptor callbackArgumentCaptor = - ArgumentCaptor.forClass(PrimaryBouncerExpansionCallback.class); - verify(mKeyguardBouncerFactory).create(any(ViewGroup.class), - callbackArgumentCaptor.capture()); - mBouncerExpansionCallback = callbackArgumentCaptor.getValue(); - } - - @Test - public void dismissWithAction_AfterKeyguardGoneSetToFalse() { - OnDismissAction action = () -> false; - Runnable cancelAction = () -> {}; - mStatusBarKeyguardViewManager.dismissWithAction( - action, cancelAction, false /* afterKeyguardGone */); - verify(mPrimaryBouncer).showWithDismissAction(eq(action), eq(cancelAction)); - } - - @Test - public void showBouncer_onlyWhenShowing() { - mStatusBarKeyguardViewManager.hide(0 /* startTime */, 0 /* fadeoutDuration */); - mStatusBarKeyguardViewManager.showPrimaryBouncer(true /* scrimmed */); - verify(mPrimaryBouncer, never()).show(anyBoolean(), anyBoolean()); - verify(mPrimaryBouncer, never()).show(anyBoolean()); - } - - @Test - public void showBouncer_notWhenBouncerAlreadyShowing() { - mStatusBarKeyguardViewManager.hide(0 /* startTime */, 0 /* fadeoutDuration */); - when(mPrimaryBouncer.isSecure()).thenReturn(true); - mStatusBarKeyguardViewManager.showPrimaryBouncer(true /* scrimmed */); - verify(mPrimaryBouncer, never()).show(anyBoolean(), anyBoolean()); - verify(mPrimaryBouncer, never()).show(anyBoolean()); - } - - @Test - public void showBouncer_showsTheBouncer() { - mStatusBarKeyguardViewManager.showPrimaryBouncer(true /* scrimmed */); - verify(mPrimaryBouncer).show(anyBoolean(), eq(true)); - } - - @Test - public void onPanelExpansionChanged_neverShowsDuringHintAnimation() { - when(mNotificationPanelView.isUnlockHintRunning()).thenReturn(true); - mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT); - verify(mPrimaryBouncer, never()).setExpansion(anyFloat()); - } - - @Test - public void onPanelExpansionChanged_propagatesToBouncerOnlyIfShowing() { - mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT); - verify(mPrimaryBouncer, never()).setExpansion(eq(0.5f)); - - when(mPrimaryBouncer.isShowing()).thenReturn(true); - mStatusBarKeyguardViewManager.onPanelExpansionChanged( - expansionEvent(/* fraction= */ 0.6f, /* expanded= */ false, /* tracking= */ true)); - verify(mPrimaryBouncer).setExpansion(eq(0.6f)); - } - - @Test - public void onPanelExpansionChanged_duplicateEventsAreIgnored() { - when(mPrimaryBouncer.isShowing()).thenReturn(true); - mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT); - verify(mPrimaryBouncer).setExpansion(eq(0.5f)); - - reset(mPrimaryBouncer); - mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT); - verify(mPrimaryBouncer, never()).setExpansion(eq(0.5f)); - } - - @Test - public void onPanelExpansionChanged_hideBouncer_afterKeyguardHidden() { - mStatusBarKeyguardViewManager.hide(0, 0); - when(mPrimaryBouncer.inTransit()).thenReturn(true); - - mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT); - verify(mPrimaryBouncer).setExpansion(eq(EXPANSION_HIDDEN)); - } - - @Test - public void onPanelExpansionChanged_showsBouncerWhenSwiping() { - mKeyguardStateController.setCanDismissLockScreen(false); - mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT); - verify(mPrimaryBouncer).show(eq(false), eq(false)); - - // But not when it's already visible - reset(mPrimaryBouncer); - when(mPrimaryBouncer.isShowing()).thenReturn(true); - mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT); - verify(mPrimaryBouncer, never()).show(eq(false), eq(false)); - - // Or animating away - reset(mPrimaryBouncer); - when(mPrimaryBouncer.isAnimatingAway()).thenReturn(true); - mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT); - verify(mPrimaryBouncer, never()).show(eq(false), eq(false)); - } - - @Test - public void onPanelExpansionChanged_neverTranslatesBouncerWhenWakeAndUnlock() { - when(mBiometricUnlockController.getMode()) - .thenReturn(BiometricUnlockController.MODE_WAKE_AND_UNLOCK); - mStatusBarKeyguardViewManager.onPanelExpansionChanged( - expansionEvent( - /* fraction= */ EXPANSION_VISIBLE, - /* expanded= */ true, - /* tracking= */ false)); - verify(mPrimaryBouncer, never()).setExpansion(anyFloat()); - } - - @Test - public void onPanelExpansionChanged_neverTranslatesBouncerWhenDismissBouncer() { - // Since KeyguardBouncer.EXPANSION_VISIBLE = 0 panel expansion, if the unlock is dismissing - // the bouncer, there may be an onPanelExpansionChanged(0) call to collapse the panel - // which would mistakenly cause the bouncer to show briefly before its visibility - // is set to hide. Therefore, we don't want to propagate panelExpansionChanged to the - // bouncer if the bouncer is dismissing as a result of a biometric unlock. - when(mBiometricUnlockController.getMode()) - .thenReturn(BiometricUnlockController.MODE_DISMISS_BOUNCER); - mStatusBarKeyguardViewManager.onPanelExpansionChanged( - expansionEvent( - /* fraction= */ EXPANSION_VISIBLE, - /* expanded= */ true, - /* tracking= */ false)); - verify(mPrimaryBouncer, never()).setExpansion(anyFloat()); - } - - @Test - public void onPanelExpansionChanged_neverTranslatesBouncerWhenOccluded() { - when(mKeyguardStateController.isOccluded()).thenReturn(true); - mStatusBarKeyguardViewManager.onPanelExpansionChanged( - expansionEvent( - /* fraction= */ EXPANSION_VISIBLE, - /* expanded= */ true, - /* tracking= */ false)); - verify(mPrimaryBouncer, never()).setExpansion(anyFloat()); - } - - @Test - public void onPanelExpansionChanged_neverTranslatesBouncerWhenShowBouncer() { - // Since KeyguardBouncer.EXPANSION_VISIBLE = 0 panel expansion, if the unlock is dismissing - // the bouncer, there may be an onPanelExpansionChanged(0) call to collapse the panel - // which would mistakenly cause the bouncer to show briefly before its visibility - // is set to hide. Therefore, we don't want to propagate panelExpansionChanged to the - // bouncer if the bouncer is dismissing as a result of a biometric unlock. - when(mBiometricUnlockController.getMode()) - .thenReturn(BiometricUnlockController.MODE_SHOW_BOUNCER); - mStatusBarKeyguardViewManager.onPanelExpansionChanged( - expansionEvent( - /* fraction= */ EXPANSION_VISIBLE, - /* expanded= */ true, - /* tracking= */ false)); - verify(mPrimaryBouncer, never()).setExpansion(anyFloat()); - } - - @Test - public void onPanelExpansionChanged_neverTranslatesBouncerWhenShadeLocked() { - when(mStatusBarStateController.getState()).thenReturn(StatusBarState.SHADE_LOCKED); - mStatusBarKeyguardViewManager.onPanelExpansionChanged( - expansionEvent( - /* fraction= */ EXPANSION_VISIBLE, - /* expanded= */ true, - /* tracking= */ false)); - verify(mPrimaryBouncer, never()).setExpansion(anyFloat()); - } - - @Test - public void setOccluded_animatesPanelExpansion_onlyIfBouncerHidden() { - mStatusBarKeyguardViewManager.setOccluded(false /* occluded */, true /* animated */); - verify(mCentralSurfaces).animateKeyguardUnoccluding(); - - when(mPrimaryBouncer.isShowing()).thenReturn(true); - clearInvocations(mCentralSurfaces); - mStatusBarKeyguardViewManager.setOccluded(false /* occluded */, true /* animated */); - verify(mCentralSurfaces, never()).animateKeyguardUnoccluding(); - } - - @Test - public void setOccluded_onKeyguardOccludedChangedCalled() { - clearInvocations(mKeyguardStateController); - clearInvocations(mKeyguardUpdateMonitor); - - mStatusBarKeyguardViewManager.setOccluded(false /* occluded */, false /* animated */); - verify(mKeyguardStateController).notifyKeyguardState(true, false); - - clearInvocations(mKeyguardUpdateMonitor); - clearInvocations(mKeyguardStateController); - - mStatusBarKeyguardViewManager.setOccluded(true /* occluded */, false /* animated */); - verify(mKeyguardStateController).notifyKeyguardState(true, true); - - clearInvocations(mKeyguardUpdateMonitor); - clearInvocations(mKeyguardStateController); - - mStatusBarKeyguardViewManager.setOccluded(false /* occluded */, false /* animated */); - verify(mKeyguardStateController).notifyKeyguardState(true, false); - } - - @Test - public void setOccluded_isInLaunchTransition_onKeyguardOccludedChangedCalled() { - mStatusBarKeyguardViewManager.show(null); - - mStatusBarKeyguardViewManager.setOccluded(true /* occluded */, false /* animated */); - verify(mKeyguardStateController).notifyKeyguardState(true, true); - } - - @Test - public void setOccluded_isLaunchingActivityOverLockscreen_onKeyguardOccludedChangedCalled() { - when(mCentralSurfaces.isLaunchingActivityOverLockscreen()).thenReturn(true); - mStatusBarKeyguardViewManager.show(null); - - mStatusBarKeyguardViewManager.setOccluded(true /* occluded */, false /* animated */); - verify(mKeyguardStateController).notifyKeyguardState(true, true); - } - - @Test - public void testHiding_cancelsGoneRunnable() { - OnDismissAction action = mock(OnDismissAction.class); - Runnable cancelAction = mock(Runnable.class); - mStatusBarKeyguardViewManager.dismissWithAction( - action, cancelAction, true /* afterKeyguardGone */); - - when(mPrimaryBouncer.isShowing()).thenReturn(false); - mStatusBarKeyguardViewManager.hideBouncer(true); - mStatusBarKeyguardViewManager.hide(0, 30); - verify(action, never()).onDismiss(); - verify(cancelAction).run(); - } - - @Test - public void testHidingBouncer_cancelsGoneRunnable() { - OnDismissAction action = mock(OnDismissAction.class); - Runnable cancelAction = mock(Runnable.class); - mStatusBarKeyguardViewManager.dismissWithAction( - action, cancelAction, true /* afterKeyguardGone */); - - when(mPrimaryBouncer.isShowing()).thenReturn(false); - mStatusBarKeyguardViewManager.hideBouncer(true); - - verify(action, never()).onDismiss(); - verify(cancelAction).run(); - } - - @Test - public void testHiding_doesntCancelWhenShowing() { - OnDismissAction action = mock(OnDismissAction.class); - Runnable cancelAction = mock(Runnable.class); - mStatusBarKeyguardViewManager.dismissWithAction( - action, cancelAction, true /* afterKeyguardGone */); - - mStatusBarKeyguardViewManager.hide(0, 30); - verify(action).onDismiss(); - verify(cancelAction, never()).run(); - } - - @Test - public void testBouncerIsOrWillBeShowing_whenBouncerIsInTransit() { - when(mPrimaryBouncer.isShowing()).thenReturn(false); - when(mPrimaryBouncer.inTransit()).thenReturn(true); - - assertTrue( - "Is or will be showing should be true when bouncer is in transit", - mStatusBarKeyguardViewManager.primaryBouncerIsOrWillBeShowing()); - } - - @Test - public void testUpdateResources_delegatesToBouncer() { - mStatusBarKeyguardViewManager.updateResources(); - - verify(mPrimaryBouncer).updateResources(); - } - - @Test - public void updateKeyguardPosition_delegatesToBouncer() { - mStatusBarKeyguardViewManager.updateKeyguardPosition(1.0f); - - verify(mPrimaryBouncer).updateKeyguardPosition(1.0f); - } - - @Test - public void testIsBouncerInTransit() { - when(mPrimaryBouncer.inTransit()).thenReturn(true); - Truth.assertThat(mStatusBarKeyguardViewManager.isPrimaryBouncerInTransit()).isTrue(); - when(mPrimaryBouncer.inTransit()).thenReturn(false); - Truth.assertThat(mStatusBarKeyguardViewManager.isPrimaryBouncerInTransit()).isFalse(); - mPrimaryBouncer = null; - Truth.assertThat(mStatusBarKeyguardViewManager.isPrimaryBouncerInTransit()).isFalse(); - } - - private static ShadeExpansionChangeEvent expansionEvent( - float fraction, boolean expanded, boolean tracking) { - return new ShadeExpansionChangeEvent( - fraction, expanded, tracking, /* dragDownPxAmount= */ 0f); - } - - @Test - public void testPredictiveBackCallback_registration() { - /* verify that a predictive back callback is registered when the bouncer becomes visible */ - mBouncerExpansionCallback.onVisibilityChanged(true); - verify(mOnBackInvokedDispatcher).registerOnBackInvokedCallback( - eq(OnBackInvokedDispatcher.PRIORITY_OVERLAY), - mOnBackInvokedCallback.capture()); - - /* verify that the same callback is unregistered when the bouncer becomes invisible */ - mBouncerExpansionCallback.onVisibilityChanged(false); - verify(mOnBackInvokedDispatcher).unregisterOnBackInvokedCallback( - eq(mOnBackInvokedCallback.getValue())); - } - - @Test - public void testPredictiveBackCallback_invocationHidesBouncer() { - mBouncerExpansionCallback.onVisibilityChanged(true); - /* capture the predictive back callback during registration */ - verify(mOnBackInvokedDispatcher).registerOnBackInvokedCallback( - eq(OnBackInvokedDispatcher.PRIORITY_OVERLAY), - mOnBackInvokedCallback.capture()); - - when(mPrimaryBouncer.isShowing()).thenReturn(true); - when(mCentralSurfaces.shouldKeyguardHideImmediately()).thenReturn(true); - /* invoke the back callback directly */ - mOnBackInvokedCallback.getValue().onBackInvoked(); - - /* verify that the bouncer will be hidden as a result of the invocation */ - verify(mCentralSurfaces).setBouncerShowing(eq(false)); - } - - @Test - public void testReportBouncerOnDreamWhenVisible() { - mBouncerExpansionCallback.onVisibilityChanged(true); - verify(mCentralSurfaces).setBouncerShowingOverDream(false); - Mockito.clearInvocations(mCentralSurfaces); - when(mDreamOverlayStateController.isOverlayActive()).thenReturn(true); - mBouncerExpansionCallback.onVisibilityChanged(true); - verify(mCentralSurfaces).setBouncerShowingOverDream(true); - } - - @Test - public void testReportBouncerOnDreamWhenNotVisible() { - mBouncerExpansionCallback.onVisibilityChanged(false); - verify(mCentralSurfaces).setBouncerShowingOverDream(false); - Mockito.clearInvocations(mCentralSurfaces); - when(mDreamOverlayStateController.isOverlayActive()).thenReturn(true); - mBouncerExpansionCallback.onVisibilityChanged(false); - verify(mCentralSurfaces).setBouncerShowingOverDream(false); - } - - @Test - public void flag_off_DoesNotCallBouncerInteractor() { - when(mFeatureFlags.isEnabled(MODERN_BOUNCER)).thenReturn(false); - mStatusBarKeyguardViewManager.hideBouncer(false); - verify(mPrimaryBouncerInteractor, never()).hide(); - } - - @Test - public void hideAlternateBouncer_beforeCentralSurfacesRegistered() { - mStatusBarKeyguardViewManager = - new StatusBarKeyguardViewManager( - getContext(), - mViewMediatorCallback, - mLockPatternUtils, - mStatusBarStateController, - mock(ConfigurationController.class), - mKeyguardUpdateMonitor, - mDreamOverlayStateController, - mock(NavigationModeController.class), - mock(DockManager.class), - mock(NotificationShadeWindowController.class), - mKeyguardStateController, - mock(NotificationMediaManager.class), - mKeyguardBouncerFactory, - mKeyguardMessageAreaFactory, - Optional.of(mSysUiUnfoldComponent), - () -> mShadeController, - mLatencyTracker, - mKeyguardSecurityModel, - mFeatureFlags, - mPrimaryBouncerCallbackInteractor, - mPrimaryBouncerInteractor, - mBouncerView, - mAlternateBouncerInteractor) { - @Override - public ViewRootImpl getViewRootImpl() { - return mViewRootImpl; - } - }; - - // the following call before registering centralSurfaces should NOT throw a NPE: - mStatusBarKeyguardViewManager.hideAlternateBouncer(true); - } -}