From 3fac0854c27c7d2feb23c1b99169e0a952088547 Mon Sep 17 00:00:00 2001 From: Beverly Date: Tue, 5 Oct 2021 20:05:31 -0400 Subject: [PATCH] Update dozing state on clock view attached Else, the clock may animate in at the wrong font weight. Test: atest AnimatableClockControllerTest Test: manually swipe away all notifications on LS, see the large clock animate in at full font weight Fixes: 201615075 Change-Id: I139e5a5c88551f23f99decff3e7ffc8bdaa5bba4 --- .../keyguard/AnimatableClockController.java | 30 ++-- .../KeyguardClockSwitchController.java | 13 +- .../KeyguardClockSwitchControllerTest.java | 3 +- .../AnimatableClockControllerTest.java | 144 ++++++++++++++++++ 4 files changed, 177 insertions(+), 13 deletions(-) create mode 100644 packages/SystemUI/tests/src/com/android/systemui/keyguard/AnimatableClockControllerTest.java diff --git a/packages/SystemUI/src/com/android/keyguard/AnimatableClockController.java b/packages/SystemUI/src/com/android/keyguard/AnimatableClockController.java index efcf40a662582..a383cab94c366 100644 --- a/packages/SystemUI/src/com/android/keyguard/AnimatableClockController.java +++ b/packages/SystemUI/src/com/android/keyguard/AnimatableClockController.java @@ -20,12 +20,16 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.res.Resources; import android.graphics.Color; import android.icu.text.NumberFormat; +import androidx.annotation.VisibleForTesting; + import com.android.settingslib.Utils; import com.android.systemui.R; import com.android.systemui.broadcast.BroadcastDispatcher; +import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.statusbar.phone.KeyguardBypassController; import com.android.systemui.statusbar.policy.BatteryController; @@ -67,20 +71,20 @@ public class AnimatableClockController extends ViewController mAttachCaptor = + ArgumentCaptor.forClass(View.OnAttachStateChangeListener.class); + private View.OnAttachStateChangeListener mAttachListener; + + @Captor private ArgumentCaptor mStatusBarStateCaptor; + private StatusBarStateController.StateListener mStatusBarStateCallback; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + mStaticMockSession = mockitoSession() + .mockStatic(Utils.class) + .strictness(Strictness.LENIENT) // it's ok if mocked classes aren't used + .startMocking(); + when(Utils.getColorAttrDefaultColor(anyObject(), anyInt())).thenReturn(0); + + mAnimatableClockController = new AnimatableClockController( + mClockView, + mStatusBarStateController, + mBroadcastDispatcher, + mBatteryController, + mKeyguardUpdateMonitor, + mBypassController, + mResources + ); + mAnimatableClockController.init(); + captureAttachListener(); + } + + @After + public void tearDown() { + mStaticMockSession.finishMocking(); + } + + @Test + public void testOnAttachedUpdatesDozeStateToTrue() { + // GIVEN dozing + when(mStatusBarStateController.isDozing()).thenReturn(true); + when(mStatusBarStateController.getDozeAmount()).thenReturn(1f); + + // WHEN the clock view gets attached + mAttachListener.onViewAttachedToWindow(mClockView); + + // THEN the clock controller updated its dozing state to true + assertTrue(mAnimatableClockController.isDozing()); + } + + @Test + public void testOnAttachedUpdatesDozeStateToFalse() { + // GIVEN not dozing + when(mStatusBarStateController.isDozing()).thenReturn(false); + when(mStatusBarStateController.getDozeAmount()).thenReturn(0f); + + // WHEN the clock view gets attached + mAttachListener.onViewAttachedToWindow(mClockView); + + // THEN the clock controller updated its dozing state to false + assertFalse(mAnimatableClockController.isDozing()); + } + + private void captureAttachListener() { + verify(mClockView).addOnAttachStateChangeListener(mAttachCaptor.capture()); + mAttachListener = mAttachCaptor.getValue(); + } +}