Fix the OOM issue while capturing the screenshot.
This is not really an OOM issue. In fact, before capturing a screenshot,
it would be great if we wait for the stability of a view. (Otherwise,
the width and height were probably observed with super large values -
10^6 for both or so).
Bug: 338457856
Test: atest -c --iteration 150 \
SystemUIGoogleRobo2RNGTests:com/android/systemui/biometrics/ui/BiometricPromptIconOnlyScreenshotTest
(Results: https://screenshot.googleplex.com/3AWjfY9nPTkY7HT.png, 150
iterations all passed.)
Change-Id: I043d2fe3ff889fa59724969d3369fb6630ddce64
diff --git a/libraries/screenshot/src/main/java/platform/test/screenshot/ViewCapture.kt b/libraries/screenshot/src/main/java/platform/test/screenshot/ViewCapture.kt
index b2ea851..f031da1 100644
--- a/libraries/screenshot/src/main/java/platform/test/screenshot/ViewCapture.kt
+++ b/libraries/screenshot/src/main/java/platform/test/screenshot/ViewCapture.kt
@@ -85,6 +85,7 @@
suspend fun View.captureToBitmap(rect: Rect? = null): Bitmap {
val mainHandlerDispatcher = Handler(Looper.getMainLooper()).asCoroutineDispatcher()
var bitmap: Bitmap? = null
+ ControlledLooperSingleton.getInstance().drainMainThreadUntilIdle()
val job =
CoroutineScope(mainHandlerDispatcher).launch {
val hardwareDrawingEnabled = HardwareRendererCompat.isDrawingEnabled()