Allow manually specified time
Additionally, disable layout animation from test
Bug: 229771520
Test: Automated
Change-Id: I2518d293f5b03e7bea7a45d8ef24ec6a998b5d30
(cherry picked from commit ed1efe9f3137395b2589dca9063d97dfcd4b3923)
diff --git a/packages/SystemUI/screenshot/src/com/android/systemui/testing/screenshot/ViewScreenshotTestRule.kt b/packages/SystemUI/screenshot/src/com/android/systemui/testing/screenshot/ViewScreenshotTestRule.kt
index 60130e1..47e2d2c 100644
--- a/packages/SystemUI/screenshot/src/com/android/systemui/testing/screenshot/ViewScreenshotTestRule.kt
+++ b/packages/SystemUI/screenshot/src/com/android/systemui/testing/screenshot/ViewScreenshotTestRule.kt
@@ -44,9 +44,13 @@
import platform.test.screenshot.MaterialYouColorsRule
import platform.test.screenshot.ScreenshotTestRule
import platform.test.screenshot.getEmulatedDevicePathConfig
+import platform.test.screenshot.matchers.BitmapMatcher
/** A rule for View screenshot diff unit tests. */
-class ViewScreenshotTestRule(emulationSpec: DeviceEmulationSpec) : TestRule {
+class ViewScreenshotTestRule(
+ emulationSpec: DeviceEmulationSpec,
+ private val matcher: BitmapMatcher = UnitTestBitmapMatcher
+) : TestRule {
private val colorsRule = MaterialYouColorsRule()
private val deviceEmulationRule = DeviceEmulationRule(emulationSpec)
private val screenshotRule =
@@ -59,7 +63,6 @@
.around(deviceEmulationRule)
.around(screenshotRule)
.around(activityRule)
- private val matcher = UnitTestBitmapMatcher
override fun apply(base: Statement, description: Description): Statement {
return delegateRule.apply(base, description)
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/clocks/AnimatableClockView.kt b/packages/SystemUI/shared/src/com/android/systemui/shared/clocks/AnimatableClockView.kt
index a21a78b..b51c84a 100644
--- a/packages/SystemUI/shared/src/com/android/systemui/shared/clocks/AnimatableClockView.kt
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/clocks/AnimatableClockView.kt
@@ -77,6 +77,8 @@
private var textAnimator: TextAnimator? = null
private var onTextAnimatorInitialized: Runnable? = null
+ var timeOverrideInMillis: Long? = null
+
val dozingWeight: Int
get() = if (useBoldedVersion()) dozingWeightInternal + 100 else dozingWeightInternal
@@ -139,7 +141,7 @@
}
fun refreshTime() {
- time.timeInMillis = System.currentTimeMillis()
+ time.timeInMillis = timeOverrideInMillis ?: System.currentTimeMillis()
contentDescription = DateFormat.format(descFormat, time)
val formattedText = DateFormat.format(format, time)
// Setting text actually triggers a layout pass (because the text view is set to
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java
index e1fabde..10d6d9f 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitch.java
@@ -68,6 +68,7 @@
private int mClockSwitchYAmount;
@VisibleForTesting boolean mChildrenAreLaidOut = false;
+ @VisibleForTesting boolean mAnimateOnLayout = true;
public KeyguardClockSwitch(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -214,7 +215,7 @@
super.onLayout(changed, l, t, r, b);
if (mDisplayedClockSize != null && !mChildrenAreLaidOut) {
- post(() -> updateClockViews(mDisplayedClockSize == LARGE, /* animate */ true));
+ post(() -> updateClockViews(mDisplayedClockSize == LARGE, mAnimateOnLayout));
}
mChildrenAreLaidOut = true;