@@ -127,10 +127,16 @@ internal class SessionLifecycleService : Service() {
127127
128128 /* * Generates a new session id and sends it everywhere it's needed */
129129 private fun newSession () {
130- SessionGenerator .instance.generateNewSession()
131- Log .d(TAG , " Generated new session." )
132- broadcastSession()
133- SessionDatastore .instance.updateSessionId(SessionGenerator .instance.currentSession.sessionId)
130+ try {
131+ SessionGenerator .instance.generateNewSession()
132+ Log .d(TAG , " Generated new session." )
133+ broadcastSession()
134+ SessionDatastore .instance.updateSessionId(
135+ SessionGenerator .instance.currentSession.sessionId
136+ )
137+ } catch (ex: IllegalStateException ) {
138+ Log .w(TAG , " Failed to generate new session." , ex)
139+ }
134140 }
135141
136142 /* *
@@ -149,10 +155,14 @@ internal class SessionLifecycleService : Service() {
149155 if (hasForegrounded) {
150156 sendSessionToClient(client, SessionGenerator .instance.currentSession.sessionId)
151157 } else {
152- // Send the value from the datastore before the first foregrounding it exists
153- val storedSession = SessionDatastore .instance.getCurrentSessionId()
154- Log .d(TAG , " App has not yet foregrounded. Using previously stored session." )
155- storedSession?.let { sendSessionToClient(client, it) }
158+ try {
159+ // Send the value from the datastore before the first foregrounding it exists
160+ val storedSession = SessionDatastore .instance.getCurrentSessionId()
161+ Log .d(TAG , " App has not yet foregrounded. Using previously stored session." )
162+ storedSession?.let { sendSessionToClient(client, it) }
163+ } catch (ex: IllegalStateException ) {
164+ Log .w(TAG , " Failed to send session to client." , ex)
165+ }
156166 }
157167 }
158168
0 commit comments