forked from upstream-mirrors/quik
#207 - Dual SIM support
commit c3dc3ada558c466be5115cd7ddbf9651a229c217 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Sat Jun 2 02:54:06 2018 -0400 Dual SIM support for QK Reply commit 48688dd4720bd1b3abc049d365e208e1dfe5ccb8 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Sat Jun 2 00:37:08 2018 -0400 #1172 - Load all recipients and subId from threadId when sending message from notification reply bar commit 0b7195fb134c0a9f2a6b551176c6c25a26bf5838 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Fri Jun 1 23:43:30 2018 -0400 Fix missing subId for RetrySending params commit 0d3ec43c0e60bab4acc293947ea9f6d2228c1b19 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Fri Jun 1 23:27:56 2018 -0400 Switch to appropriate SIM when new message is received commit 1ae883af890104cf1da9e970571371c95666db66 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Fri Jun 1 23:07:16 2018 -0400 Fix message grouping for incoming messages commit 2bf7b2d99ddbfdcafff873f305180d6d38c37d65 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Fri Jun 1 22:56:31 2018 -0400 Correctly assign subId for incoming SMS commit 1f6028f8921320358a3053a2dbc2c6e05410964b Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Fri Jun 1 20:52:01 2018 -0400 Abstract SubscriptionManager usage behind SubscriptionUtils commit 8b18f16271f19a42800c737cfbd867365c4aa781 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Fri Jun 1 20:05:52 2018 -0400 Store subId when receiving SMS commit f0e4ffdf15eb54d8ef78adfe244943ef4cb95d4e Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Fri Jun 1 19:52:40 2018 -0400 Use appropriate SIM card based on last message commit b7893d69891e4fb61755b0733a5fab561e86bbf3 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Thu May 31 00:20:42 2018 -0400 Fix crash when device doesn't support multi-sim commit bb038068129227e931167976628e1a535efb09a0 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Wed May 30 23:54:14 2018 -0400 Show sim indicator when subId changes in conversation commit 952f15f7ebfb85a03feef51373ef30568b76d5eb Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Wed May 30 22:13:57 2018 -0400 Send message from selected SIM commit 4cfab7ca9ec9bd9c7ce82b3eb5f228cf511a7c7b Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Wed May 30 21:46:01 2018 -0400 Fix filename for ActiveSubscriptionObservable commit 720cb79cb4fbfb98b10e169f2fea84be02fd2f91 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Wed May 30 20:35:30 2018 -0400 Allow cycling through inserted sims commit fa95980e9bc8e8c01dab7b4b8e4ed3a1c9a0f0b0 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Wed May 30 18:26:44 2018 -0400 Show sim card slot in compose bar
This commit is contained in:
@@ -85,7 +85,7 @@ class CursorToMessageImpl @Inject constructor(
|
||||
dateSent = cursor.getLong(columnsMap.dateSent)
|
||||
read = cursor.getInt(columnsMap.read) != 0
|
||||
locked = cursor.getInt(columnsMap.locked) != 0
|
||||
subId = cursor.getInt(columnsMap.subId)
|
||||
subId = if (columnsMap.subId != -1) cursor.getInt(columnsMap.subId) else -1
|
||||
|
||||
when (type) {
|
||||
"sms" -> {
|
||||
|
||||
@@ -25,24 +25,32 @@ import android.support.v4.app.RemoteInput
|
||||
import dagger.android.AndroidInjection
|
||||
import interactor.MarkRead
|
||||
import interactor.SendMessage
|
||||
import repository.MessageRepository
|
||||
import util.SubscriptionUtils
|
||||
import javax.inject.Inject
|
||||
|
||||
class RemoteMessagingReceiver : BroadcastReceiver() {
|
||||
|
||||
@Inject lateinit var sendMessage: SendMessage
|
||||
@Inject lateinit var markRead: MarkRead
|
||||
@Inject lateinit var messageRepo: MessageRepository
|
||||
@Inject lateinit var sendMessage: SendMessage
|
||||
@Inject lateinit var subUtils: SubscriptionUtils
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
AndroidInjection.inject(this, context)
|
||||
|
||||
val remoteInput = RemoteInput.getResultsFromIntent(intent)
|
||||
val bundle = intent.extras
|
||||
if (remoteInput != null && bundle != null) {
|
||||
val address = bundle.getString("address")
|
||||
val threadId = bundle.getLong("threadId")
|
||||
val body = remoteInput.getCharSequence("body").toString()
|
||||
markRead.execute(threadId)
|
||||
sendMessage.execute(SendMessage.Params(threadId, listOf(address), body))
|
||||
}
|
||||
val remoteInput = RemoteInput.getResultsFromIntent(intent) ?: return
|
||||
val bundle = intent.extras ?: return
|
||||
|
||||
val threadId = bundle.getLong("threadId")
|
||||
val body = remoteInput.getCharSequence("body").toString()
|
||||
markRead.execute(threadId)
|
||||
|
||||
val lastMessage = messageRepo.getMessages(threadId).lastOrNull()
|
||||
val subId = subUtils.subscriptions.firstOrNull { it.subscriptionId == lastMessage?.subId }?.subscriptionId ?: -1
|
||||
val addresses = messageRepo.getConversation(threadId)?.recipients?.map { it.address } ?: return
|
||||
|
||||
val pendingRepository = goAsync()
|
||||
sendMessage.execute(SendMessage.Params(subId, threadId, addresses, body)) { pendingRepository.finish() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +34,10 @@ class SmsReceiver : BroadcastReceiver() {
|
||||
AndroidInjection.inject(this, context)
|
||||
|
||||
Sms.Intents.getMessagesFromIntent(intent)?.let { messages ->
|
||||
val subId = intent.extras?.getInt("subscription", -1) ?: -1
|
||||
|
||||
val pendingResult = goAsync()
|
||||
receiveMessage.execute(messages, { pendingResult.finish() })
|
||||
receiveMessage.execute(ReceiveSms.Params(subId, messages), { pendingResult.finish() })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -393,7 +393,7 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override fun sendSmsAndPersist(threadId: Long, address: String, body: String) {
|
||||
override fun sendSmsAndPersist(subId: Int, threadId: Long, address: String, body: String) {
|
||||
if (prefs.sendDelay.get() != Preferences.SEND_DELAY_NONE) {
|
||||
val delay = when (prefs.sendDelay.get()) {
|
||||
Preferences.SEND_DELAY_SHORT -> 3000
|
||||
@@ -403,7 +403,7 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
}
|
||||
|
||||
val sendTime = System.currentTimeMillis() + delay
|
||||
val message = insertSentSms(threadId, address, body, sendTime)
|
||||
val message = insertSentSms(subId, threadId, address, body, sendTime)
|
||||
|
||||
val intent = getIntentForDelayedSms(message.id)
|
||||
|
||||
@@ -414,13 +414,13 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
alarmManager.setExact(AlarmManager.RTC_WAKEUP, sendTime, intent)
|
||||
}
|
||||
} else {
|
||||
val message = insertSentSms(threadId, address, body, System.currentTimeMillis())
|
||||
val message = insertSentSms(subId, threadId, address, body, System.currentTimeMillis())
|
||||
sendSms(message)
|
||||
}
|
||||
}
|
||||
|
||||
override fun sendSms(message: Message) {
|
||||
val smsManager = SmsManager.getDefault()
|
||||
val smsManager = SmsManager.getSmsManagerForSubscriptionId(message.subId)
|
||||
|
||||
val parts = smsManager.divideMessage(if (prefs.unicode.get()) StripAccents.stripAccents(message.body) else message.body)
|
||||
?: arrayListOf()
|
||||
@@ -443,8 +443,8 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
smsManager.sendMultipartTextMessage(message.address, null, parts, ArrayList(sentIntents), ArrayList(deliveredIntents))
|
||||
}
|
||||
|
||||
override fun sendMms(threadId: Long, addresses: List<String>, body: String, attachments: List<Attachment>) {
|
||||
val settings = Settings()
|
||||
override fun sendMms(subId: Int, threadId: Long, addresses: List<String>, body: String, attachments: List<Attachment>) {
|
||||
val settings = Settings().apply { subscriptionId = subId }
|
||||
val message = com.klinker.android.send_message.Message(body, addresses.toTypedArray())
|
||||
|
||||
// Add the GIFs as attachments. The app currently can't compress them, which may result
|
||||
@@ -509,7 +509,7 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
return PendingIntent.getBroadcast(context, id.toInt(), intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
}
|
||||
|
||||
override fun insertSentSms(threadId: Long, address: String, body: String, date: Long): Message {
|
||||
override fun insertSentSms(subId: Int, threadId: Long, address: String, body: String, date: Long): Message {
|
||||
|
||||
// Insert the message to Realm
|
||||
val message = Message().apply {
|
||||
@@ -517,6 +517,7 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
this.address = address
|
||||
this.body = body
|
||||
this.date = date
|
||||
this.subId = subId
|
||||
|
||||
id = messageIds.newId()
|
||||
boxId = Telephony.Sms.MESSAGE_TYPE_OUTBOX
|
||||
@@ -537,6 +538,7 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
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 uri = context.contentResolver.insert(Telephony.Sms.CONTENT_URI, values)
|
||||
|
||||
@@ -548,7 +550,7 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
return message
|
||||
}
|
||||
|
||||
override fun insertReceivedSms(address: String, body: String, sentTime: Long): Message {
|
||||
override fun insertReceivedSms(subId: Int, address: String, body: String, sentTime: Long): Message {
|
||||
|
||||
// Insert the message to Realm
|
||||
val message = Message().apply {
|
||||
@@ -556,6 +558,7 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
this.body = body
|
||||
this.dateSent = sentTime
|
||||
this.date = System.currentTimeMillis()
|
||||
this.subId = subId
|
||||
|
||||
id = messageIds.newId()
|
||||
threadId = getOrCreateConversation(address).blockingGet().id
|
||||
@@ -571,6 +574,7 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
put(Telephony.Sms.ADDRESS, address)
|
||||
put(Telephony.Sms.BODY, body)
|
||||
put(Telephony.Sms.DATE_SENT, sentTime)
|
||||
put(Telephony.Sms.SUBSCRIPTION_ID, subId)
|
||||
}
|
||||
val uri = context.contentResolver.insert(Telephony.Sms.Inbox.CONTENT_URI, values)
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ class HeadlessSmsSendService : IntentService("HeadlessSmsSendService") {
|
||||
val intentUri = intent.data
|
||||
val recipients = getRecipients(intentUri).split(";")
|
||||
val threadId = messageRepo.getOrCreateConversation(recipients).blockingGet()?.id ?: 0L
|
||||
sendMessage.execute(SendMessage.Params(threadId, recipients, body))
|
||||
sendMessage.execute(SendMessage.Params(-1, threadId, recipients, body))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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 util
|
||||
|
||||
import android.telephony.SubscriptionInfo
|
||||
import android.telephony.SubscriptionManager
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.Observer
|
||||
import io.reactivex.disposables.Disposable
|
||||
|
||||
class ActiveSubscriptionObservable(private val subscriptionManager: SubscriptionManager) : Observable<List<SubscriptionInfo>>() {
|
||||
|
||||
override fun subscribeActual(observer: Observer<in List<SubscriptionInfo>>) {
|
||||
observer.onNext(subscriptionManager.activeSubscriptionInfoList ?: listOf())
|
||||
|
||||
val listener = Listener(subscriptionManager, observer)
|
||||
observer.onSubscribe(listener)
|
||||
subscriptionManager.addOnSubscriptionsChangedListener(listener)
|
||||
}
|
||||
|
||||
internal class Listener(
|
||||
private val subscriptionManager: SubscriptionManager,
|
||||
private val observer: Observer<in List<SubscriptionInfo>>
|
||||
) : Disposable, SubscriptionManager.OnSubscriptionsChangedListener() {
|
||||
|
||||
private var disposed: Boolean = false
|
||||
|
||||
override fun onSubscriptionsChanged() {
|
||||
if (!isDisposed) {
|
||||
observer.onNext(subscriptionManager.activeSubscriptionInfoList ?: listOf())
|
||||
}
|
||||
}
|
||||
|
||||
override fun isDisposed(): Boolean = disposed
|
||||
|
||||
override fun dispose() {
|
||||
disposed = true
|
||||
subscriptionManager.removeOnSubscriptionsChangedListener(this)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package util
|
||||
|
||||
import android.content.Context
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import android.telephony.SubscriptionInfo
|
||||
import android.telephony.SubscriptionManager
|
||||
import io.reactivex.Observable
|
||||
import javax.inject.Inject
|
||||
|
||||
class SubscriptionUtilsImpl @Inject constructor(context: Context) : SubscriptionUtils {
|
||||
|
||||
private val subscriptionManager = SubscriptionManager.from(context)
|
||||
|
||||
override val subscriptions: List<SubscriptionInfo>
|
||||
get() = subscriptionManager.activeSubscriptionInfoList ?: listOf()
|
||||
|
||||
override val subscriptionsObservable: Observable<List<SubscriptionInfo>> = ActiveSubscriptionObservable(subscriptionManager)
|
||||
|
||||
override fun getSubIdForAddress(address: String): Int {
|
||||
return subscriptions.firstOrNull { PhoneNumberUtils.compare(it.number, address) }?.subscriptionId ?: -1
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user