Modern Apps git

← Modern-Apps.git

communicate: conversation shortcuts, notifications and bubbles (#633)

Commit
e1c296bf285a3ee0c49d44a28ddd23a30b529be5
Author
vayun-mathur <[email protected]>
When
2026-09-02 19:46 UTC (3 months ago)
Parents
f487da6

Diff

communicate/src/main/AndroidManifest.xml
diff --git a/communicate/src/main/AndroidManifest.xml b/communicate/src/main/AndroidManifest.xmlindex 5e1b36835f..2cafa43025 100644--- a/communicate/src/main/AndroidManifest.xml+++ b/communicate/src/main/AndroidManifest.xml@@ -125,6 +125,15 @@             </intent-filter>         </activity> +        <!-- Expanded conversation bubble host: must be embeddable and document-launched. -->+        <activity+            android:name=".notifications.BubbleActivity"+            android:allowEmbedded="true"+            android:documentLaunchMode="always"+            android:exported="false"+            android:resizeableActivity="true"+            android:theme="@style/Theme.General" />+         <receiver             android:name=".telephony.SmsDeliverReceiver"             android:exported="true"
communicate/src/main/java/com/vayunmathur/communicate/DeepLinks.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/DeepLinks.kt b/communicate/src/main/java/com/vayunmathur/communicate/DeepLinks.ktindex 76f1f01761..bad8c617c8 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/DeepLinks.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/DeepLinks.kt@@ -3,6 +3,7 @@ package com.vayunmathur.communicate import android.content.Intent import android.net.Uri import com.vayunmathur.communicate.data.CommunicateLine+import com.vayunmathur.communicate.notifications.ConversationSpace  /**  * What an incoming intent asked us to open.@@ -12,7 +13,16 @@ import com.vayunmathur.communicate.data.CommunicateLine  */ sealed interface DeepLink {     /** Open (or start) a conversation with [address] on [line]. */-    data class Conversation(val address: String, val line: CommunicateLine, val body: String? = null) : DeepLink+    data class Conversation(+        val address: String,+        val line: CommunicateLine,+        val body: String? = null,+        val remoteId: String? = null,+        val threadId: Long = -1L,+        val isGroup: Boolean = false,+        val groupTitle: String? = null,+        val subscriptionId: Int? = null,+    ) : DeepLink      /** A group invite we can't join yet, but shouldn't silently swallow either. */     data class UnsupportedGroupInvite(val line: CommunicateLine) : DeepLink@@ -28,6 +38,8 @@ sealed interface DeepLink { object DeepLinks {     fun parse(intent: Intent?): DeepLink? {         val intent = intent ?: return null+        // A tap on a conversation notification / shortcut carries the thread in extras, not a URI.+        fromConversationExtras(intent)?.let { return it }         val data = intent.data ?: return null         return when (intent.action) {             Intent.ACTION_VIEW, Intent.ACTION_SENDTO, Intent.ACTION_DIAL, Intent.ACTION_CALL ->@@ -36,6 +48,20 @@ object DeepLinks {         }     } +    private fun fromConversationExtras(intent: Intent): DeepLink.Conversation? {+        val lineName = intent.getStringExtra(ConversationSpace.EXTRA_LINE) ?: return null+        val line = runCatching { CommunicateLine.valueOf(lineName) }.getOrNull() ?: return null+        return DeepLink.Conversation(+            address = intent.getStringExtra(ConversationSpace.EXTRA_ADDRESS).orEmpty(),+            line = line,+            remoteId = intent.getStringExtra(ConversationSpace.EXTRA_REMOTE_ID),+            threadId = intent.getLongExtra(ConversationSpace.EXTRA_THREAD_ID, -1L),+            isGroup = intent.getBooleanExtra(ConversationSpace.EXTRA_IS_GROUP, false),+            groupTitle = intent.getStringExtra(ConversationSpace.EXTRA_TITLE),+            subscriptionId = intent.getIntExtra(ConversationSpace.EXTRA_SUB_ID, -1).takeIf { it >= 0 },+        )+    }+     internal fun fromUri(uri: Uri, body: String? = null): DeepLink? = resolve(         scheme = uri.scheme,         host = uri.host,
communicate/src/main/java/com/vayunmathur/communicate/MainActivity.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/MainActivity.kt b/communicate/src/main/java/com/vayunmathur/communicate/MainActivity.ktindex 5cd085876e..0974968b65 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/MainActivity.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/MainActivity.kt@@ -198,9 +198,13 @@ private fun CommunicateApp(initialDeepLink: DeepLink? = null) {         when (val link = initialDeepLink) {             is DeepLink.Conversation -> backStack.add(                 Route.Conversation(-                    threadId = -1L,+                    threadId = link.threadId,                     address = link.address,                     line = link.line,+                    remoteId = link.remoteId,+                    subscriptionId = link.subscriptionId,+                    isGroup = link.isGroup,+                    groupTitle = link.groupTitle,                 ),             )             is DeepLink.UnsupportedGroupInvite ->
communicate/src/main/java/com/vayunmathur/communicate/notifications/BubbleActivity.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/notifications/BubbleActivity.kt b/communicate/src/main/java/com/vayunmathur/communicate/notifications/BubbleActivity.ktnew file mode 100644index 0000000000..dfc04ab54d--- /dev/null+++ b/communicate/src/main/java/com/vayunmathur/communicate/notifications/BubbleActivity.kt@@ -0,0 +1,46 @@+package com.vayunmathur.communicate.notifications++import android.os.Bundle+import androidx.activity.ComponentActivity+import androidx.activity.compose.setContent+import androidx.activity.enableEdgeToEdge+import com.vayunmathur.communicate.data.CommunicateLine+import com.vayunmathur.communicate.ui.ConversationScreen+import com.vayunmathur.library.ui.DynamicTheme++/**+ * The expanded contents of a conversation bubble. Kept separate from [com.vayunmathur.communicate.MainActivity]+ * because a bubble host must be embeddable and document-launched, and reuses the normal+ * [ConversationScreen] so a bubbled thread looks and behaves like the in-app one.+ */+class BubbleActivity : ComponentActivity() {+    override fun onCreate(savedInstanceState: Bundle?) {+        super.onCreate(savedInstanceState)+        enableEdgeToEdge()++        val line = intent.getStringExtra(ConversationSpace.EXTRA_LINE)+            ?.let { runCatching { CommunicateLine.valueOf(it) }.getOrNull() }+            ?: CommunicateLine.Sim+        val address = intent.getStringExtra(ConversationSpace.EXTRA_ADDRESS).orEmpty()+        val remoteId = intent.getStringExtra(ConversationSpace.EXTRA_REMOTE_ID)+        val threadId = intent.getLongExtra(ConversationSpace.EXTRA_THREAD_ID, -1L)+        val isGroup = intent.getBooleanExtra(ConversationSpace.EXTRA_IS_GROUP, false)+        val title = intent.getStringExtra(ConversationSpace.EXTRA_TITLE)+        val subscriptionId = intent.getIntExtra(ConversationSpace.EXTRA_SUB_ID, -1).takeIf { it >= 0 }++        setContent {+            DynamicTheme {+                ConversationScreen(+                    threadId = threadId,+                    address = address,+                    line = line,+                    remoteId = remoteId,+                    subscriptionId = subscriptionId,+                    isGroup = isGroup,+                    groupTitle = title,+                    onBack = { finish() },+                )+            }+        }+    }+}
communicate/src/main/java/com/vayunmathur/communicate/notifications/ConversationSpace.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/notifications/ConversationSpace.kt b/communicate/src/main/java/com/vayunmathur/communicate/notifications/ConversationSpace.ktnew file mode 100644index 0000000000..83345644dd--- /dev/null+++ b/communicate/src/main/java/com/vayunmathur/communicate/notifications/ConversationSpace.kt@@ -0,0 +1,203 @@+package com.vayunmathur.communicate.notifications++import android.app.NotificationManager+import android.app.PendingIntent+import android.content.Context+import android.content.Intent+import androidx.annotation.DrawableRes+import androidx.core.app.NotificationCompat+import androidx.core.app.Person+import androidx.core.content.LocusIdCompat+import androidx.core.content.pm.ShortcutInfoCompat+import androidx.core.content.pm.ShortcutManagerCompat+import androidx.core.graphics.drawable.IconCompat+import com.vayunmathur.communicate.MainActivity+import com.vayunmathur.communicate.R+import com.vayunmathur.communicate.data.CommunicateLine+import com.vayunmathur.library.util.ensureNotificationChannel++/**+ * Identifies one conversation across the three surfaces that make up Android's Conversation Space:+ * a long-lived dynamic shortcut, a `MessagingStyle` notification that references it, and a bubble.+ */+data class ConversationTarget(+    val line: CommunicateLine,+    val address: String,+    val remoteId: String? = null,+    val threadId: Long = -1L,+    val isGroup: Boolean = false,+    /** Group/conversation title, shown for group threads. */+    val title: String? = null,+    /** Display name of the other party (or the sender, for a group). */+    val personName: String,+    val subscriptionId: Int? = null,+)++/**+ * Promotes Communicate's message notifications into the system Conversation Space.+ *+ * A notification only reaches the conversations section (and becomes eligible for prioritisation and+ * bubbling) when it is a [NotificationCompat.MessagingStyle] notification whose `shortcutId` points at+ * a *long-lived* dynamic shortcut in the [ShortcutManagerCompat.getShortcuts] set, tagged with the+ * system conversations category. This centralises that wiring so every line (SIM, Google Voice,+ * WhatsApp, Signal) behaves identically.+ */+object ConversationSpace {+    // Extras describing a conversation, shared by the tap intent, the shortcut intent and the bubble.+    const val EXTRA_LINE = "convo_line"+    const val EXTRA_ADDRESS = "convo_address"+    const val EXTRA_REMOTE_ID = "convo_remote_id"+    const val EXTRA_THREAD_ID = "convo_thread_id"+    const val EXTRA_IS_GROUP = "convo_is_group"+    const val EXTRA_TITLE = "convo_title"+    const val EXTRA_SUB_ID = "convo_sub_id"++    /** Incoming-message channel for the SIM line (the vendor lines own their own channels). */+    const val SIM_CHANNEL_ID = "sms_messages_incoming"++    private const val CONVERSATION_CATEGORY = "com.google.android.category.CONVERSATIONS"++    // One notification per conversation: newer messages replace the previous one under the same tag,+    // which is what makes a thread accumulate in the shade rather than stacking N separate entries.+    private const val MESSAGE_NOTIFICATION_ID = 1++    /** Stable per-conversation id, unique across lines. */+    fun shortcutId(target: ConversationTarget): String {+        val key = target.remoteId+            ?: target.threadId.takeIf { it >= 0 }?.toString()+            ?: target.address+        return "${target.line.name}:$key"+    }++    /** Copy the conversation descriptor onto [intent] so the target screen can rebuild it. */+    fun putExtras(intent: Intent, target: ConversationTarget): Intent = intent.apply {+        putExtra(EXTRA_LINE, target.line.name)+        putExtra(EXTRA_ADDRESS, target.address)+        putExtra(EXTRA_REMOTE_ID, target.remoteId)+        putExtra(EXTRA_THREAD_ID, target.threadId)+        putExtra(EXTRA_IS_GROUP, target.isGroup)+        putExtra(EXTRA_TITLE, target.title)+        putExtra(EXTRA_SUB_ID, target.subscriptionId ?: -1)+    }++    /** Create (or refresh) an incoming-message channel that permits bubbles. */+    fun ensureIncomingChannel(context: Context, channelId: String, name: String, description: String?) {+        context.ensureNotificationChannel(+            id = channelId,+            name = name,+            importance = NotificationManager.IMPORTANCE_HIGH,+            description = description,+        ) {+            setAllowBubbles(true)+        }+    }++    private fun person(context: Context, target: ConversationTarget): Person =+        Person.Builder()+            .setName(target.personName)+            .setKey(shortcutId(target))+            .setImportant(true)+            .setIcon(IconCompat.createWithResource(context, R.mipmap.ic_launcher))+            .build()++    /** Publish/refresh the long-lived shortcut backing [target]; returns its id. */+    fun pushShortcut(context: Context, target: ConversationTarget): String {+        val id = shortcutId(target)+        val label = (target.title ?: target.personName).ifBlank { context.getString(R.string.app_name) }+        val intent = putExtras(+            Intent(context, MainActivity::class.java)+                .setAction(Intent.ACTION_VIEW)+                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP),+            target,+        )+        val shortcut = ShortcutInfoCompat.Builder(context, id)+            .setLongLived(true)+            .setShortLabel(label)+            .setIntent(intent)+            .setPerson(person(context, target))+            .setCategories(setOf(CONVERSATION_CATEGORY))+            .setIcon(IconCompat.createWithResource(context, R.mipmap.ic_launcher))+            .build()+        runCatching { ShortcutManagerCompat.pushDynamicShortcut(context, shortcut) }+        return id+    }++    /** Remove the shortcut for [target] (e.g. when a conversation is deleted). */+    fun removeShortcut(context: Context, target: ConversationTarget) {+        runCatching { ShortcutManagerCompat.removeLongLivedShortcuts(context, listOf(shortcutId(target))) }+    }++    /**+     * Post a conversation-style notification for an inbound message, pushing the backing shortcut and+     * attaching bubble metadata first so the system can surface it in the conversations section.+     */+    fun notifyIncoming(+        context: Context,+        target: ConversationTarget,+        channelId: String,+        body: String,+        timestamp: Long,+        @DrawableRes smallIcon: Int,+    ) {+        val shortcutId = pushShortcut(context, target)+        val sender = person(context, target)+        val self = Person.Builder().setName(context.getString(R.string.you)).build()++        val messagingStyle = NotificationCompat.MessagingStyle(self)+            .setGroupConversation(target.isGroup)+            .setConversationTitle(target.title.takeIf { target.isGroup })+            .addMessage(body, timestamp, sender)++        val contentIntent = PendingIntent.getActivity(+            context,+            shortcutId.hashCode(),+            putExtras(+                Intent(context, MainActivity::class.java)+                    .setAction(Intent.ACTION_VIEW)+                    .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),+                target,+            ),+            PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,+        )++        val bubbleIntent = PendingIntent.getActivity(+            context,+            "bubble:$shortcutId".hashCode(),+            putExtras(+                Intent(context, BubbleActivity::class.java)+                    .setAction(Intent.ACTION_VIEW)+                    .addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT),+                target,+            ),+            PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,+        )+        val bubbleMetadata = NotificationCompat.BubbleMetadata.Builder(+            bubbleIntent,+            IconCompat.createWithResource(context, R.mipmap.ic_launcher),+        )+            .setDesiredHeight(BUBBLE_HEIGHT_DP)+            .setAutoExpandBubble(false)+            .setSuppressNotification(false)+            .build()++        val notification = NotificationCompat.Builder(context, channelId)+            .setSmallIcon(smallIcon)+            .setContentTitle(target.title ?: target.personName)+            .setContentText(body)+            .setStyle(messagingStyle)+            .setShortcutId(shortcutId)+            .setLocusId(LocusIdCompat(shortcutId))+            .addPerson(sender)+            .setContentIntent(contentIntent)+            .setBubbleMetadata(bubbleMetadata)+            .setAutoCancel(true)+            .setCategory(NotificationCompat.CATEGORY_MESSAGE)+            .setPriority(NotificationCompat.PRIORITY_HIGH)+            .build()++        val nm = context.getSystemService(NotificationManager::class.java) ?: return+        nm.notify(shortcutId, MESSAGE_NOTIFICATION_ID, notification)+    }++    private const val BUBBLE_HEIGHT_DP = 600+}
communicate/src/main/java/com/vayunmathur/communicate/telephony/GoogleVoiceSyncService.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/telephony/GoogleVoiceSyncService.kt b/communicate/src/main/java/com/vayunmathur/communicate/telephony/GoogleVoiceSyncService.ktindex d79520bfbb..55d5b49cdc 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/telephony/GoogleVoiceSyncService.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/telephony/GoogleVoiceSyncService.kt@@ -11,16 +11,18 @@ import android.os.Build import android.os.IBinder import android.util.Log import androidx.core.app.NotificationCompat-import androidx.core.app.Person import androidx.core.content.ContextCompat import com.vayunmathur.communicate.MainActivity import com.vayunmathur.communicate.R+import com.vayunmathur.communicate.data.CommunicateLine import com.vayunmathur.communicate.data.googlevoice.GoogleVoiceAuthException import com.vayunmathur.communicate.data.googlevoice.GoogleVoiceClient import com.vayunmathur.communicate.data.googlevoice.GoogleVoiceSession import com.vayunmathur.communicate.data.googlevoice.GvFolder import com.vayunmathur.communicate.data.googlevoice.GvMessage import com.vayunmathur.communicate.data.googlevoice.call.GoogleVoiceCallManager+import com.vayunmathur.communicate.notifications.ConversationSpace+import com.vayunmathur.communicate.notifications.ConversationTarget import com.vayunmathur.library.util.ensureNotificationChannel import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers@@ -147,7 +149,9 @@ class GoogleVoiceSyncService : Service() {             name = getString(R.string.gv_incoming_channel_name),             importance = NotificationManager.IMPORTANCE_HIGH,             description = getString(R.string.gv_incoming_channel_desc),-        )+        ) {+            setAllowBubbles(true)+        }     }      private fun buildSyncNotification(): Notification {@@ -178,34 +182,21 @@ class GoogleVoiceSyncService : Service() {     }      private fun showIncomingNotification(message: GvMessage) {-        val notificationId = message.id.hashCode()-        val tap = PendingIntent.getActivity(-            this,-            notificationId,-            Intent(this, MainActivity::class.java).apply {-                addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)-                putExtra(EXTRA_OPEN_GOOGLE_VOICE_THREAD, message.threadId)-            },-            PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,+        val name = message.phoneNumber.ifBlank { getString(R.string.account_google_voice) }+        val target = ConversationTarget(+            line = CommunicateLine.GoogleVoice,+            address = message.phoneNumber,+            remoteId = message.threadId,+            personName = name,+        )+        ConversationSpace.notifyIncoming(+            context = this,+            target = target,+            channelId = INCOMING_CHANNEL_ID,+            body = message.notificationText(),+            timestamp = message.timestampMillis,+            smallIcon = R.mipmap.ic_launcher,         )-        val sender = Person.Builder()-            .setName(message.phoneNumber.ifBlank { getString(R.string.account_google_voice) })-            .build()-        val self = Person.Builder().setName(getString(R.string.you)).build()-        val body = message.notificationText()-        val notification = NotificationCompat.Builder(this, INCOMING_CHANNEL_ID)-            .setSmallIcon(R.mipmap.ic_launcher)-            .setContentTitle(sender.name)-            .setContentText(body)-            .setStyle(NotificationCompat.MessagingStyle(self).addMessage(body, message.timestampMillis, sender))-            .setContentIntent(tap)-            .setAutoCancel(true)-            .setCategory(NotificationCompat.CATEGORY_MESSAGE)-            .setDefaults(NotificationCompat.DEFAULT_ALL)-            .setPriority(NotificationCompat.PRIORITY_HIGH)-            .build()-        val nm = getSystemService(NOTIFICATION_SERVICE) as NotificationManager-        nm.notify(message.threadId, notificationId, notification)     }      private fun GvMessage.shouldNotify(): Boolean = !outgoing
communicate/src/main/java/com/vayunmathur/communicate/telephony/MmsDeliverReceiver.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/telephony/MmsDeliverReceiver.kt b/communicate/src/main/java/com/vayunmathur/communicate/telephony/MmsDeliverReceiver.ktindex 8515ee25f5..d235a3c4d6 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/telephony/MmsDeliverReceiver.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/telephony/MmsDeliverReceiver.kt@@ -9,6 +9,10 @@ import android.net.Uri import android.provider.Telephony import android.telephony.SmsManager import android.util.Log+import com.vayunmathur.communicate.R+import com.vayunmathur.communicate.data.CommunicateLine+import com.vayunmathur.communicate.notifications.ConversationSpace+import com.vayunmathur.communicate.notifications.ConversationTarget import java.io.File  /**@@ -117,6 +121,28 @@ class MmsDeliverReceiver : BroadcastReceiver() {                 put("charset", 106)             }             context.contentResolver.insert(Uri.parse("content://mms/$mmsId/addr"), av)++            val textBody = msg.parts.firstOrNull { it.contentType == "text/plain" }?.text+            val body = textBody?.takeIf { it.isNotBlank() } ?: context.getString(R.string.media_message)+            ConversationSpace.ensureIncomingChannel(+                context,+                ConversationSpace.SIM_CHANNEL_ID,+                context.getString(R.string.sms_incoming_channel_name),+                context.getString(R.string.sms_incoming_channel_desc),+            )+            ConversationSpace.notifyIncoming(+                context = context,+                target = ConversationTarget(+                    line = CommunicateLine.Sim,+                    address = from,+                    threadId = threadId ?: -1L,+                    personName = from,+                ),+                channelId = ConversationSpace.SIM_CHANNEL_ID,+                body = body,+                timestamp = System.currentTimeMillis(),+                smallIcon = R.mipmap.ic_launcher,+            )         }     } 
communicate/src/main/java/com/vayunmathur/communicate/telephony/SignalSyncService.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/telephony/SignalSyncService.kt b/communicate/src/main/java/com/vayunmathur/communicate/telephony/SignalSyncService.ktindex 8575bd1d0a..2c333ed223 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/telephony/SignalSyncService.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/telephony/SignalSyncService.kt@@ -11,14 +11,16 @@ import android.os.Build import android.os.IBinder import android.util.Log import androidx.core.app.NotificationCompat-import androidx.core.app.Person import androidx.core.content.ContextCompat import com.vayunmathur.communicate.MainActivity import com.vayunmathur.communicate.R+import com.vayunmathur.communicate.data.CommunicateLine import com.vayunmathur.communicate.data.signal.SignalClient import com.vayunmathur.communicate.data.signal.SignalEvent import com.vayunmathur.communicate.data.signal.SignalFeature import com.vayunmathur.communicate.data.signal.SignalLineSession+import com.vayunmathur.communicate.notifications.ConversationSpace+import com.vayunmathur.communicate.notifications.ConversationTarget import com.vayunmathur.library.util.ensureNotificationChannel import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers@@ -116,7 +118,9 @@ class SignalSyncService : Service() {             name = "Signal messages",             importance = NotificationManager.IMPORTANCE_HIGH,             description = "Incoming Signal messages",-        )+        ) {+            setAllowBubbles(true)+        }     }      private fun buildSyncNotification(): Notification {@@ -147,33 +151,23 @@ class SignalSyncService : Service() {     }      private fun showIncomingNotification(event: SignalEvent.IncomingMessage) {-        val notificationId = event.messageId.hashCode()-        val tap = PendingIntent.getActivity(-            this,-            notificationId,-            Intent(this, MainActivity::class.java).apply {-                addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)-                putExtra(EXTRA_OPEN_SIGNAL_THREAD, event.conversationId)-            },-            PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,+        val isGroup = event.conversationId.startsWith("group:")+        val target = ConversationTarget(+            line = CommunicateLine.Signal,+            address = event.peerPhone ?: event.conversationId,+            remoteId = event.conversationId,+            isGroup = isGroup,+            title = if (isGroup) event.peerName else null,+            personName = event.senderName ?: event.peerName ?: event.peerPhone ?: "Signal",+        )+        ConversationSpace.notifyIncoming(+            context = this,+            target = target,+            channelId = INCOMING_CHANNEL_ID,+            body = event.body.ifBlank { getString(R.string.new_message) },+            timestamp = event.timestamp,+            smallIcon = R.mipmap.ic_launcher,         )-        val sender = Person.Builder()-            .setName(event.senderName ?: event.peerName ?: event.peerPhone ?: "Signal")-            .build()-        val self = Person.Builder().setName(getString(R.string.you)).build()-        val body = event.body.ifBlank { "New message" }-        val notification = NotificationCompat.Builder(this, INCOMING_CHANNEL_ID)-            .setSmallIcon(R.mipmap.ic_launcher)-            .setContentTitle(sender.name)-            .setContentText(body)-            .setStyle(NotificationCompat.MessagingStyle(self).addMessage(body, event.timestamp, sender))-            .setContentIntent(tap)-            .setAutoCancel(true)-            .setCategory(NotificationCompat.CATEGORY_MESSAGE)-            .setPriority(NotificationCompat.PRIORITY_HIGH)-            .build()-        (getSystemService(NOTIFICATION_SERVICE) as NotificationManager)-            .notify(event.conversationId, notificationId, notification)     }      /**
communicate/src/main/java/com/vayunmathur/communicate/telephony/SmsDeliverReceiver.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/telephony/SmsDeliverReceiver.kt b/communicate/src/main/java/com/vayunmathur/communicate/telephony/SmsDeliverReceiver.ktindex 664f631574..6d583005a4 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/telephony/SmsDeliverReceiver.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/telephony/SmsDeliverReceiver.kt@@ -6,6 +6,10 @@ import android.content.Context import android.content.Intent import android.provider.Telephony import android.util.Log+import com.vayunmathur.communicate.R+import com.vayunmathur.communicate.data.CommunicateLine+import com.vayunmathur.communicate.notifications.ConversationSpace+import com.vayunmathur.communicate.notifications.ConversationTarget  /**  * Handles inbound SMS as the default SMS app. Android delivers `SMS_DELIVER` only to the default@@ -61,6 +65,29 @@ class SmsDeliverReceiver : BroadcastReceiver() {         }         context.contentResolver.insert(Telephony.Sms.Inbox.CONTENT_URI, values)         Log.d(TAG, "stored inbound SMS parts=${parts.size} thread=$threadId")++        if (address != null) {+            ConversationSpace.ensureIncomingChannel(+                context,+                ConversationSpace.SIM_CHANNEL_ID,+                context.getString(R.string.sms_incoming_channel_name),+                context.getString(R.string.sms_incoming_channel_desc),+            )+            ConversationSpace.notifyIncoming(+                context = context,+                target = ConversationTarget(+                    line = CommunicateLine.Sim,+                    address = address,+                    threadId = threadId ?: -1L,+                    personName = address,+                    subscriptionId = if (subscriptionId >= 0) subscriptionId else null,+                ),+                channelId = ConversationSpace.SIM_CHANNEL_ID,+                body = body.ifBlank { context.getString(R.string.new_message) },+                timestamp = System.currentTimeMillis(),+                smallIcon = R.mipmap.ic_launcher,+            )+        }     }      companion object {
communicate/src/main/java/com/vayunmathur/communicate/telephony/WhatsAppSyncService.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/telephony/WhatsAppSyncService.kt b/communicate/src/main/java/com/vayunmathur/communicate/telephony/WhatsAppSyncService.ktindex eb5c10428b..80451de7d9 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/telephony/WhatsAppSyncService.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/telephony/WhatsAppSyncService.kt@@ -11,15 +11,17 @@ import android.os.Build import android.os.IBinder import android.util.Log import androidx.core.app.NotificationCompat-import androidx.core.app.Person import androidx.core.content.ContextCompat import com.vayunmathur.communicate.MainActivity import com.vayunmathur.communicate.R+import com.vayunmathur.communicate.data.CommunicateLine import com.vayunmathur.communicate.data.whatsapp.WhatsAppClient import com.vayunmathur.communicate.data.whatsapp.WhatsAppDatabase import com.vayunmathur.communicate.data.whatsapp.WhatsAppEvent import com.vayunmathur.communicate.data.whatsapp.WhatsAppEventProcessor import com.vayunmathur.communicate.data.whatsapp.WhatsAppLineSession+import com.vayunmathur.communicate.notifications.ConversationSpace+import com.vayunmathur.communicate.notifications.ConversationTarget import com.vayunmathur.library.util.ensureNotificationChannel import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers@@ -109,7 +111,9 @@ class WhatsAppSyncService : Service() {             name = "WhatsApp messages",             importance = NotificationManager.IMPORTANCE_HIGH,             description = "Incoming WhatsApp messages",-        )+        ) {+            setAllowBubbles(true)+        }     }      private fun buildSyncNotification(): Notification {@@ -140,33 +144,23 @@ class WhatsAppSyncService : Service() {     }      private fun showIncomingNotification(event: WhatsAppEvent.IncomingMessage) {-        val notificationId = event.messageId.hashCode()-        val tap = PendingIntent.getActivity(-            this,-            notificationId,-            Intent(this, MainActivity::class.java).apply {-                addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)-                putExtra(EXTRA_OPEN_WHATSAPP_THREAD, event.conversationId)-            },-            PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,+        val isGroup = event.conversationId.endsWith("@g.us")+        val target = ConversationTarget(+            line = CommunicateLine.WhatsApp,+            address = event.peerPhone ?: event.conversationId,+            remoteId = event.conversationId,+            isGroup = isGroup,+            title = if (isGroup) event.peerName else null,+            personName = event.senderName ?: event.peerName ?: event.peerPhone ?: "WhatsApp",+        )+        ConversationSpace.notifyIncoming(+            context = this,+            target = target,+            channelId = INCOMING_CHANNEL_ID,+            body = event.body.ifBlank { getString(R.string.new_message) },+            timestamp = event.timestamp,+            smallIcon = R.mipmap.ic_launcher,         )-        val sender = Person.Builder()-            .setName(event.senderName ?: event.peerName ?: event.peerPhone ?: "WhatsApp")-            .build()-        val self = Person.Builder().setName(getString(R.string.you)).build()-        val body = event.body.ifBlank { "New message" }-        val notification = NotificationCompat.Builder(this, INCOMING_CHANNEL_ID)-            .setSmallIcon(R.mipmap.ic_launcher)-            .setContentTitle(sender.name)-            .setContentText(body)-            .setStyle(NotificationCompat.MessagingStyle(self).addMessage(body, event.timestamp, sender))-            .setContentIntent(tap)-            .setAutoCancel(true)-            .setCategory(NotificationCompat.CATEGORY_MESSAGE)-            .setPriority(NotificationCompat.PRIORITY_HIGH)-            .build()-        (getSystemService(NOTIFICATION_SERVICE) as NotificationManager)-            .notify(event.conversationId, notificationId, notification)     }      private fun startForegroundCompat(notification: Notification) {
communicate/src/main/res/values/strings.xml
diff --git a/communicate/src/main/res/values/strings.xml b/communicate/src/main/res/values/strings.xmlindex b40287f927..798c83519c 100644--- a/communicate/src/main/res/values/strings.xml+++ b/communicate/src/main/res/values/strings.xml@@ -68,6 +68,12 @@     <string name="gv_sync_notification_title">Google Voice receive active</string>     <string name="gv_sync_notification_text">Listening for calls and checking for new messages</string>     <string name="notification_action_stop">Stop</string>+    <!-- Notification channel title for incoming SIM SMS/MMS messages -->+    <string name="sms_incoming_channel_name">Text messages</string>+    <!-- Notification channel description for incoming SIM SMS/MMS messages -->+    <string name="sms_incoming_channel_desc">Incoming SMS and MMS messages.</string>+    <!-- Fallback notification body for a message whose only content is media (e.g. an MMS picture) -->+    <string name="media_message">Media message</string>     <string name="you">You</string>     <string name="call_mute">Mute</string>     <string name="call_unmute">Unmute</string>