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

Try catch for datastore write #5833

Merged
merged 10 commits into from
Apr 17, 2024
2 changes: 2 additions & 0 deletions firebase-sessions/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Unreleased

* [fixed] Handled datastore writes when device has full internal memory more gracefully.

# 1.2.3

* [fixed] Force validation or rotation of FIDs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.datastore.preferences.preferencesDataStore
import com.google.firebase.Firebase
import com.google.firebase.app
import com.google.firebase.sessions.ProcessDetailsProvider.getProcessName
import java.io.IOException
import java.util.concurrent.atomic.AtomicReference
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -84,8 +85,15 @@ internal class SessionDatastoreImpl(

override fun updateSessionId(sessionId: String) {
CoroutineScope(backgroundDispatcher).launch {
context.dataStore.edit { preferences ->
preferences[FirebaseSessionDataKeys.SESSION_ID] = sessionId
try {
context.dataStore.edit { preferences ->
preferences[FirebaseSessionDataKeys.SESSION_ID] = sessionId
}
} catch (e: IOException) {
Log.w(
TAG,
"Failed to update session Id: $e",
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,16 @@ internal class SettingsCache(private val dataStore: DataStore<Preferences>) {

@VisibleForTesting
internal suspend fun removeConfigs() {
dataStore.edit { preferences ->
preferences.clear()
updateSessionConfigs(preferences)
try {
dataStore.edit { preferences ->
preferences.clear()
updateSessionConfigs(preferences)
}
} catch (e: IOException) {
Log.w(
TAG,
"Failed to remove config values: $e",
)
}
}

Expand Down
Loading