File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed
firebase-sessions/src/main/kotlin/com/google/firebase/sessions Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,8 @@ import kotlinx.coroutines.launch
34
34
35
35
/* * Repository to persist session data to be shared between all app processes. */
36
36
internal interface SharedSessionRepository {
37
+ val isInForeground: Boolean
38
+
37
39
fun appBackground ()
38
40
39
41
fun appForeground ()
@@ -59,6 +61,9 @@ constructor(
59
61
/* * Local copy of the session data. Can get out of sync, must be double-checked in datastore. */
60
62
internal lateinit var localSessionData: SessionData
61
63
64
+ override var isInForeground = false
65
+ private set
66
+
62
67
/* *
63
68
* Either notify the subscribers with general multi-process supported session or fallback local
64
69
* session
@@ -95,6 +100,7 @@ constructor(
95
100
}
96
101
97
102
override fun appBackground () {
103
+ isInForeground = false
98
104
if (! ::localSessionData.isInitialized) {
99
105
Log .d(TAG , " App backgrounded, but local SessionData not initialized" )
100
106
return
@@ -115,6 +121,7 @@ constructor(
115
121
}
116
122
117
123
override fun appForeground () {
124
+ isInForeground = true
118
125
if (! ::localSessionData.isInitialized) {
119
126
Log .d(TAG , " App foregrounded, but local SessionData not initialized" )
120
127
return
Original file line number Diff line number Diff line change @@ -38,8 +38,11 @@ object CrashEventReceiver {
38
38
@JvmStatic
39
39
fun notifyCrashOccurred () {
40
40
try {
41
- // Treat the crash as if the app went to the background, and update session state.
42
- SharedSessionRepository .instance.appBackground()
41
+ // Treat a foreground crash as if the app went to the background, and update session state.
42
+ val sharedSessionRepository = SharedSessionRepository .instance
43
+ if (sharedSessionRepository.isInForeground) {
44
+ sharedSessionRepository.appBackground()
45
+ }
43
46
} catch (_: Exception ) {
44
47
// Catch and suppress any exception to avoid crashing during crash handling.
45
48
// This can occur if Firebase or the SDK are in an unexpected state (e.g. FirebaseApp deleted)
You can’t perform that action at this time.
0 commit comments