Commit Graph
44 Commits
Author SHA1 Message Date
Henrik RydgårdandClaude Opus 5.5 56580581e0 Android: Check for Java exceptions after content URI calls
ContentUri catches Exception, but an Error got through, and none of the
native wrappers checked. A thrown int call returned 0, which reads as
SUCCESS, and the exception stayed pending, so the next JNI call aborted.
copyDocument/moveDocument are API 24/25 while the folder browser is
offered from 21, so those threw NoSuchMethodError there - now they return
a failure so the callers fall back.

Also convert non-URI names to Java's modified UTF-8.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 14:41:19 +02:00
Henrik RydgårdandClaude Fable 5.1 2f6bb8d55e Android: Don't leak the activity on recreate, and hand it over safely
registerCallbacks took a new global ref to the activity on every onCreate
without releasing the previous one, and unregisterCallbacks only runs on a
real shutdown. Since rotation and resizing recreate the activity, each of
those leaked the old one, view hierarchy and all.

Releasing it means other threads can no longer use the raw global ref,
which had been copied into AndroidStorage and TextDrawerAndroid and was
read from the emu thread and IO threads. They now take a local ref under a
mutex (Android_GetActivity, and the equivalent inside AndroidStorage for
the shortcut activity's sake), so a call in flight keeps its activity
alive while the UI thread swaps in the new one.

The "no activity" bail is a null check on that local ref rather than a
separate HasActivity() test beforehand. Between such a test and the call
the UI thread can swap the activity out, and we'd hand null to a Java
method that wants a Context. The one remaining HasActivity() caller never
passes the activity on, so it has nothing to race with.

The ContentUri class ref and method IDs are now only looked up once,
instead of leaking a class ref per activity.

Headless and the unit test executable link Common but not app-android.cpp, so
they get a stub for this the same way they already do for getEnv and findClass.
Without it the Android CI build fails at link time, where a normal gradle build
is perfectly happy.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01152igCdjTNhT29qvphPyPC
2026-10-08 18:54:46 +02:00
Henrik RydgårdandClaude Fable 5.1 35c586b27b Android: Stop leaking JNI local references on native threads
Local refs are only freed automatically when a native method returns to
Java. The content URI functions mostly run on threads we attached
ourselves, where nothing ever freed the strings they created - two per
file open, one per exists check and so on. From Android 8 that's a slow
leak; before it the table has 512 slots and overflowing it aborts.

Add JNILocalFrame (PushLocalFrame/PopLocalFrame) and use it in all of
AndroidStorage.cpp, in the camera device list, and free the name string
in findClass.

Also: Android_GetFileInfo never released its GetStringUTFChars buffer, a
native leak on every call, and Android_ListContentUri called
GetArrayLength on a null array if the Java side returned none.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-08 18:54:46 +02:00
Henrik Rydgård 092ab42fe7 Clean up ugly usage of the g_nativeLibDir global. Now it's local in VulkanLoader. 2026-08-06 18:12:04 +02:00
Henrik Rydgård e6e82c9ad3 Add java-side prefix filtering for ContentUri directory listing 2026-01-09 10:12:15 +01:00
Henrik Rydgård cfe807baed Android refactor: Move all contentUri utilities to the new class ContentUri 2025-11-06 23:44:55 +01:00
Henrik Rydgård 073ef61643 Merge the two functions, fix JNI lifetime issues
Fixes the last part of #10885 finally.
2025-09-05 10:31:51 +02:00
Henrik Rydgård 2a7dad43c6 WIP: Turn the methods into static methods. 2025-09-05 10:31:27 +02:00
Henrik Rydgård 7df5941531 Correctly convert one AndroidStorage method into static 2025-09-05 10:31:27 +02:00
Henrik Rydgård 44902bffdd Make logging work in these callbacks, and clarify the future solution 2025-09-05 10:31:27 +02:00
Henrik Rydgård c9acf8e80e More std::string_view 2025-08-31 20:20:59 +02:00
Henrik Rydgård b472eb8b8b Remove a lot of unnecessary string constructors 2025-08-31 15:49:29 +02:00
Henrik Rydgård 5eb87f0fb4 Logging fixes and cleanups around folder move 2025-05-29 13:13:07 +02:00
Henrik Rydgård 91bf4d5b5c Correct some log categories, add UI category, some warning fixes 2025-04-09 13:45:21 +02:00
Henrik Rydgård bb2b214d5e Minor FS logging 2024-12-29 09:31:50 +01:00
Henrik Rydgård 1f108a0e8c Remove the java-side directory listing filtering, didn't work. 2024-11-30 02:44:01 +01:00
Henrik Rydgård edbc7afcc1 Add support for prefix filtering in directory listing. 2024-11-29 11:14:52 +01:00
Henrik Rydgård e93427c433 CPU_Init: Bail out earlier if we fail to identify a file. 2024-10-31 23:56:36 +01:00
Henrik Rydgård d47c05f4a1 Android memstick folder move: Minor logging and robustness improvements 2024-09-09 17:47:21 +02:00
Henrik Rydgård e01ca5b057 Logging API change (refactor) (#19324)
* Rename LogType to Log

* Explicitly use the Log:: enum when logging. Allows for autocomplete when editing.

* Mac/ARM64 buildfix

* Do the same with the hle result log macros

* Rename the log names to mixed case while at it.

* iOS buildfix

* Qt buildfix attempt, ARM32 buildfix
2024-07-14 14:42:59 +02:00
Dzmitry Dubrova a461800973 Implement custom driver loading for ARM64 Android devices 2023-12-14 08:53:03 +03:00
Henrik Rydgård d234fa24e6 Add progress bar (without %) to install/uninstall. Other fixes. 2023-12-08 16:16:28 +01:00
Henrik Rydgård d0ee5fc308 Path: Use string_view more to avoid allocations 2023-11-13 23:24:42 +01:00
Henrik Rydgård 3b39e9e068 Turn the VFS into a class, to be able to reuse it for other purposes. 2023-03-06 16:42:47 +01:00
Unknown W. Brackets 7b8350f8a8 Android: Differentiate empty dir from failure. 2022-10-09 14:42:31 -07:00
Unknown W. Brackets 656576c283 Io: Correct access field on dir listings. 2022-07-13 23:40:38 -07:00
Henrik Rydgård 07413aa4e3 Feedback 2021-09-11 18:53:46 +02:00
Henrik Rydgård dc520a59d3 Log the duration of directory size computations too 2021-09-11 18:17:14 +02:00
Henrik Rydgård e842d395fa Add untested function Android_ComputeRecursiveDirectorySize 2021-09-11 18:11:53 +02:00
Henrik Rydgård a0a5f7a67a Minor improvements on Android 9/10. Let the user reset to root of storage.
This includes handling weird "raw:/" content URIs. These I haven't seen
on newer versions.
2021-08-04 23:22:43 +02:00
Henrik Rydgård 3ec13b8440 Two more functions 2021-07-25 17:32:12 +02:00
Henrik Rydgård 0997b8500c Convert four more functions to allow for error codes.
Note that they still don't actually use them...
2021-07-25 17:32:12 +02:00
Henrik Rydgård 2333239514 Change one storage function to use an error code. 2021-07-25 17:32:12 +02:00
Henrik Rydgård ab69b896c3 Add and hook up Android_MoveFile 2021-07-25 17:32:12 +02:00
Henrik Rydgård 729496b60a Error code support preparations 2021-07-25 17:32:09 +02:00
Henrik Rydgård d5781824eb Fix lastModified, speed up Android_FileExists. Add Android_CopyFile (unused) 2021-07-24 00:33:05 +02:00
Henrik Rydgård bd99e4a287 Greatly speed up content URI file listings by using DocumentContract queries. 2021-07-24 00:33:05 +02:00
Henrik Rydgård 2f04fc1c00 Refactor DirectoryFileSystem::GetDirListing to use GetFilesInDir.
Lets us remove some platform specific code, fixing the content URI case.
2021-07-19 17:34:51 +02:00
Henrik Rydgård 4f10ff9d31 Add quick method to check file existence by content URI.
Seems to speed up bringing up the pause screen slightly (checking for
save state files).
2021-07-19 17:34:51 +02:00
Henrik Rydgård 15fafe5415 Fix date/time display for savestates 2021-07-19 17:34:51 +02:00
Henrik Rydgård fff3850096 Add ability to rename content URI files, fixing saving save states.
buildfix
2021-07-19 17:34:50 +02:00
Henrik Rydgård c6163fd3e4 Only log slow file listings 2021-06-07 00:26:27 +02:00
Henrik Rydgård 3737daaf0c Address more feedback, warning fix 2021-06-07 00:26:26 +02:00
Henrik Rydgård 9b32ea2f55 Split out AndroidStorage.cpp from android/jni/app-android.cpp, move to Common 2021-06-07 00:26:24 +02:00