Skip to content

Commit

Permalink
Fallback back to Telephony create thread in MMS export on failure.
Browse files Browse the repository at this point in the history
  • Loading branch information
cody-signal authored and greyson-signal committed Apr 12, 2023
1 parent 055f4b0 commit 07c32e2
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package org.signal.smsexporter.internal.mms

import android.content.Context
import android.database.sqlite.SQLiteException
import android.os.Build
import android.provider.Telephony
import com.klinker.android.send_message.Utils
import org.signal.core.util.Try
import org.signal.core.util.logging.Log
import org.signal.smsexporter.ExportableMessage

/**
Expand All @@ -12,6 +16,9 @@ import org.signal.smsexporter.ExportableMessage
* This method will also filter out messages that do not have addresses.
*/
internal object GetOrCreateMmsThreadIdsUseCase {

private val TAG = Log.tag(GetOrCreateMmsThreadIdsUseCase::class.java)

fun execute(
context: Context,
mms: ExportableMessage.Mms<*>,
Expand All @@ -31,7 +38,16 @@ internal object GetOrCreateMmsThreadIdsUseCase {
return if (cache.containsKey(recipients)) {
cache[recipients]!!
} else {
val threadId = Utils.getOrCreateThreadId(context, recipients)
val threadId = try {
Utils.getOrCreateThreadId(context, recipients)
} catch (e: SQLiteException) {
Log.w(TAG, "Unable to create thread using Klinker, falling back to system if possible")
if (Build.VERSION.SDK_INT >= 23) {
Telephony.Threads.getOrCreateThreadId(context, recipients)
} else {
throw e
}
}
cache[recipients] = threadId
threadId
}
Expand Down

0 comments on commit 07c32e2

Please sign in to comment.