Skip to content

android: PickDirectories lacks persistent SAF grants and in-place core.Video playback URIs #2245

In review

Description

@henry-wm

Context

Follow-up to #26 (PickDirectories on Android/iOS/web, tested on NSGo v0.3.0).

In Wood & Wind Music (a local music player targeting macOS, Windows, and Android), desktop folders picked via PickDirectories return a native Path, so the app scans tags, reads .lrc lyrics, and plays audio directly from the user's folder without duplicating files.

On Android, PickDirectories returns a pathless core.Directory backed by ACTION_OPEN_DOCUMENT_TREE. Today, an app cannot keep using that picked folder directly across restarts or stream its files in-place with core.Video, which forces the app either to copy the entire music library (often gigabytes of FLAC/MP3 files) into app-private storage — doubling storage usage and preventing rescans from seeing later changes — or to maintain a custom Android host bridge.

Specific Gaps in v0.3.0

  1. No persistent directory access across restarts

    • internal/platform/android/java/dev/oneo/nsgo/Services.java (startFolder) launches new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) without FLAG_GRANT_READ_URI_PERMISSION | FLAG_GRANT_PERSISTABLE_URI_PERMISSION, and NsgoView.documentsResult does not call ContentResolver.takePersistableUriPermission.
    • core.Directory exposes no opaque/serializable token (or bookmark) and there is no API to reopen a previously granted folder after restart or release the persisted grant when the user removes the folder.
    • (On iOS, security-scoped bookmarks cover the same persistence lifecycle.)
  2. No playable URI / media source for files inside core.Directory

    • VideoNode.java (setMediaSource) calls player.setDataSource(context, Uri.parse(uri)), so Android's MediaPlayer already supports streaming content:// document URIs directly with zero copying and working seek/rate controls.
    • However, core.Directory only exposes fs.FS (byte reads over the Go↔Java pipe) and gives no way to obtain a core.Video-compatible source URI for an entry in the picked tree.
  3. Repeated descriptor opens when scanning large trees on Android

    • Services.readDocument opens a new ParcelFileDescriptor + FileChannel on every Read RPC, and document in internal/platform/android/folders.go does not implement io.ReaderAt.
    • Tag and duration parsers issue many small Read/Seek calls per track; keeping an open descriptor per fs.File until Close() (and optionally implementing io.ReaderAt or batch tree listing) would substantially reduce provider IPC overhead when scanning hundreds or thousands of files in-place.

Minimal Reproduction

// On Android (NSGo v0.3.0):
cx.PickDirectories(core.PickDirectoriesOptions{}, func(dirs []core.Directory, err error) {
	if err != nil || len(dirs) == 0 {
		return
	}
	dir := dirs[0]
	// 1. dir.Path is "" on Android, and core.Directory has no persistable token
	//    to save to disk and reopen after an app restart.
	// 2. Opening a track via dir.Open("song.flac") only provides an fs.File;
	//    there is no URI/handle to pass to core.Video{Source: ...} without
	//    copying the audio file into cx.DataDir().
})

Request

Could NSGo support persistent, in-place access for picked directories? For example:

  • An option on PickDirectoriesOptions (e.g., Persist: true) that takes a persistable grant (Android takePersistableUriPermission; iOS security-scoped bookmark) and populates a serializable handle/token on core.Directory, along with Scope methods to reopen a persisted directory by token and release the grant.
  • A way to obtain a read-only playable media source/URI for a file inside a core.Directory that core.Video can stream directly (e.g., content:// on Android, file:// on desktop/iOS).
  • Keeping the Android ParcelFileDescriptor open for the lifetime of an opened fs.File (and/or supporting io.ReaderAt) so metadata scanning does not reopen the provider descriptor on every chunk read.

Activity

  1. self-assigned this
    on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions