Merge "Fix NPE in Stepped Clock Animation" into tm-qpr-dev

This commit is contained in:
Hawkwood Glazier
2023-03-20 21:02:02 +00:00
committed by Android (Google) Code Review
3 changed files with 24 additions and 8 deletions

View File

@@ -22,6 +22,7 @@ import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
import static com.android.keyguard.KeyguardClockSwitch.LARGE; import static com.android.keyguard.KeyguardClockSwitch.LARGE;
import static com.android.keyguard.KeyguardClockSwitch.SMALL; import static com.android.keyguard.KeyguardClockSwitch.SMALL;
import android.annotation.Nullable;
import android.database.ContentObserver; import android.database.ContentObserver;
import android.os.UserHandle; import android.os.UserHandle;
import android.provider.Settings; import android.provider.Settings;
@@ -458,6 +459,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
mView.setClock(clock, mStatusBarStateController.getState()); mView.setClock(clock, mStatusBarStateController.getState());
} }
@Nullable
private ClockController getClock() { private ClockController getClock() {
return mClockEventController.getClock(); return mClockEventController.getClock();
} }
@@ -510,8 +512,10 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
} }
/** Gets the animations for the current clock. */ /** Gets the animations for the current clock. */
@Nullable
public ClockAnimations getClockAnimations() { public ClockAnimations getClockAnimations() {
return getClock().getAnimations(); ClockController clock = getClock();
return clock == null ? null : clock.getAnimations();
} }
} }

View File

@@ -158,6 +158,7 @@ import com.android.systemui.model.SysUiState;
import com.android.systemui.navigationbar.NavigationBarController; import com.android.systemui.navigationbar.NavigationBarController;
import com.android.systemui.navigationbar.NavigationBarView; import com.android.systemui.navigationbar.NavigationBarView;
import com.android.systemui.navigationbar.NavigationModeController; import com.android.systemui.navigationbar.NavigationModeController;
import com.android.systemui.plugins.ClockAnimations;
import com.android.systemui.plugins.FalsingManager; import com.android.systemui.plugins.FalsingManager;
import com.android.systemui.plugins.FalsingManager.FalsingTapListener; import com.android.systemui.plugins.FalsingManager.FalsingTapListener;
import com.android.systemui.plugins.qs.QS; import com.android.systemui.plugins.qs.QS;
@@ -1574,10 +1575,9 @@ public final class NotificationPanelViewController implements Dumpable {
transition.setInterpolator(Interpolators.FAST_OUT_SLOW_IN); transition.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
transition.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD); transition.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD);
boolean customClockAnimation = ClockAnimations clockAnims = mKeyguardStatusViewController.getClockAnimations();
mKeyguardStatusViewController.getClockAnimations() != null boolean customClockAnimation = clockAnims != null
&& mKeyguardStatusViewController.getClockAnimations() && clockAnims.getHasCustomPositionUpdatedAnimation();
.getHasCustomPositionUpdatedAnimation();
if (mFeatureFlags.isEnabled(Flags.STEP_CLOCK_ANIMATION) && customClockAnimation) { if (mFeatureFlags.isEnabled(Flags.STEP_CLOCK_ANIMATION) && customClockAnimation) {
// Find the clock, so we can exclude it from this transition. // Find the clock, so we can exclude it from this transition.
@@ -5033,9 +5033,14 @@ public final class NotificationPanelViewController implements Dumpable {
Rect from = (Rect) startValues.values.get(PROP_BOUNDS); Rect from = (Rect) startValues.values.get(PROP_BOUNDS);
Rect to = (Rect) endValues.values.get(PROP_BOUNDS); Rect to = (Rect) endValues.values.get(PROP_BOUNDS);
anim.addUpdateListener( anim.addUpdateListener(animation -> {
animation -> mController.getClockAnimations().onPositionUpdated( ClockAnimations clockAnims = mController.getClockAnimations();
from, to, animation.getAnimatedFraction())); if (clockAnims == null) {
return;
}
clockAnims.onPositionUpdated(from, to, animation.getAnimatedFraction());
});
return anim; return anim;
} }

View File

@@ -17,6 +17,7 @@
package com.android.keyguard; package com.android.keyguard;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
@@ -365,6 +366,12 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase {
assertEquals(View.VISIBLE, mFakeWeatherView.getVisibility()); assertEquals(View.VISIBLE, mFakeWeatherView.getVisibility());
} }
@Test
public void testGetClockAnimations_nullClock_returnsNull() {
when(mClockEventController.getClock()).thenReturn(null);
assertNull(mController.getClockAnimations());
}
private void verifyAttachment(VerificationMode times) { private void verifyAttachment(VerificationMode times) {
verify(mClockRegistry, times).registerClockChangeListener( verify(mClockRegistry, times).registerClockChangeListener(
any(ClockRegistry.ClockChangeListener.class)); any(ClockRegistry.ClockChangeListener.class));