Fix potential crash during notification processing.

This commit is contained in:
Greyson Parrelli
2021-09-14 09:18:27 -04:00
parent 8df86962e9
commit 8815cdc3de

View File

@@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.notifications.v2
import android.content.Context
import androidx.annotation.WorkerThread
import org.signal.core.util.logging.Log
import org.thoughtcrime.securesms.database.DatabaseFactory
import org.thoughtcrime.securesms.database.MmsSmsColumns
import org.thoughtcrime.securesms.database.MmsSmsDatabase
@@ -10,12 +11,15 @@ import org.thoughtcrime.securesms.database.model.MessageRecord
import org.thoughtcrime.securesms.database.model.ReactionRecord
import org.thoughtcrime.securesms.recipients.Recipient
import org.thoughtcrime.securesms.util.CursorUtil
import java.lang.IllegalStateException
/**
* Queries the message databases to determine messages that should be in notifications.
*/
object NotificationStateProvider {
private val TAG = Log.tag(NotificationStateProvider::class.java)
@WorkerThread
fun constructNotificationState(context: Context, stickyThreads: Map<Long, MessageNotifierV2.StickyThread>): NotificationStateV2 {
val messages: MutableList<NotificationMessage> = mutableListOf()
@@ -40,7 +44,13 @@ object NotificationStateProvider {
lastReactionRead = CursorUtil.requireLong(unreadMessages, MmsSmsColumns.REACTIONS_LAST_SEEN)
)
}
record = reader.next
try {
record = reader.next
} catch (e: IllegalStateException) {
// XXX Weird SQLCipher bug that's being investigated
record = null
Log.w(TAG, "Failed to read next record!", e)
}
}
}
}