Merge pull request #687 from esensar/fix/duplicate-mms
Ensure that MMS reception ACK is sent to prevent duplicate MMS
This commit is contained in:
commit
eb35bf3761
|
@ -66,7 +66,7 @@ dependencies {
|
||||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:b4cc381943'
|
implementation 'com.github.SimpleMobileTools:Simple-Commons:b4cc381943'
|
||||||
implementation 'org.greenrobot:eventbus:3.3.1'
|
implementation 'org.greenrobot:eventbus:3.3.1'
|
||||||
implementation 'com.github.tibbi:IndicatorFastScroll:4524cd0b61'
|
implementation 'com.github.tibbi:IndicatorFastScroll:4524cd0b61'
|
||||||
implementation 'com.github.tibbi:android-smsmms:33fcaf94d9'
|
implementation 'com.github.tibbi:android-smsmms:5657799572'
|
||||||
implementation "me.leolin:ShortcutBadger:1.1.22"
|
implementation "me.leolin:ShortcutBadger:1.1.22"
|
||||||
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
|
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
|
||||||
implementation 'com.googlecode.ez-vcard:ez-vcard:0.11.3'
|
implementation 'com.googlecode.ez-vcard:ez-vcard:0.11.3'
|
||||||
|
|
|
@ -1,11 +1,17 @@
|
||||||
package com.simplemobiletools.smsmessenger
|
package com.simplemobiletools.smsmessenger
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
|
import com.klinker.android.send_message.ApnUtils
|
||||||
import com.simplemobiletools.commons.extensions.checkUseEnglish
|
import com.simplemobiletools.commons.extensions.checkUseEnglish
|
||||||
|
import com.simplemobiletools.commons.helpers.isRPlus
|
||||||
|
|
||||||
class App : Application() {
|
class App : Application() {
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
checkUseEnglish()
|
checkUseEnglish()
|
||||||
|
|
||||||
|
if (isRPlus()) {
|
||||||
|
ApnUtils.initDefaultApns(this) {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,16 +4,75 @@ import android.content.Context
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
|
import android.preference.PreferenceManager
|
||||||
|
import android.provider.Telephony
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
|
import com.klinker.android.send_message.MmsReceivedReceiver
|
||||||
|
import com.simplemobiletools.commons.extensions.getStringValue
|
||||||
import com.simplemobiletools.commons.extensions.isNumberBlocked
|
import com.simplemobiletools.commons.extensions.isNumberBlocked
|
||||||
import com.simplemobiletools.commons.extensions.normalizePhoneNumber
|
import com.simplemobiletools.commons.extensions.normalizePhoneNumber
|
||||||
|
import com.simplemobiletools.commons.extensions.queryCursor
|
||||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
|
import com.simplemobiletools.commons.helpers.isQPlus
|
||||||
|
import com.simplemobiletools.commons.helpers.isRPlus
|
||||||
import com.simplemobiletools.smsmessenger.R
|
import com.simplemobiletools.smsmessenger.R
|
||||||
import com.simplemobiletools.smsmessenger.extensions.*
|
import com.simplemobiletools.smsmessenger.extensions.*
|
||||||
import com.simplemobiletools.smsmessenger.helpers.refreshMessages
|
import com.simplemobiletools.smsmessenger.helpers.refreshMessages
|
||||||
|
|
||||||
// more info at https://github.com/klinker41/android-smsmms
|
// more info at https://github.com/klinker41/android-smsmms
|
||||||
class MmsReceiver : com.klinker.android.send_message.MmsReceivedReceiver() {
|
class MmsReceiver : MmsReceivedReceiver() {
|
||||||
|
|
||||||
|
private var carriers = mutableMapOf<Int, MmscInformation>()
|
||||||
|
|
||||||
|
private fun populateMmscInformation(context: Context, subscriptionId: Int) {
|
||||||
|
if (isRPlus() && carriers.isNotEmpty()) {
|
||||||
|
// This information is stored by ApnUtils from android-smsmms
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(context).apply {
|
||||||
|
carriers[0] = MmscInformation(
|
||||||
|
getString("mmsc_url", ""),
|
||||||
|
getString("mms_proxy", ""),
|
||||||
|
getString("mms_port", "0")?.toInt() ?: 0
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (carriers.containsKey(subscriptionId).not()) {
|
||||||
|
val baseUri = if (isQPlus()) {
|
||||||
|
Telephony.Carriers.SIM_APN_URI
|
||||||
|
} else {
|
||||||
|
Telephony.Carriers.CONTENT_URI
|
||||||
|
}
|
||||||
|
val uri = Uri.withAppendedPath(baseUri, subscriptionId.toString())
|
||||||
|
val projection = arrayOf(
|
||||||
|
Telephony.Carriers.MMSC,
|
||||||
|
Telephony.Carriers.MMSPROXY,
|
||||||
|
Telephony.Carriers.MMSPORT,
|
||||||
|
)
|
||||||
|
val selection = "${Telephony.Carriers.TYPE} LIKE ?"
|
||||||
|
val selectionArgs = arrayOf("%mms%")
|
||||||
|
|
||||||
|
context.queryCursor(uri, projection = projection, selection = selection, selectionArgs = selectionArgs) { cursor ->
|
||||||
|
carriers[subscriptionId] = MmscInformation(
|
||||||
|
cursor.getStringValue(Telephony.Carriers.MMSC),
|
||||||
|
cursor.getStringValue(Telephony.Carriers.MMSPROXY),
|
||||||
|
cursor.getStringValue(Telephony.Carriers.MMSPORT).toIntOrNull() ?: 0,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getMmscInformation(subscriptionId: Int): MmscInformation? {
|
||||||
|
return if (isRPlus()) {
|
||||||
|
carriers[0]
|
||||||
|
} else {
|
||||||
|
carriers[subscriptionId]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getMmscInfoForReceptionAck(context: Context, subscriptionId: Int): MmscInformation? {
|
||||||
|
populateMmscInformation(context, subscriptionId)
|
||||||
|
return getMmscInformation(subscriptionId)
|
||||||
|
}
|
||||||
|
|
||||||
override fun isAddressBlocked(context: Context, address: String): Boolean {
|
override fun isAddressBlocked(context: Context, address: String): Boolean {
|
||||||
val normalizedAddress = address.normalizePhoneNumber()
|
val normalizedAddress = address.normalizePhoneNumber()
|
||||||
|
|
Loading…
Reference in New Issue