Skip to content

Commit 4534229

Browse files
authored
Fix crash when trying to get active notifications (#5085)
Sometimes something goes wrong when unmarshalling them
1 parent 6017379 commit 4534229

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/ActiveNotificationsProvider.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ package io.element.android.libraries.push.impl.notifications
1010
import android.service.notification.StatusBarNotification
1111
import androidx.core.app.NotificationManagerCompat
1212
import com.squareup.anvil.annotations.ContributesBinding
13+
import io.element.android.libraries.core.extensions.runCatchingExceptions
1314
import io.element.android.libraries.di.AppScope
1415
import io.element.android.libraries.matrix.api.core.RoomId
1516
import io.element.android.libraries.matrix.api.core.SessionId
1617
import io.element.android.libraries.push.api.notifications.NotificationIdProvider
18+
import timber.log.Timber
1719
import javax.inject.Inject
1820

1921
interface ActiveNotificationsProvider {
@@ -30,7 +32,12 @@ class DefaultActiveNotificationsProvider @Inject constructor(
3032
private val notificationManager: NotificationManagerCompat,
3133
) : ActiveNotificationsProvider {
3234
override fun getNotificationsForSession(sessionId: SessionId): List<StatusBarNotification> {
33-
return notificationManager.activeNotifications.filter { it.notification.group == sessionId.value }
35+
return runCatchingExceptions { notificationManager.activeNotifications }
36+
.onFailure {
37+
Timber.e(it, "Failed to get active notifications")
38+
}
39+
.getOrElse { emptyList() }
40+
.filter { it.notification.group == sessionId.value }
3441
}
3542

3643
override fun getMembershipNotificationForSession(sessionId: SessionId): List<StatusBarNotification> {

0 commit comments

Comments
 (0)