Fix NPE in Stepped Clock Animation
Bug: 274122173
Fixes: 274193808
Test: atest KeyguardClockSwitchControllerTest
Change-Id: Ia309c822b0179f7335b48f77acffb3048b4b0eac
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java
index b85b2b8..ba21780 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java
@@ -22,6 +22,7 @@
import static com.android.keyguard.KeyguardClockSwitch.LARGE;
import static com.android.keyguard.KeyguardClockSwitch.SMALL;
+import android.annotation.Nullable;
import android.database.ContentObserver;
import android.os.UserHandle;
import android.provider.Settings;
@@ -458,6 +459,7 @@
mView.setClock(clock, mStatusBarStateController.getState());
}
+ @Nullable
private ClockController getClock() {
return mClockEventController.getClock();
}
@@ -510,8 +512,10 @@
}
/** Gets the animations for the current clock. */
+ @Nullable
public ClockAnimations getClockAnimations() {
- return getClock().getAnimations();
+ ClockController clock = getClock();
+ return clock == null ? null : clock.getAnimations();
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java
index 36be442..19f4d80 100644
--- a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java
+++ b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java
@@ -158,6 +158,7 @@
import com.android.systemui.navigationbar.NavigationBarController;
import com.android.systemui.navigationbar.NavigationBarView;
import com.android.systemui.navigationbar.NavigationModeController;
+import com.android.systemui.plugins.ClockAnimations;
import com.android.systemui.plugins.FalsingManager;
import com.android.systemui.plugins.FalsingManager.FalsingTapListener;
import com.android.systemui.plugins.qs.QS;
@@ -1574,10 +1575,9 @@
transition.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
transition.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD);
- boolean customClockAnimation =
- mKeyguardStatusViewController.getClockAnimations() != null
- && mKeyguardStatusViewController.getClockAnimations()
- .getHasCustomPositionUpdatedAnimation();
+ ClockAnimations clockAnims = mKeyguardStatusViewController.getClockAnimations();
+ boolean customClockAnimation = clockAnims != null
+ && clockAnims.getHasCustomPositionUpdatedAnimation();
if (mFeatureFlags.isEnabled(Flags.STEP_CLOCK_ANIMATION) && customClockAnimation) {
// Find the clock, so we can exclude it from this transition.
@@ -5018,9 +5018,14 @@
Rect from = (Rect) startValues.values.get(PROP_BOUNDS);
Rect to = (Rect) endValues.values.get(PROP_BOUNDS);
- anim.addUpdateListener(
- animation -> mController.getClockAnimations().onPositionUpdated(
- from, to, animation.getAnimatedFraction()));
+ anim.addUpdateListener(animation -> {
+ ClockAnimations clockAnims = mController.getClockAnimations();
+ if (clockAnims == null) {
+ return;
+ }
+
+ clockAnims.onPositionUpdated(from, to, animation.getAnimatedFraction());
+ });
return anim;
}
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java
index a5f90f8..b15ac39 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java
@@ -17,6 +17,7 @@
package com.android.keyguard;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.eq;
@@ -365,6 +366,12 @@
assertEquals(View.VISIBLE, mFakeWeatherView.getVisibility());
}
+ @Test
+ public void testGetClockAnimations_nullClock_returnsNull() {
+ when(mClockEventController.getClock()).thenReturn(null);
+ assertNull(mController.getClockAnimations());
+ }
+
private void verifyAttachment(VerificationMode times) {
verify(mClockRegistry, times).registerClockChangeListener(
any(ClockRegistry.ClockChangeListener.class));