#1332 - Don't allow bad message to break restore, send log when messages fail to restore

This commit is contained in:
moezbhatti
2019-03-04 23:43:36 -05:00
parent b4ac3fc0f0
commit 16409db689
@@ -176,6 +176,7 @@ class BackupRepositoryImpl @Inject constructor(
}
val messageCount = backup?.messages?.size ?: 0
var errorCount = 0
backup?.messages?.forEachIndexed { index, message ->
if (stopFlag) {
@@ -187,7 +188,8 @@ class BackupRepositoryImpl @Inject constructor(
// Update the progress
restoreProgress.onNext(BackupRepository.Progress.Running(messageCount, index))
context.contentResolver.insert(Telephony.Sms.CONTENT_URI, contentValuesOf(
try {
context.contentResolver.insert(Telephony.Sms.CONTENT_URI, contentValuesOf(
Telephony.Sms.TYPE to message.type,
Telephony.Sms.ADDRESS to message.address,
Telephony.Sms.DATE to message.date,
@@ -200,6 +202,14 @@ class BackupRepositoryImpl @Inject constructor(
Telephony.Sms.SERVICE_CENTER to message.serviceCenter,
Telephony.Sms.LOCKED to message.locked,
Telephony.Sms.SUBSCRIPTION_ID to message.subId))
} catch (e: Exception) {
Timber.w(e)
errorCount++
}
}
if (errorCount > 0) {
Timber.w(Exception("Failed to backup $errorCount/$messageCount messages"))
}
// Sync the messages