Skip to content

Commit

Permalink
Error handling for PixelCopy.request
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarta committed Jan 9, 2025
1 parent c01df35 commit c6c3527
Showing 1 changed file with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,37 @@ internal class HotwireViewScreenshotHolder {

val bitmap = Bitmap.createBitmap(rect.width(), rect.height(), Bitmap.Config.ARGB_8888)

PixelCopy.request(
window,
rect,
bitmap,
{ result ->
if (result == PixelCopy.SUCCESS) {
logEvent(
"viewScreenshotCreated", listOf(
"size" to "${bitmap.width}x${bitmap.height}",
"duration" to "${System.currentTimeMillis() - start}ms",
try {
PixelCopy.request(
window,
rect,
bitmap,
{ result ->
if (result == PixelCopy.SUCCESS) {
logEvent(
"viewScreenshotCreated", listOf(
"size" to "${bitmap.width}x${bitmap.height}",
"duration" to "${System.currentTimeMillis() - start}ms",
)
)
)
if (continuation.isActive) {
continuation.resume(bitmap, null)
if (continuation.isActive) {
continuation.resume(bitmap, null)
}
} else {
logEvent("viewScreenshotFailed", listOf("error" to result))
if (continuation.isActive) {
continuation.resume(null, null)
}
}
} else {
logEvent("viewScreenshotFailed", listOf("error" to result))
if (continuation.isActive) {
continuation.resume(null, null)
}
}
},
Handler(Looper.getMainLooper())
)
},
Handler(Looper.getMainLooper())
)
} catch (exception: Exception) {
logEvent("viewScreenshotFailed", listOf("error" to exception))
if (continuation.isActive) {
continuation.resume(null, null)
}
}
}
}

Expand Down

0 comments on commit c6c3527

Please sign in to comment.