mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-21 19:48:29 +00:00
Be more lenient when backing up possibly-invalid recipients.
This commit is contained in:
@@ -8,6 +8,7 @@ package org.thoughtcrime.securesms.backup.v2.exporters
|
|||||||
import android.database.Cursor
|
import android.database.Cursor
|
||||||
import okio.ByteString.Companion.toByteString
|
import okio.ByteString.Companion.toByteString
|
||||||
import org.signal.core.util.Base64
|
import org.signal.core.util.Base64
|
||||||
|
import org.signal.core.util.logging.Log
|
||||||
import org.signal.core.util.requireBoolean
|
import org.signal.core.util.requireBoolean
|
||||||
import org.signal.core.util.requireInt
|
import org.signal.core.util.requireInt
|
||||||
import org.signal.core.util.requireLong
|
import org.signal.core.util.requireLong
|
||||||
@@ -26,12 +27,17 @@ import java.io.Closeable
|
|||||||
* Provides a nice iterable interface over a [RecipientTable] cursor, converting rows to [ArchiveRecipient]s.
|
* Provides a nice iterable interface over a [RecipientTable] cursor, converting rows to [ArchiveRecipient]s.
|
||||||
* Important: Because this is backed by a cursor, you must close it. It's recommended to use `.use()` or try-with-resources.
|
* Important: Because this is backed by a cursor, you must close it. It's recommended to use `.use()` or try-with-resources.
|
||||||
*/
|
*/
|
||||||
class ContactArchiveExporter(private val cursor: Cursor, private val selfId: Long) : Iterator<ArchiveRecipient>, Closeable {
|
class ContactArchiveExporter(private val cursor: Cursor, private val selfId: Long) : Iterator<ArchiveRecipient?>, Closeable {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val TAG = Log.tag(ContactArchiveExporter::class)
|
||||||
|
}
|
||||||
|
|
||||||
override fun hasNext(): Boolean {
|
override fun hasNext(): Boolean {
|
||||||
return cursor.count > 0 && !cursor.isLast
|
return cursor.count > 0 && !cursor.isLast
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun next(): ArchiveRecipient {
|
override fun next(): ArchiveRecipient? {
|
||||||
if (!cursor.moveToNext()) {
|
if (!cursor.moveToNext()) {
|
||||||
throw NoSuchElementException()
|
throw NoSuchElementException()
|
||||||
}
|
}
|
||||||
@@ -49,7 +55,8 @@ class ContactArchiveExporter(private val cursor: Cursor, private val selfId: Lon
|
|||||||
val e164 = cursor.requireString(RecipientTable.E164)?.e164ToLong()
|
val e164 = cursor.requireString(RecipientTable.E164)?.e164ToLong()
|
||||||
|
|
||||||
if (aci == null && pni == null && e164 == null) {
|
if (aci == null && pni == null && e164 == null) {
|
||||||
throw IllegalStateException("Should not happen! Query guards against this.")
|
Log.w(TAG, "All identifiers are null! Before parsing, ACI: ${cursor.requireString(RecipientTable.ACI_COLUMN) != null}, PNI: ${cursor.requireString(RecipientTable.PNI_COLUMN) != null}, E164: ${cursor.requireString(RecipientTable.E164) != null}")
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
val contactBuilder = Contact.Builder()
|
val contactBuilder = Contact.Builder()
|
||||||
|
|||||||
@@ -51,8 +51,10 @@ object RecipientArchiveProcessor {
|
|||||||
|
|
||||||
db.recipientTable.getContactsForBackup(selfId).use { reader ->
|
db.recipientTable.getContactsForBackup(selfId).use { reader ->
|
||||||
for (recipient in reader) {
|
for (recipient in reader) {
|
||||||
exportState.recipientIds.add(recipient.id)
|
if (recipient != null) {
|
||||||
emitter.emit(Frame(recipient = recipient))
|
exportState.recipientIds.add(recipient.id)
|
||||||
|
emitter.emit(Frame(recipient = recipient))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user