Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 16409db6 authored by moezbhatti's avatar moezbhatti
Browse files

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

parent b4ac3fc0
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -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,6 +188,7 @@ class BackupRepositoryImpl @Inject constructor(
            // Update the progress
            restoreProgress.onNext(BackupRepository.Progress.Running(messageCount, index))

            try {
                context.contentResolver.insert(Telephony.Sms.CONTENT_URI, contentValuesOf(
                    Telephony.Sms.TYPE to message.type,
                    Telephony.Sms.ADDRESS to message.address,
@@ -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