plat/android_host.rs#
Source: lib/plat/android_host.rs
android_host -- what Android's Java host does for plat while Rust waits: the
ContentResolver behind content:// (content.rs: ContentFs over AndroidDocs), the system
clipboard (ClipboardManager), the persisted grants of the user's documents.
Rust asks synchronously on the UI thread: jfgui_host_call(kind, bytes) in bridge.c calls
GalleryHost.call(kind, byte[]) (android/GalleryHost.java) and copies its answer into the
buffer jfgui_reply hands out; null / an exception = None. The file picker and the export of
download() answer later (web.rs: REQUEST_FILE_DIALOG / REQUEST_OPEN / REQUEST_DOWNLOAD,
jfgui_file_result). A provider whose tree the app listed reports changes through
jfgui_content_changed (DocHost::generation: content.rs's name cache starts again).
Wire (little endian): u32 numbers, i64 times, strings and byte blocks as u32 length + bytes.
CALL_QUERY uri -> DocInfo, or nothing (missing / not allowed)
CALL_CHILDREN uri -> u32 count, DocInfo..
CALL_CREATE u32 dir, parent, name -> DocInfo
CALL_DELETE uri -> u32 ok
CALL_RENAME uri, name -> DocInfo
CALL_OPEN u32 mode (FO_*), uri -> i32 file descriptor (detached: ours to close)
CALL_CLIP_GET u32 format (CLIP_TEXT / CLIP_HTML / CLIP_IMAGE) -> u32 found, bytes
CALL_CLIP_SET text, html, png (each may be empty) -> i64 stamp of the new clip
CALL_CLIP_HAS u32 format -> u32
CALL_CLIP_STAMP -> i64 (ClipDescription.getTimestamp of the current clip, 0 = none or no
access: Android lets only the focused app read the clipboard)
CALL_CLIP_OURS -> u32 (the clip's first item is a file of the app's GalleryFiles)
CALL_GRANTS -> u32 count, (uri, u32 read, u32 write)..
CALL_RELEASE uri -> u32 ok
CALL_SECRET_* the secret store (android_secret.rs, android/GallerySecrets.java)
50 .. 59 android/GallerySystem.java: notifications (web_notify.rs), the screen kept on
(web_power.rs), sensors and location (web_sensors.rs), the back key
(web_system.rs)
DocInfo: uri, display name, u32 dir, u64 size (u64::MAX unknown), i64 mtime ms, u32 DOC_*
The clipboard: text (and HTML) go to the system; the library's richer forms (RTF, DOCX)
stay in the process and count while the system's clip is still the one we set (its
timestamp; when the app had no focus while setting it -- right after the picker -- the
contents decide once it can read them); images go as a PNG through the app's GalleryFiles
provider when the manifest has one (else only inside the app).
extern "C" fn jfgui_reply(len: u32) -> usize(bridge.c) a buffer of len bytes for the answer of a host call; 0 = no memorystruct AndroidDocsthe ContentResolver as ContentFs's hostfn content_fs() -> Arc<dyn Provider>the provider of content:// (mounted by vfs::route on first use): writes go through a copy in the app's data folder (.content-journal), and what a crash left there is finished nowfn content_grants() -> Vec<(String, bool, bool)>the documents and folders the app keeps access to across restarts (the system's persisted grants): (content:// URI, read, write)fn content_release(uri: &str) -> boolgive up the lasting access to a document or folder the user chose (Android keeps at most 128 / 512 of them per app) -> whether there was one