forked from upstream-mirrors/quik
Check for sub id support before adding field
This commit is contained in:
@@ -24,6 +24,7 @@ import android.provider.Telephony
|
||||
import androidx.core.content.contentValuesOf
|
||||
import com.moez.QKSMS.model.BackupFile
|
||||
import com.moez.QKSMS.model.Message
|
||||
import com.moez.QKSMS.util.Preferences
|
||||
import com.moez.QKSMS.util.QkFileObserver
|
||||
import com.moez.QKSMS.util.tryOrNull
|
||||
import com.squareup.moshi.Moshi
|
||||
@@ -46,6 +47,7 @@ import kotlin.concurrent.schedule
|
||||
class BackupRepositoryImpl @Inject constructor(
|
||||
private val context: Context,
|
||||
private val moshi: Moshi,
|
||||
private val prefs: Preferences,
|
||||
private val syncRepo: SyncRepository
|
||||
) : BackupRepository {
|
||||
|
||||
@@ -193,7 +195,7 @@ class BackupRepositoryImpl @Inject constructor(
|
||||
restoreProgress.onNext(BackupRepository.Progress.Running(messageCount, index))
|
||||
|
||||
try {
|
||||
context.contentResolver.insert(Telephony.Sms.CONTENT_URI, contentValuesOf(
|
||||
val values = contentValuesOf(
|
||||
Telephony.Sms.TYPE to message.type,
|
||||
Telephony.Sms.ADDRESS to message.address,
|
||||
Telephony.Sms.DATE to message.date,
|
||||
@@ -204,9 +206,14 @@ class BackupRepositoryImpl @Inject constructor(
|
||||
Telephony.Sms.BODY to message.body,
|
||||
Telephony.Sms.PROTOCOL to message.protocol,
|
||||
Telephony.Sms.SERVICE_CENTER to message.serviceCenter,
|
||||
Telephony.Sms.LOCKED to message.locked,
|
||||
Telephony.Sms.SUBSCRIPTION_ID to message.subId)
|
||||
Telephony.Sms.LOCKED to message.locked
|
||||
)
|
||||
|
||||
if (prefs.canUseSubId.get()) {
|
||||
values.put(Telephony.Sms.SUBSCRIPTION_ID, message.subId)
|
||||
}
|
||||
|
||||
context.contentResolver.insert(Telephony.Sms.CONTENT_URI, values)
|
||||
} catch (e: Exception) {
|
||||
Timber.w(e)
|
||||
errorCount++
|
||||
|
||||
@@ -29,6 +29,7 @@ import android.os.Build
|
||||
import android.provider.Telephony
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import android.telephony.SmsManager
|
||||
import androidx.core.content.contentValuesOf
|
||||
import com.google.android.mms.ContentType
|
||||
import com.google.android.mms.MMSPart
|
||||
import com.klinker.android.send_message.SmsManagerFactory
|
||||
@@ -349,16 +350,20 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
realm.executeTransaction { managedMessage = realm.copyToRealmOrUpdate(message) }
|
||||
|
||||
// Insert the message to the native content provider
|
||||
val values = ContentValues().apply {
|
||||
put(Telephony.Sms.ADDRESS, address)
|
||||
put(Telephony.Sms.BODY, body)
|
||||
put(Telephony.Sms.DATE, System.currentTimeMillis())
|
||||
put(Telephony.Sms.READ, true)
|
||||
put(Telephony.Sms.SEEN, true)
|
||||
put(Telephony.Sms.TYPE, Telephony.Sms.MESSAGE_TYPE_OUTBOX)
|
||||
put(Telephony.Sms.THREAD_ID, threadId)
|
||||
put(Telephony.Sms.SUBSCRIPTION_ID, subId)
|
||||
val values = contentValuesOf(
|
||||
Telephony.Sms.ADDRESS to address,
|
||||
Telephony.Sms.BODY to body,
|
||||
Telephony.Sms.DATE to System.currentTimeMillis(),
|
||||
Telephony.Sms.READ to true,
|
||||
Telephony.Sms.SEEN to true,
|
||||
Telephony.Sms.TYPE to Telephony.Sms.MESSAGE_TYPE_OUTBOX,
|
||||
Telephony.Sms.THREAD_ID to threadId
|
||||
)
|
||||
|
||||
if (prefs.canUseSubId.get()) {
|
||||
values.put(Telephony.Sms.SUBSCRIPTION_ID, message.subId)
|
||||
}
|
||||
|
||||
val uri = context.contentResolver.insert(Telephony.Sms.CONTENT_URI, values)
|
||||
|
||||
// Update the contentId after the message has been inserted to the content provider
|
||||
@@ -400,11 +405,14 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
realm.executeTransaction { managedMessage = realm.copyToRealmOrUpdate(message) }
|
||||
|
||||
// Insert the message to the native content provider
|
||||
val values = ContentValues().apply {
|
||||
put(Telephony.Sms.ADDRESS, address)
|
||||
put(Telephony.Sms.BODY, body)
|
||||
put(Telephony.Sms.DATE_SENT, sentTime)
|
||||
put(Telephony.Sms.SUBSCRIPTION_ID, subId)
|
||||
val values = contentValuesOf(
|
||||
Telephony.Sms.ADDRESS to address,
|
||||
Telephony.Sms.BODY to body,
|
||||
Telephony.Sms.DATE_SENT to sentTime
|
||||
)
|
||||
|
||||
if (prefs.canUseSubId.get()) {
|
||||
values.put(Telephony.Sms.SUBSCRIPTION_ID, message.subId)
|
||||
}
|
||||
|
||||
context.contentResolver.insert(Telephony.Sms.Inbox.CONTENT_URI, values)?.let { uri ->
|
||||
|
||||
Reference in New Issue
Block a user