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
32 changes: 26 additions & 6 deletions location/drivers/android.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +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;

// Check if the auto save state feature is enabled
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,
double *vert_accuracy)
Expand Down
20 changes: 20 additions & 0 deletions location_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,24 @@ bool driver_location_start(void)

void driver_location_stop(void)
{
#ifdef __ANDROID__
// Check if the auto save state feature is enabled
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
gitgudyyao marked this conversation as resolved.
Show resolved Hide resolved
command_event(CMD_EVENT_SAVE_FILES, NULL);
#endif

location_driver_state_t
*location_st = &location_driver_st;
if ( location_st
Expand All @@ -116,6 +134,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