RetroArch icon indicating copy to clipboard operation
RetroArch copied to clipboard

Save SRAM and state on Android shutdown

Open fishcu opened this issue 9 months ago • 5 comments

Guidelines

  1. Rebase before opening a pull request
  2. If you are sending several unrelated fixes or features, use a branch and a separate pull request for each
  3. If possible try squashing everything in a single commit. This is particularly beneficial in the case of feature merges since it allows easy bisecting when a problem arises

Description

Bring relevant changes in https://github.com/libretro/RetroArch/pull/14804 forward to latest upstream.

Related Issues

https://github.com/libretro/RetroArch/issues/14518

Reviewers

@hizzlekizzle @warmenhoven

fishcu avatar Feb 16 '25 15:02 fishcu

The original PR replicated the code changes in the header (!) inside driver_location_stop().

AFAICT, driver_location_stop() will call android_location_stop() anyway, so no need to replicate this functionality. I did not bring these changes forward.

fishcu avatar Feb 16 '25 15:02 fishcu

I'm going to assume we should just merge this @warmenhoven ? Or are there issues with it still?

LibretroAdmin avatar Mar 07 '25 17:03 LibretroAdmin

I was hoping to find a better location for this than the location driver but I'm not very familiar with the android apis and can't find an equivalent to iOS's delegate function for handling backgrounding. Putting it in the location driver means that if someone has changed their location driver to null then this change won't work.

Anyway it shouldn't cause any problems and does fix an issue so it should be safe to merge. Just maybe not the cleanest possible implementation.

warmenhoven avatar Mar 07 '25 17:03 warmenhoven

Someone did a brief testing of the CI build from this MR, and found that it did not fix the issue. So, I would actually close this PR until we find a working solution. I was hoping the original work already fixed the issue but was just abandoned. But it seems like it was not working in the first place.

fishcu avatar Mar 07 '25 18:03 fishcu

If this is primarily for Android, couldn't you edit the RetroActivityFuture.java, include an onPause or onDestroy with a function to call a JNI and then use the command event from a .c file?

I did this test on my own on the java file, i simply made:

public void onPause() {
    super.onPause();
    try {
        nativeFlushSaveRAM();
        Log.d("sram", "SRAM flushed via onPause()");
    } catch (Exception e) {
        Log.e("sram", "Failed to flush SRAM onPause", e);
    }
}

i then just pointed it to a flush.c file, and added the file to Android.mk local files section and it worked! (And i double checked by turning off autosave interval to make sure).

JNIEXPORT void JNICALL Java_com_retroarch_browser_retroactivity_RetroActivityFuture_nativeFlushSaveRAM(JNIEnv* env, jobject obj)
{
LOGI("SRAMSaving: Flushing SRAM via command_event");
command_event(CMD_EVENT_SAVE_FILES, NULL);
}

marpet6137 avatar May 22 '25 18:05 marpet6137