Skip to content

Commit

Permalink
fix: Ensure app was not in foreground before resetting timer
Browse files Browse the repository at this point in the history
Addresses a potential case where Bugsnag is initialized in an Activity
and the activity restarts for some reason (rotation?)
  • Loading branch information
kattrali committed Sep 20, 2018
1 parent cb9c851 commit 9233622
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ndk/src/main/jni/bugsnag_ndk.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,14 @@ Java_com_bugsnag_android_ndk_NativeBridge_updateInForeground(
? NULL
: (char *)(*env)->GetStringUTFChars(env, activity_, 0);
bsg_request_env_write_lock();
bool was_in_foreground = bsg_global_env->next_report.app.in_foreground;
bsg_global_env->next_report.app.in_foreground = (bool)new_value;
bsg_strncpy_safe(bsg_global_env->next_report.app.active_screen, activity,
sizeof(bsg_global_env->next_report.app.active_screen));
if ((bool)new_value) {
time(&bsg_global_env->foreground_start_time);
if (!was_in_foreground) {
time(&bsg_global_env->foreground_start_time);
}
} else {
bsg_global_env->foreground_start_time = 0;
bsg_global_env->next_report.app.duration_in_foreground_ms_offset = 0;
Expand Down

0 comments on commit 9233622

Please sign in to comment.