docs/image-input.md
Image input ownership
attachments.ImageReader prepares only explicitly selected/shared/pasted Android
content: URIs, off main while their grants are usable. It snapshots bytes into
RAM and closes provider streams/cursors. It does not persist a URI/grant, read an
ordinary chat path, stage a remote file or monitor the clipboard. Native input UI
and submission wiring are separate from these preparation helpers.
PreparedImage holds immutable process-local bytes and display metadata. Bounds
must be recognized, dimensions must be at most 256 Mi-pixels, and a bounded pixel
decode must succeed before admission. This is decodability screening, not proof
that every image frame/byte is intact. Previews are sampled to a bounded edge;
original bytes are sent, not thumbnails. Native-Skia JVM tests cover known
quadrant pixels, a recognizable header with corrupt pixel data, and oversized
dimensions using a fake content provider. Those are not real-provider grant or
Waydroid/device acceptance checks; interactive input still needs device validation.
ImageDraft belongs to a composer origin, not the visible Activity. It permits
16 images and 32 MiB aggregate decoded image-file bytes per draft; the count
is an Android resource/UI bound in addition to the API's binary-byte limit.
Recheck both bounds when asynchronous imports finish. Snapshot/validate the full
list before allocating the inline JSON/base64 payload, and encode off main.
Captured references survive navigation/removal. Failed preparation/submission
must preserve existing draft contents. Clear only the accepted captured revision;
newer edits survive late acknowledgements.
Reads fill fixed 64 KiB chunks across short provider reads. A one-byte oversize probe enforces the byte bound without retaining an object per short read. Cooperative cancellation is checked at stage boundaries, including EOF, consolidation, native decoding and per-image encoding. It cannot forcibly stop a provider or native codec already blocked inside a call. Bound concurrent jobs, process-wide retained drafts and bitmap caches in the integration owner; per-draft limits alone do not bound total process memory. Native decoding/memory errors must produce an actionable import error rather than retrying indefinitely.
Posting uses existing PendingTurn.withAttachments / AttachmentBlob with
matching file_array and meta_files, inline base64, MIME and decoded byte sizes.
No Android URI or local path is a remote agent filename. Historical attachment
metadata does not imply an image-payload retrieval API.