Repository navigation
Capture screenshots from the correct window and gate on system memory - #217
Merged
Merged
Conversation
Screenshots of a DialogFragment destination were copied from the Activity window, which captured the screen behind the dialog. Resolve the dialog's own window in the delegate and pass it to the screenshot holder. The memory check compared the Java heap footprint to its maximum, which refused every capture once the heap had grown, however much was free. Bitmap pixels live on the native heap, so the Java heap never reflected the cost anyway. Gate on ActivityManager.MemoryInfo instead, catch a failed native allocation, and log skipped captures. Skip the capture when the view is no longer attached, which is the case for the second detach during a dialog cancel.
This was referenced Sep 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Combines and extends #209 and #216.
Problem
Two independent reasons a destination ends up without a screenshot backdrop during navigation:
HotwireViewScreenshotHolderalways copies from the Activity window. ADialogFragmentdestination (bottom sheets) draws in its own window, so the capture picks up the screen behind the sheet and shows it inside the sheet as it dismisses (Modal dismiss shows underlying view before closing #150, Allow capturing dialog window content instead of Activities window #216).hasEnoughMemoryForScreenshot()comparestotalMemory()tomaxMemory(), which measures how much the Java heap can still grow, not how much is free. Once the heap has grown to its limit the check is pinned at0.0and every capture is refused (Measure used heap, not allocated heap, before capturing a screenshot #209). Bitmap pixels live on the native heap anyway, so the Java heap never reflected the cost being guarded — a 12.6 MB capture on a Pixel emulator moves the native heap by 12.6 MB and the Java heap by 0.Fix
HotwireWebFragmentDelegate.screenshotView()resolves the window — the dialog's own window for aDialogFragment, the Activity's otherwise — and passes it to the holder. The capture is skipped when the view is no longer attached, which is the case for the second detach during a dialog cancel.ActivityManager.MemoryInfo: skip whenlowMemoryis set or when the bitmap would pushavailMemunderthreshold.Bitmap.createBitmapis wrapped to catch a failed native allocation.viewScreenshotSkippedwith the values at hand instead of returning silently.Testing
HotwireViewScreenshotHolderTestcovers the memory gate: headroom,lowMemory, crossing the threshold, and reaching it exactly.