add delay send mms. add group send to individual recipients - sms and mms. add immediate show messages in convo, not wait for sent. new qktransaction that replaces android/smsmms transaction with mods for quik. lots of code cleanups and removing superfluous code. some bug fixes.

This commit is contained in:
gavine99
2025-04-10 16:59:35 +10:00
parent 6f70c8e932
commit 2810b56cd0
375 changed files with 20297 additions and 3161 deletions
@@ -27,6 +27,7 @@ import dev.octoshrimpy.quik.repository.ConversationRepository
import dev.octoshrimpy.quik.util.Preferences
import dagger.android.AndroidInjection
import io.reactivex.schedulers.Schedulers
import timber.log.Timber
import javax.inject.Inject
class BlockThreadReceiver : BroadcastReceiver() {
@@ -39,6 +40,8 @@ class BlockThreadReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
AndroidInjection.inject(this, context)
Timber.v("received")
val threadId = intent.getLongExtra("threadId", 0)
blockingClient
@@ -23,19 +23,25 @@ import android.content.Context
import android.content.Intent
import dev.octoshrimpy.quik.interactor.DeleteMessages
import dagger.android.AndroidInjection
import timber.log.Timber
import javax.inject.Inject
class DeleteMessagesReceiver : BroadcastReceiver() {
@Inject lateinit var deleteMessages: DeleteMessages
override fun onReceive(context: Context, intent: Intent) {
AndroidInjection.inject(this, context)
val pendingResult = goAsync()
val threadId = intent.getLongExtra("threadId", 0)
val messageIds = intent.getLongArrayExtra("messageIds") ?: longArrayOf()
deleteMessages.execute(DeleteMessages.Params(messageIds.toList(), threadId)) { pendingResult.finish() }
Timber.v("received")
intent.getLongExtra("threadId", 0).takeIf { it > 0 }?.let { threadId ->
intent.getLongArrayExtra("messageIds")?.let { messageIds ->
val pendingResult = goAsync()
deleteMessages.execute(DeleteMessages.Params(messageIds.toList(), threadId)) {
pendingResult.finish()
}
}
}
}
}
@@ -1,40 +0,0 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package dev.octoshrimpy.quik.receiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import dev.octoshrimpy.quik.interactor.MarkArchived
import dagger.android.AndroidInjection
import javax.inject.Inject
class MarkArchivedReceiver : BroadcastReceiver() {
@Inject lateinit var markArchived: MarkArchived
override fun onReceive(context: Context, intent: Intent) {
AndroidInjection.inject(this, context)
val pendingResult = goAsync()
val threadId = intent.getLongExtra("threadId", 0)
markArchived.execute(listOf(threadId)) { pendingResult.finish() }
}
}
@@ -1,40 +0,0 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package dev.octoshrimpy.quik.receiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import dev.octoshrimpy.quik.interactor.MarkRead
import dagger.android.AndroidInjection
import javax.inject.Inject
class MarkReadReceiver : BroadcastReceiver() {
@Inject lateinit var markRead: MarkRead
override fun onReceive(context: Context, intent: Intent) {
AndroidInjection.inject(this, context)
val pendingResult = goAsync()
val threadId = intent.getLongExtra("threadId", 0)
markRead.execute(listOf(threadId)) { pendingResult.finish() }
}
}
@@ -1,40 +0,0 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package dev.octoshrimpy.quik.receiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import dev.octoshrimpy.quik.interactor.MarkSeen
import dagger.android.AndroidInjection
import javax.inject.Inject
class MarkSeenReceiver : BroadcastReceiver() {
@Inject lateinit var markSeen: MarkSeen
override fun onReceive(context: Context, intent: Intent) {
AndroidInjection.inject(this, context)
val pendingResult = goAsync()
val threadId = intent.getLongExtra("threadId", 0)
markSeen.execute(threadId) { pendingResult.finish() }
}
}
@@ -25,9 +25,13 @@ import android.content.Intent
import dev.octoshrimpy.quik.interactor.MarkDelivered
import dev.octoshrimpy.quik.interactor.MarkDeliveryFailed
import dagger.android.AndroidInjection
import timber.log.Timber
import javax.inject.Inject
class SmsDeliveredReceiver : BroadcastReceiver() {
class MessageDeliveredReceiver : BroadcastReceiver() {
companion object {
const val EXTRA_QUIK_MESSAGE_ID = "messageId"
}
@Inject lateinit var markDelivered: MarkDelivered
@Inject lateinit var markDeliveryFailed: MarkDeliveryFailed
@@ -35,21 +39,25 @@ class SmsDeliveredReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
AndroidInjection.inject(this, context)
val id = intent.getLongExtra("id", 0L)
Timber.v("received")
when (resultCode) {
// TODO notify about delivery
Activity.RESULT_OK -> {
intent.extras?.getLong(EXTRA_QUIK_MESSAGE_ID)?.takeIf { it > 0 }
?.let { messageId ->
val pendingResult = goAsync()
markDelivered.execute(id) { pendingResult.finish() }
}
// TODO notify about delivery failure
Activity.RESULT_CANCELED -> {
val pendingResult = goAsync()
markDeliveryFailed.execute(MarkDeliveryFailed.Params(id, resultCode)) { pendingResult.finish() }
}
}
Timber.v("resultcode: ${pendingResult.resultCode}")
when (pendingResult.resultCode) {
// TODO notify about delivery
Activity.RESULT_OK -> markDelivered.execute(messageId) { pendingResult.finish() }
// TODO notify about delivery failure
else ->
markDeliveryFailed.execute(MarkDeliveryFailed.Params(messageId, resultCode)) {
pendingResult.finish()
}
}
} ?: let { Timber.e("couldn't get message id") }
}
}
@@ -0,0 +1,67 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package dev.octoshrimpy.quik.receiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import dagger.android.AndroidInjection
import dev.octoshrimpy.quik.interactor.MarkArchived
import dev.octoshrimpy.quik.interactor.MarkSeen
import dev.octoshrimpy.quik.interactor.MarkRead
import timber.log.Timber
import javax.inject.Inject
class MessageMarkReceiver : BroadcastReceiver() {
enum class MarkType {
Seen,
Read,
Archived
}
@Inject lateinit var markSeen: MarkSeen
@Inject lateinit var markRead: MarkRead
@Inject lateinit var markArchived: MarkArchived
override fun onReceive(context: Context, intent: Intent) {
AndroidInjection.inject(this, context)
Timber.v("received")
intent.getLongExtra("threadId", 0).takeIf { it > 0 }?.let { threadId ->
intent.getIntExtra("type", -1).takeIf { it >= 0 }?.let { type ->
val pendingResult = goAsync()
when (type) {
MarkType.Seen.ordinal -> markSeen.execute(threadId) {
pendingResult.finish()
}
MarkType.Read.ordinal -> markRead.execute(listOf(threadId)) {
pendingResult.finish()
}
MarkType.Archived.ordinal -> markArchived.execute(listOf(threadId)) {
pendingResult.finish()
}
}
} ?:let { Timber.e("didn't get a valid type") }
} ?:let { Timber.e("didn't get a valid thread id") }
}
}
@@ -0,0 +1,79 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package dev.octoshrimpy.quik.receiver
import android.app.Activity
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.klinker.android.send_message.MmsSentReceiver.EXTRA_FILE_PATH
import dagger.android.AndroidInjection
import dev.octoshrimpy.quik.interactor.MarkFailed
import dev.octoshrimpy.quik.interactor.MarkSent
import dev.octoshrimpy.quik.repository.MessageRepository
import timber.log.Timber
import java.io.File
import javax.inject.Inject
class MessageSentReceiver : BroadcastReceiver() {
companion object {
const val EXTRA_QUIK_MESSAGE_ID = "messageId"
const val EXTRA_IS_NOTIFY = "isNotify"
}
@Inject lateinit var markSent: MarkSent
@Inject lateinit var markFailed: MarkFailed
@Inject lateinit var messageRepo: MessageRepository
override fun onReceive(context: Context?, intent: Intent) {
AndroidInjection.inject(this, context)
Timber.v("received")
// if have EXTRA_FILE_PATH then need to delete mms cache file
intent.extras?.getString(EXTRA_FILE_PATH)?.let { filePath ->
Timber.v("delete mms temp file $filePath")
File(filePath).delete()
}
if (intent.extras?.getInt(EXTRA_IS_NOTIFY, -1) != -1) {
Timber.v("notify message sent resultcode $resultCode")
return
}
intent.extras?.getLong(EXTRA_QUIK_MESSAGE_ID)?.takeIf { it > 0 }
?.let { messageId ->
Timber.v("resultcode: $resultCode")
val pendingResult = goAsync()
when (pendingResult.resultCode) {
Activity.RESULT_OK ->
markSent.execute(messageId) { pendingResult.finish() }
else -> markFailed.execute(
MarkFailed.Params(messageId, pendingResult.resultCode)
) {
pendingResult.finish()
}
}
} ?: let { Timber.e("couldn't get message id") }
}
}
@@ -1,45 +1,333 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
* Copyright (C) 2015 Jacob Klinker
*
* This file is part of QKSMS.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* QKSMS is free software: you can redistribute it and/or modify
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
* modifications from original:
* Copyright (C) 2025
*
* This file is part of QUIK.
*
* QUIK is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* QUIK is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
* along with QUIK. If not, see <http://www.gnu.org/licenses/>.
*/
package dev.octoshrimpy.quik.receiver
import android.app.PendingIntent
import android.content.BroadcastReceiver
import android.content.ContentResolver
import android.content.Context
import android.content.Intent
import android.net.Uri
import com.klinker.android.send_message.MmsReceivedReceiver
import android.os.AsyncTask
import android.os.Parcelable
import android.provider.Telephony
import android.telephony.SmsManager
import androidx.core.net.toUri
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.OutOfQuotaPolicy
import androidx.work.WorkManager
import androidx.work.workDataOf
import com.android.mms.service_alt.DownloadRequest
import com.android.mms.service_alt.MmsConfig
import com.android.mms.service_alt.MmsConfig.Overridden
import com.android.mms.transaction.DownloadManager
import com.google.android.mms.pdu_alt.AcknowledgeInd
import com.google.android.mms.pdu_alt.EncodedStringValue
import com.google.android.mms.pdu_alt.NotificationInd
import com.google.android.mms.pdu_alt.NotifyRespInd
import com.google.android.mms.pdu_alt.PduComposer
import com.google.android.mms.pdu_alt.PduHeaders
import com.google.android.mms.pdu_alt.PduParser
import com.google.android.mms.pdu_alt.PduPersister
import com.google.android.mms.pdu_alt.RetrieveConf
import com.google.android.mms.util_alt.SqliteWrapper
import com.klinker.android.send_message.MmsSentReceiver
import com.klinker.android.send_message.SmsManagerFactory
import com.klinker.android.send_message.Utils
import dev.octoshrimpy.quik.interactor.ReceiveMms
import dagger.android.AndroidInjection
import javax.inject.Inject
import dev.octoshrimpy.quik.worker.ReceiveMmsWorker
import dev.octoshrimpy.quik.worker.ReceiveMmsWorker.Companion.INPUT_DATA_EXTRA_FILE_PATH
import dev.octoshrimpy.quik.worker.ReceiveMmsWorker.Companion.INPUT_DATA_EXTRA_LOCATION_URL
import dev.octoshrimpy.quik.worker.ReceiveMmsWorker.Companion.INPUT_DATA_EXTRA_MMS_HTTP_STATUS
import dev.octoshrimpy.quik.worker.ReceiveMmsWorker.Companion.INPUT_DATA_EXTRA_URI
import dev.octoshrimpy.quik.worker.ReceiveMmsWorker.Companion.INPUT_DATA_SUBSCRIPTION_ID
import timber.log.Timber
import java.io.File
import java.io.FileInputStream
import java.io.FileNotFoundException
import java.io.FileOutputStream
import java.io.IOException
import java.util.UUID
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
class MmsReceivedReceiver : MmsReceivedReceiver() {
class MmsReceivedReceiver : BroadcastReceiver() {
companion object {
const val EXTRA_FILE_PATH: String = "file_path"
const val EXTRA_LOCATION_URL: String = "location_url"
const val EXTRA_URI: String = "notification_ind_uri"
const val SUBSCRIPTION_ID: String = "subscription_id"
@Inject lateinit var receiveMms: ReceiveMms
private const val LOCATION_SELECTION =
Telephony.Mms.MESSAGE_TYPE + "=? AND " + Telephony.Mms.CONTENT_LOCATION + " =?"
override fun onReceive(context: Context?, intent: Intent?) {
AndroidInjection.inject(this, context)
super.onReceive(context, intent)
}
private val RECEIVE_NOTIFICATION_EXECUTOR: ExecutorService =
Executors.newSingleThreadExecutor()
override fun onMessageReceived(messageUri: Uri?) {
messageUri?.let { uri ->
val pendingResult = goAsync()
receiveMms.execute(uri) { pendingResult.finish() }
private fun getNotificationInd(context: Context, extraUri: String) =
PduPersister.getPduPersister(context).load(extraUri.toUri()) as NotificationInd
fun onReceiveWorker(
context: Context, subscriptionId: Int, filePath: String, locationUrl: String,
mmsHttpStatus: Int, extraUri: String, receiveMms: ReceiveMms
) {
if (filePath.isEmpty()) {
Timber.e("empty file path")
return
}
if (locationUrl.isEmpty()) {
Timber.e("empty location url")
return
}
if (extraUri.isEmpty()) {
Timber.e("empty extra uri")
return
}
Timber.v(filePath)
val downloadFile = File(filePath)
try {
// read file into a bytearray
val mmsData = FileInputStream(downloadFile).use { inputStream ->
val fileLength = downloadFile.length().toInt()
ByteArray(fileLength).let { bytes ->
inputStream.read(bytes, 0, fileLength)
bytes
}
}
Timber.v("response buffered length: ${mmsData.size}")
if (mmsData.isNotEmpty()) {
val notificationTasks =
getNotificationTasks(context, subscriptionId, extraUri, mmsData)
// persist message
val messageUri = DownloadRequest.persist(
context, mmsData, Overridden(MmsConfig(context), null),
locationUrl, subscriptionId, null
)
// run notifiers to notify back to mmsc
Timber.v("running the common async notifier for download")
for (task in notificationTasks)
task.executeOnExecutor(RECEIVE_NOTIFICATION_EXECUTOR)
handleHttpError(context, mmsHttpStatus, locationUrl)
DownloadManager.finishDownload(locationUrl)
// message is 'raw' received, so do quik app processing
if (messageUri != null)
receiveMms.execute(messageUri)
}
else Timber.e("empty mms data")
} catch (e: FileNotFoundException) {
Timber.e("file not found", e)
} catch (e: IOException) {
Timber.e("io exception", e)
} finally {
downloadFile.delete()
}
}
private fun handleHttpError(context: Context, mmsHttpStatus: Int, locationUrl: String) {
if ((mmsHttpStatus == 404) || (mmsHttpStatus == 400)) {
// Delete the corresponding NotificationInd
SqliteWrapper.delete(
context, context.contentResolver, Telephony.Mms.CONTENT_URI,
LOCATION_SELECTION,
arrayOf(
PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND.toString(),
locationUrl
)
)
}
}
private abstract class CommonAsyncTask(
protected val mContext: Context, private val subscriptionId: Int,
protected val mNotificationInd: NotificationInd
) : AsyncTask<Void?, Void?, Void?>() {
fun sendPdu(pduBytes: ByteArray) {
// write pdu bytes to temporary file
val fileName = "send.notify.${UUID.randomUUID()}.dat"
val contentUri = Uri.Builder()
.authority("${mContext.packageName}.MmsFileProvider")
.path(fileName)
.scheme(ContentResolver.SCHEME_CONTENT)
.build()
try {
FileOutputStream(File(mContext.cacheDir, fileName)).use { outputStream ->
outputStream.write(pduBytes)
}
Timber.v("notify send file $fileName")
} catch (e: Exception) {
Timber.e("error writing notify send file", e)
}
val useWapMmsc = com.android.mms.MmsConfig.getNotifyWapMMSC()
if (useWapMmsc)
Timber.v("using content location for wap mmsc")
SmsManagerFactory.createSmsManager(subscriptionId).sendMultimediaMessage(
mContext, contentUri,
if (useWapMmsc) String(mNotificationInd.contentLocation)
else null,
null,
PendingIntent.getBroadcast(
mContext, 0,
Intent(mContext, MessageSentReceiver::class.java)
.putExtra(MmsSentReceiver.EXTRA_FILE_PATH, fileName)
.putExtra(MessageSentReceiver.EXTRA_IS_NOTIFY, 1),
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
)
}
}
private class NotifyRespTask(context: Context, subscriptionId: Int, ind: NotificationInd) :
CommonAsyncTask(context, subscriptionId, ind) {
override fun doInBackground(vararg params: Void?): Void? {
// Create the M-NotifyResp.ind
Timber.v("create m-notifyresp.ind")
try {
val notifyRespInd = NotifyRespInd(
PduHeaders.CURRENT_MMS_VERSION,
mNotificationInd.transactionId,
PduHeaders.STATUS_RETRIEVED
)
// Pack M-NotifyResp.ind and send it
sendPdu(PduComposer(mContext, notifyRespInd).make())
} catch (e: Exception) {
Timber.e("error creating m-notifyresp.ind", e)
}
return null
}
}
private class AcknowledgeIndTask(
context: Context, subscriptionId: Int, ind: NotificationInd,
private val mRetrieveConf: RetrieveConf
) : CommonAsyncTask(context, subscriptionId, ind) {
override fun doInBackground(vararg params: Void?): Void? {
// Send M-Acknowledge.ind to MMSC if required.
// If the Transaction-ID isn't set in the M-Retrieve.conf, it means
// the MMS proxy-relay doesn't require an ACK.
Timber.v("create m-acknowledge.ind")
mRetrieveConf.transactionId?.let { tranId ->
// Create M-Acknowledge.ind
try {
val acknowledgeInd = AcknowledgeInd(PduHeaders.CURRENT_MMS_VERSION, tranId)
// insert the 'from' address per spec
acknowledgeInd.from = EncodedStringValue(
Utils.getMyPhoneNumber(mContext).orEmpty()
)
// Pack M-Acknowledge.ind and send it
sendPdu(PduComposer(mContext, acknowledgeInd).make())
} catch (e: Exception) {
Timber.e("error creating m-acknowledge.ind", e)
}
} ?: let { Timber.e("no transaction id for creating m-acknowledge.ind") }
return null
}
}
private fun getNotificationTasks(
context: Context, subscriptionId: Int, extraUri: String, mmsData: ByteArray
): List<CommonAsyncTask> {
val pdu = PduParser(
mmsData,
Overridden(MmsConfig(context), null).supportMmsContentDisposition
).parse()
if (pdu is RetrieveConf) {
try {
Timber.v("create notification tasks")
return getNotificationInd(context, extraUri).let { notificationInd ->
listOf(
AcknowledgeIndTask(context, subscriptionId, notificationInd, pdu),
NotifyRespTask(context, subscriptionId, notificationInd)
)
}
} catch (e: Exception) {
Timber.e("error get notification tasks", e)
}
} else
Timber.e("MmsReceivedReceiver.sendNotification failed to parse pdu")
return listOf()
}
}
override fun onReceive(context: Context, intent: Intent) {
Timber.v("mms downloaded, persisting it to the database with worker")
// start worker with message id as param
WorkManager.getInstance(context).enqueue(
OneTimeWorkRequestBuilder<ReceiveMmsWorker>()
.setInputData(
workDataOf(
INPUT_DATA_SUBSCRIPTION_ID to intent.getIntExtra(
SUBSCRIPTION_ID,
Utils.getDefaultSubscriptionId()
),
INPUT_DATA_EXTRA_FILE_PATH to intent.getStringExtra(EXTRA_FILE_PATH),
INPUT_DATA_EXTRA_LOCATION_URL to intent.getStringExtra(EXTRA_LOCATION_URL),
INPUT_DATA_EXTRA_MMS_HTTP_STATUS to intent.getIntExtra(
SmsManager.EXTRA_MMS_HTTP_STATUS,
0
),
INPUT_DATA_EXTRA_URI to
(intent.getParcelableExtra<Parcelable>(EXTRA_URI) as Uri?)?.toString()
)
)
.setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST)
.build()
)
}
}
@@ -1,93 +0,0 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package dev.octoshrimpy.quik.receiver
import android.app.Activity
import android.content.BroadcastReceiver
import android.content.ContentUris
import android.content.ContentValues
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.provider.Telephony
import com.google.android.mms.MmsException
import com.google.android.mms.util_alt.SqliteWrapper
import com.klinker.android.send_message.Transaction
import dev.octoshrimpy.quik.interactor.SyncMessage
import dagger.android.AndroidInjection
import timber.log.Timber
import java.io.File
import javax.inject.Inject
class MmsSentReceiver : BroadcastReceiver() {
@Inject lateinit var syncMessage: SyncMessage
override fun onReceive(context: Context, intent: Intent) {
AndroidInjection.inject(this, context)
Timber.v("MMS sending result: $resultCode")
val uri = Uri.parse(intent.getStringExtra(Transaction.EXTRA_CONTENT_URI))
Timber.v(uri.toString())
when (resultCode) {
Activity.RESULT_OK -> {
Timber.v("MMS has finished sending, marking it as so in the database")
val values = ContentValues(1)
values.put(Telephony.Mms.MESSAGE_BOX, Telephony.Mms.MESSAGE_BOX_SENT)
SqliteWrapper.update(context, context.contentResolver, uri, values, null, null)
}
else -> {
Timber.v("MMS has failed to send, marking it as so in the database")
try {
val messageId = ContentUris.parseId(uri)
val values = ContentValues(1)
values.put(Telephony.Mms.MESSAGE_BOX, Telephony.Mms.MESSAGE_BOX_FAILED)
SqliteWrapper.update(context, context.contentResolver, Telephony.Mms.CONTENT_URI, values,
"${Telephony.Mms._ID} = ?", arrayOf(messageId.toString()))
// TODO this query isn't able to find any results
// Need to figure out why the message isn't appearing in the PendingMessages Uri,
// so that we can properly assign the error type
val errorTypeValues = ContentValues(1)
errorTypeValues.put(Telephony.MmsSms.PendingMessages.ERROR_TYPE,
Telephony.MmsSms.ERR_TYPE_GENERIC_PERMANENT)
SqliteWrapper.update(context, context.contentResolver, Telephony.MmsSms.PendingMessages.CONTENT_URI,
errorTypeValues, "${Telephony.MmsSms.PendingMessages.MSG_ID} = ?",
arrayOf(messageId.toString()))
} catch (e: MmsException) {
e.printStackTrace()
}
}
}
val filePath = intent.getStringExtra(Transaction.EXTRA_FILE_PATH)
Timber.v(filePath)
File(filePath).delete()
Uri.parse(intent.getStringExtra("content_uri"))?.let { uri ->
val pendingResult = goAsync()
syncMessage.execute(uri) { pendingResult.finish() }
}
}
}
@@ -20,4 +20,4 @@ package dev.octoshrimpy.quik.receiver
import com.android.mms.transaction.PushReceiver
class MmsReceiver : PushReceiver()
class MmsWapPushReceiver : PushReceiver()
@@ -24,18 +24,17 @@ import android.content.Intent
import androidx.core.app.RemoteInput
import dev.octoshrimpy.quik.compat.SubscriptionManagerCompat
import dev.octoshrimpy.quik.interactor.MarkRead
import dev.octoshrimpy.quik.interactor.SendMessage
import dev.octoshrimpy.quik.interactor.SendNewMessage
import dev.octoshrimpy.quik.repository.ConversationRepository
import dev.octoshrimpy.quik.repository.MessageRepository
import dagger.android.AndroidInjection
import javax.inject.Inject
class RemoteMessagingReceiver : BroadcastReceiver() {
@Inject lateinit var conversationRepo: ConversationRepository
@Inject lateinit var markRead: MarkRead
@Inject lateinit var messageRepo: MessageRepository
@Inject lateinit var sendMessage: SendMessage
@Inject lateinit var sendNewMessage: SendNewMessage
@Inject lateinit var subscriptionManager: SubscriptionManagerCompat
override fun onReceive(context: Context, intent: Intent) {
@@ -45,16 +44,23 @@ class RemoteMessagingReceiver : BroadcastReceiver() {
val bundle = intent.extras ?: return
val threadId = bundle.getLong("threadId")
val body = remoteInput.getCharSequence("body").toString()
markRead.execute(listOf(threadId))
val lastMessage = messageRepo.getMessages(threadId).lastOrNull()
val subId = subscriptionManager.activeSubscriptionInfoList
.firstOrNull { it.subscriptionId == lastMessage?.subId }
?.subscriptionId ?: -1
val addresses = conversationRepo.getConversation(threadId)?.recipients?.map { it.address } ?: return
val conversation = conversationRepo.getConversation(threadId)
val pendingRepository = goAsync()
sendMessage.execute(SendMessage.Params(subId, threadId, addresses, body)) { pendingRepository.finish() }
sendNewMessage.execute(
SendNewMessage.Params(
subscriptionManager.activeSubscriptionInfoList
.firstOrNull { it.subscriptionId == lastMessage?.subId }
?.subscriptionId ?: -1,
0,
conversation?.recipients?.map { it.address } ?: return,
remoteInput.getCharSequence("body").toString(),
conversation.sendAsGroup
)
) { pendingRepository.finish() }
}
}
@@ -21,26 +21,31 @@ package dev.octoshrimpy.quik.receiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.net.Uri
import dev.octoshrimpy.quik.interactor.SyncMessage
import dagger.android.AndroidInjection
import dev.octoshrimpy.quik.interactor.ActionDelayedMessage
import timber.log.Timber
import javax.inject.Inject
class MmsUpdatedReceiver : BroadcastReceiver() {
class SendDelayedMessageReceiver : BroadcastReceiver() {
companion object {
const val URI = "uri"
const val MESSAGE_ID_EXTRA = "messageId"
}
@Inject lateinit var syncMessage: SyncMessage
@Inject lateinit var actionDelayedMessage: ActionDelayedMessage
override fun onReceive(context: Context, intent: Intent) {
AndroidInjection.inject(this, context)
intent.getStringExtra(URI)?.let { uriString ->
val pendingResult = goAsync()
syncMessage.execute(Uri.parse(uriString)) { pendingResult.finish() }
}
Timber.v("received")
intent.extras?.getLong(MESSAGE_ID_EXTRA)?.takeIf { it > 0 }
?.let { messageId ->
val result = goAsync()
actionDelayedMessage.execute(
ActionDelayedMessage.Params(messageId, ActionDelayedMessage.Action.Send)
) { result.finish() }
}
}
}
}
@@ -24,6 +24,7 @@ import android.content.Intent
import dev.octoshrimpy.quik.interactor.SendScheduledMessage
import dev.octoshrimpy.quik.repository.MessageRepository
import dagger.android.AndroidInjection
import timber.log.Timber
import javax.inject.Inject
class SendScheduledMessageReceiver : BroadcastReceiver() {
@@ -34,6 +35,8 @@ class SendScheduledMessageReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
AndroidInjection.inject(this, context)
Timber.v("received")
intent.getLongExtra("id", -1L).takeIf { it >= 0 }?.let { id ->
val result = goAsync()
sendScheduledMessage.execute(id) { result.finish() }
@@ -1,43 +0,0 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package dev.octoshrimpy.quik.receiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import dev.octoshrimpy.quik.interactor.RetrySending
import dev.octoshrimpy.quik.repository.MessageRepository
import dagger.android.AndroidInjection
import javax.inject.Inject
class SendSmsReceiver : BroadcastReceiver() {
@Inject lateinit var messageRepo: MessageRepository
@Inject lateinit var retrySending: RetrySending
override fun onReceive(context: Context, intent: Intent) {
AndroidInjection.inject(this, context)
val messageId = intent.getLongExtra("id", -1L).takeIf { it >= 0 } ?: return
val result = goAsync()
retrySending.execute(messageId) { result.finish() }
}
}
@@ -43,13 +43,11 @@ class SmsProviderChangedReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
AndroidInjection.inject(this, context)
// Obtain the uri for the changed data
// If the value is null, don't continue
val uri = intent.data ?: return
// Sync the message to our realm
val pendingResult = goAsync()
syncMessage.execute(uri) { pendingResult.finish() }
syncMessage.execute(SyncMessage.Params(intent.data ?: return)) {
pendingResult.finish()
}
}
}
@@ -35,7 +35,7 @@ import io.reactivex.schedulers.Schedulers
import timber.log.Timber
import javax.inject.Inject
class SmsReceiver : BroadcastReceiver() {
class SmsReceivedReceiver : BroadcastReceiver() {
@Inject lateinit var messageRepo: MessageRepository
override fun onReceive(context: Context, intent: Intent) {
@@ -1,53 +0,0 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package dev.octoshrimpy.quik.receiver
import android.app.Activity
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import dev.octoshrimpy.quik.interactor.MarkFailed
import dev.octoshrimpy.quik.interactor.MarkSent
import dagger.android.AndroidInjection
import javax.inject.Inject
class SmsSentReceiver : BroadcastReceiver() {
@Inject lateinit var markSent: MarkSent
@Inject lateinit var markFailed: MarkFailed
override fun onReceive(context: Context, intent: Intent) {
AndroidInjection.inject(this, context)
val id = intent.getLongExtra("id", 0L)
when (resultCode) {
Activity.RESULT_OK -> {
val pendingResult = goAsync()
markSent.execute(id) { pendingResult.finish() }
}
else -> {
val pendingResult = goAsync()
markFailed.execute(MarkFailed.Params(id, resultCode)) { pendingResult.finish() }
}
}
}
}
@@ -23,6 +23,7 @@ import android.content.Context
import android.content.Intent
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
import dagger.android.AndroidInjection
import dev.octoshrimpy.quik.util.nonDebugPackageName
class StartActivityFromWidgetReceiver : BroadcastReceiver() {
// why does this shim class exist rather than the widget launching activities more directly?
@@ -51,7 +52,7 @@ class StartActivityFromWidgetReceiver : BroadcastReceiver() {
}
context.startActivity(
Intent(context, Class.forName(context.packageName + activityToStartName))
Intent(context, Class.forName(nonDebugPackageName(context.packageName) + activityToStartName))
.setFlags(FLAG_ACTIVITY_NEW_TASK)
.putExtra("threadId", intent.getLongExtra("threadId", 0L))
)