Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Everything is lost when the app is killed in background for android #14804

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
31 changes: 26 additions & 5 deletions location/drivers/android.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,38 @@ static bool android_location_start(void *data)
return true;
}

#ifdef __ANDROID__

static void android_location_stop(void *data)
{
struct android_app *android_app = (struct android_app*)g_android;
androidlocation_t *androidlocation = (androidlocation_t*)data;
JNIEnv *env = jni_thread_getenv();
if (!env)
androidlocation_t *androidlocation = (androidlocation_t*)data;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong indentation

JNIEnv *env = jni_thread_getenv();

if (!androidlocation || !env)
return;


settings_t* settings = config_get_ptr();
bool auto_save_state = settings->bools.auto_save_state;

if (auto_save_state)
{
/* Make a save state */
command_event(CMD_EVENT_SAVE_STATE, NULL);

/* Flush the auto save state to disk */
command_event(CMD_EVENT_AUTOSAVE_DELETE, NULL);
}

/* Flush SRAM to disk */
command_event(CMD_EVENT_SAVE_FILES, NULL);

/* Stop the location service */
struct android_app *android_app = (struct android_app*)g_android;
CALL_VOID_METHOD(env, android_app->activity->clazz,
androidlocation->onLocationStop);
androidlocation->onLocationStop);
}
#endif

static bool android_location_get_position(void *data, double *latitude,
double *longitude, double *horiz_accuracy,
Expand Down
2 changes: 2 additions & 0 deletions location_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ void driver_location_stop(void)
location_st->driver->stop(location_st->data);
}



Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant newlines

void driver_location_set_interval(unsigned interval_msecs,
unsigned interval_distance)
{
Expand Down
24 changes: 23 additions & 1 deletion location_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,29 @@ void driver_location_set_interval(unsigned interval_msecs,
*
* Returns: true (1) if successful, otherwise false (0).
**/
void driver_location_stop(void);
void driver_location_stop(void)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a header.

{
if (location_driver_state.active && location_driver_state.driver->stop)
location_driver_state.driver->stop(location_driver_state.data);

// Flush SRAM to disk
if (RetroArch.isSramAutoSaveEnabled()) {
RetroArch.saveSram();
}

// If auto save state is on, make a save state
if (RetroArch.isAutoSaveStateEnabled()) {
RetroArch.saveState();
}

// Flush auto save state to disk
if (RetroArch.isAutoSaveStateEnabled()) {
RetroArch.flushAutoSaveState();
}

location_driver_state.active = false;
}


/**
* driver_location_start:
Expand Down