Fix clock position is too high in lockscreen preview in tablet portrait mode

Bug: 369937183
Flag: com.android.systemui.migrate_clocks_to_blueprint
Test: manual test, attach screenshots in comment#6
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:efa861ac8951da4c6c82d849c64b29c06df68299)
Merged-In: I4455798e3de7bb4b597a232926041311ce382b47
Change-Id: I4455798e3de7bb4b597a232926041311ce382b47
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardPreviewClockViewBinder.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardPreviewClockViewBinder.kt
index 8386628..57cb10f 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardPreviewClockViewBinder.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardPreviewClockViewBinder.kt
@@ -121,7 +121,10 @@
     private fun applyClockDefaultConstraints(context: Context, constraints: ConstraintSet) {
         constraints.apply {
             constrainWidth(R.id.lockscreen_clock_view_large, ConstraintSet.WRAP_CONTENT)
-            constrainHeight(R.id.lockscreen_clock_view_large, ConstraintSet.MATCH_CONSTRAINT)
+            // The following two lines make lockscreen_clock_view_large is constrained to available
+            // height when it goes beyond constraints; otherwise, it use WRAP_CONTENT
+            constrainHeight(R.id.lockscreen_clock_view_large, WRAP_CONTENT)
+            constrainMaxHeight(R.id.lockscreen_clock_view_large, 0)
             val largeClockTopMargin =
                 SystemBarUtils.getStatusBarHeight(context) +
                     context.resources.getDimensionPixelSize(
@@ -138,7 +141,7 @@
                 R.id.lockscreen_clock_view_large,
                 ConstraintSet.END,
                 PARENT_ID,
-                ConstraintSet.END
+                ConstraintSet.END,
             )
 
             // In preview, we'll show UDFPS icon for UDFPS devices
@@ -160,14 +163,14 @@
                     BOTTOM,
                     PARENT_ID,
                     BOTTOM,
-                    clockBottomMargin
+                    clockBottomMargin,
                 )
             }
 
             constrainWidth(R.id.lockscreen_clock_view, WRAP_CONTENT)
             constrainHeight(
                 R.id.lockscreen_clock_view,
-                context.resources.getDimensionPixelSize(customizationR.dimen.small_clock_height)
+                context.resources.getDimensionPixelSize(customizationR.dimen.small_clock_height),
             )
             connect(
                 R.id.lockscreen_clock_view,
@@ -175,7 +178,7 @@
                 PARENT_ID,
                 START,
                 context.resources.getDimensionPixelSize(customizationR.dimen.clock_padding_start) +
-                    context.resources.getDimensionPixelSize(R.dimen.status_view_margin_horizontal)
+                    context.resources.getDimensionPixelSize(R.dimen.status_view_margin_horizontal),
             )
             val smallClockTopMargin =
                 context.resources.getDimensionPixelSize(R.dimen.keyguard_clock_top_margin) +
@@ -188,7 +191,7 @@
         context: Context,
         rootView: ConstraintLayout,
         previewClock: ClockController,
-        viewModel: KeyguardPreviewClockViewModel
+        viewModel: KeyguardPreviewClockViewModel,
     ) {
         val cs = ConstraintSet().apply { clone(rootView) }
         applyClockDefaultConstraints(context, cs)