Skip to content

feat: open files through the host in Formatter, BitmapFactory and MediaMetadataRetriever - #24

Merged
NenkaLab merged 1 commit into
masterfrom
feat/guard-path-apis
Nov 15, 2026
Merged

NenkaLab merged 1 commit into
masterfrom
feat/guard-path-apis

Conversation

@NenkaLab

Copy link
Copy Markdown
Member

What changed

Classes that open a file by path inside themselves bypassed the guard and failed with EACCES in engine apps without storage permission. Three common ones now have same-shaped replacements registered in GuardPolicy.substitutes, so both Javet and GraalJS pick them up through the existing lookup:

  • java.util.Formatter (final): all constructors; the file name and File ones write through GuardFileOutputStream, the charset is checked before the file is opened as in the real class.
  • android.graphics.BitmapFactory: decodeFile reads through the host and, like the real class, logs and returns null on failure; the other decoders are the real ones.
  • android.media.MediaMetadataRetriever: subclass whose setDataSource(String) opens paths and file: addresses through the host (other schemes go to the real URL path).

Still not covered (they need a real path): SQLite databases (use the host db module), java.util.logging.FileHandler, URL("file:..."), XML parse(File), MediaPlayer.setDataSource(path), AtomicFile.

Testing

  • :guard:connectedDebugAndroidTest on an API 36 x86_64 emulator: 26/26 (new boundary tests; the parity test now also checks the three replacements against the real classes).
  • JavaGuardConformance gains classesThatOpenAPathGoThroughTheHost; NodeJSPlugin and the GraalJS fixture pass 12/12 on the emulator with this revision.

🤖 Generated with Claude Code

@NenkaLab
NenkaLab merged commit 7e31985 into master Nov 15, 2026
1 check passed
@NenkaLab
NenkaLab deleted the feat/guard-path-apis branch November 15, 2026 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant