Fix dump() which got broken by flow migrations

Test: Added a new test
Change-Id: Ia51d54e7690d95c052bf1f5bfaf5943b8e54be6f
diff --git a/wear/watchface/watchface/src/main/java/androidx/wear/watchface/WatchFace.kt b/wear/watchface/watchface/src/main/java/androidx/wear/watchface/WatchFace.kt
index c8131ae..f3f9d7f 100644
--- a/wear/watchface/watchface/src/main/java/androidx/wear/watchface/WatchFace.kt
+++ b/wear/watchface/watchface/src/main/java/androidx/wear/watchface/WatchFace.kt
@@ -493,6 +493,7 @@
 
     // True if 'Do Not Disturb' mode is on.
     private var muteMode = false
+    internal var lastDrawTimeMillis: Long = 0
     internal var nextDrawTimeMillis: Long = 0
 
     private val pendingUpdateTime: CancellableUniqueTask =
@@ -809,6 +810,7 @@
         val startTimeMillis = startTime.toInstant().toEpochMilli()
         maybeUpdateDrawMode()
         renderer.renderInternal(startTime)
+        lastDrawTimeMillis = startTimeMillis
 
         if (renderer.shouldAnimate()) {
             val currentTimeMillis = systemTimeProvider.getSystemTimeMillis()
@@ -1063,12 +1065,13 @@
         writer.println("mockTime.maxTime=${mockTime.maxTime}")
         writer.println("mockTime.minTime=${mockTime.minTime}")
         writer.println("mockTime.speed=${mockTime.speed}")
+        writer.println("lastDrawTimeMillis=$lastDrawTimeMillis")
         writer.println("nextDrawTimeMillis=$nextDrawTimeMillis")
         writer.println("muteMode=$muteMode")
         writer.println("pendingUpdateTime=${pendingUpdateTime.isPending()}")
         writer.println("lastTappedComplicationId=$lastTappedComplicationId")
         writer.println(
-            "currentUserStyleRepository.userStyle=${currentUserStyleRepository.userStyle}"
+            "currentUserStyleRepository.userStyle=${currentUserStyleRepository.userStyle.value}"
         )
         writer.println("currentUserStyleRepository.schema=${currentUserStyleRepository.schema}")
         watchState.dump(writer)
diff --git a/wear/watchface/watchface/src/main/java/androidx/wear/watchface/WatchState.kt b/wear/watchface/watchface/src/main/java/androidx/wear/watchface/WatchState.kt
index 50e9400..e92e399 100644
--- a/wear/watchface/watchface/src/main/java/androidx/wear/watchface/WatchState.kt
+++ b/wear/watchface/watchface/src/main/java/androidx/wear/watchface/WatchState.kt
@@ -76,10 +76,10 @@
     internal fun dump(writer: IndentingPrintWriter) {
         writer.println("WatchState:")
         writer.increaseIndent()
-        writer.println("interruptionFilter=$interruptionFilter")
-        writer.println("isAmbient=$isAmbient")
-        writer.println("isBatteryLowAndNotCharging=$isBatteryLowAndNotCharging")
-        writer.println("isVisible=$isVisible")
+        writer.println("interruptionFilter=${interruptionFilter.value}")
+        writer.println("isAmbient=${isAmbient.value}")
+        writer.println("isBatteryLowAndNotCharging=${isBatteryLowAndNotCharging.value}")
+        writer.println("isVisible=${isVisible.value}")
         writer.println("hasLowBitAmbient=$hasLowBitAmbient")
         writer.println("hasBurnInProtection=$hasBurnInProtection")
         writer.println("analogPreviewReferenceTimeMillis=$analogPreviewReferenceTimeMillis")
diff --git a/wear/watchface/watchface/src/test/java/androidx/wear/watchface/TestCommon.kt b/wear/watchface/watchface/src/test/java/androidx/wear/watchface/TestCommon.kt
index 0065745..4641ee1 100644
--- a/wear/watchface/watchface/src/test/java/androidx/wear/watchface/TestCommon.kt
+++ b/wear/watchface/watchface/src/test/java/androidx/wear/watchface/TestCommon.kt
@@ -54,13 +54,13 @@
     private val tapListener: WatchFace.TapListener?,
     private val preAndroidR: Boolean,
     private val directBootParams: WallpaperInteractiveWatchFaceInstanceParams?,
-    private val choreographer: ChoreographerWrapper
+    private val choreographer: ChoreographerWrapper,
+    var mockSystemTimeMillis: Long = 0L
 ) : WatchFaceService() {
     /** The ids of the [ComplicationSlot]s that have been tapped. */
     val tappedComplicationSlotIds: List<Int>
         get() = mutableTappedComplicationIds
     var complicationSelected: Int? = null
-    var mockSystemTimeMillis = 0L
     var mockZoneId: ZoneId = ZoneId.of("UTC")
     var renderer: TestRenderer? = null
 
diff --git a/wear/watchface/watchface/src/test/java/androidx/wear/watchface/WatchFaceServiceTest.kt b/wear/watchface/watchface/src/test/java/androidx/wear/watchface/WatchFaceServiceTest.kt
index e93054f..997edc1 100644
--- a/wear/watchface/watchface/src/test/java/androidx/wear/watchface/WatchFaceServiceTest.kt
+++ b/wear/watchface/watchface/src/test/java/androidx/wear/watchface/WatchFaceServiceTest.kt
@@ -106,6 +106,7 @@
 import org.mockito.Mockito.validateMockitoUsage
 import org.mockito.Mockito.verify
 import org.robolectric.annotation.Config
+import java.io.StringWriter
 import java.time.Instant
 import java.util.ArrayDeque
 import java.util.PriorityQueue
@@ -504,7 +505,8 @@
             null,
             false,
             null,
-            choreographer
+            choreographer,
+            mockSystemTimeMillis = looperTimeMillis
         )
 
         InteractiveInstanceManager
@@ -3382,6 +3384,58 @@
         assertThat(onDestroyCalled).isTrue()
     }
 
+    @Test
+    public fun dump() {
+        // Advance time a little so timestamps are not zero
+        looperTimeMillis = 1000
+
+        initWallpaperInteractiveWatchFaceInstance(
+            WatchFaceType.ANALOG,
+            listOf(leftComplication, rightComplication),
+            UserStyleSchema(listOf(colorStyleSetting, watchHandStyleSetting)),
+            WallpaperInteractiveWatchFaceInstanceParams(
+                "TestID",
+                DeviceConfig(
+                    false,
+                    false,
+                    0,
+                    0
+                ),
+                WatchUiState(false, 0),
+                UserStyle(emptyMap()).toWireFormat(),
+                emptyList()
+            )
+        )
+
+        val writer = StringWriter()
+        val indentingPrintWriter = IndentingPrintWriter(writer)
+
+        engineWrapper.dump(indentingPrintWriter)
+
+        val dump = writer.toString()
+        // The full dump contains addresses that change from run to run, however these are a
+        // collection of sub strings we expect.
+        assertThat(dump).contains("Androidx style init flow")
+        assertThat(dump).contains("createdBy=Boot with pendingWallpaperInstanc")
+        assertThat(dump).contains("lastDrawTimeMillis=1000")
+        assertThat(dump).contains("nextDrawTimeMillis=1016")
+        assertThat(dump).contains("isHeadless=false")
+        assertThat(dump).contains(
+            "currentUserStyleRepository.userStyle=UserStyle[color_style_setting -> red_style, " +
+                "hand_style_setting -> classic_style]")
+        assertThat(dump).contains(
+            "currentUserStyleRepository.schema=[{color_style_setting : red_style, green_style, " +
+                "blue_style}, {hand_style_setting : classic_style, modern_style, gothic_style}]")
+        assertThat(dump).contains("ComplicationSlot 1000:")
+        assertThat(dump).contains("ComplicationSlot 1001:")
+        assertThat(dump).contains("screenBounds=Rect(0, 0 - 100, 100)")
+        assertThat(dump).contains("interactiveDrawModeUpdateDelayMillis=16")
+        assertThat(dump).contains("CanvasRenderer:")
+        assertThat(dump).contains("screenBounds=Rect(0, 0 - 100, 100)")
+        assertThat(dump).contains("interactiveDrawModeUpdateDelayMillis=16")
+        assertThat(dump).contains("watchFaceLayers=BASE, COMPLICATIONS, COMPLICATIONS_OVERLAY")
+    }
+
     @SuppressLint("NewApi")
     @Suppress("DEPRECATION")
     private fun getChinWindowInsetsApi25(@Px chinHeight: Int): WindowInsets =