Modern Apps git

← Modern-Apps.git

communicate: ring audibly on incoming calls

Commit
bcfbcfc1c958ee3a94939da233ca9b6e25938e40
Author
vayun-mathur <[email protected]>
When
2026-10-22 15:42 UTC (1 month ago)
Parents
048d96d

Diff

communicate/src/main/AndroidManifest.xml
diff --git a/communicate/src/main/AndroidManifest.xml b/communicate/src/main/AndroidManifest.xmlindex a9dfa4b541..d432d4a12b 100644--- a/communicate/src/main/AndroidManifest.xml+++ b/communicate/src/main/AndroidManifest.xml@@ -24,6 +24,7 @@     <uses-permission android:name="android.permission.FOREGROUND_SERVICE_REMOTE_MESSAGING" />     <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />     <uses-permission android:name="android.permission.WAKE_LOCK" />+    <uses-permission android:name="android.permission.VIBRATE" />     <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />     <uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" /> 
communicate/src/main/java/com/vayunmathur/communicate/data/googlevoice/call/GoogleVoiceCallManager.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/data/googlevoice/call/GoogleVoiceCallManager.kt b/communicate/src/main/java/com/vayunmathur/communicate/data/googlevoice/call/GoogleVoiceCallManager.ktindex 0aab43e3b6..600c88ea09 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/data/googlevoice/call/GoogleVoiceCallManager.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/data/googlevoice/call/GoogleVoiceCallManager.kt@@ -216,6 +216,14 @@ object GoogleVoiceCallManager {             pendingInviteSdp = remoteSdp             _state.value = CallState(phase = CallPhase.Incoming, remoteNumber = from)             onIncomingCall?.invoke(from)+            // Telecom can silently drop the mirror (no failure callback); the ringing surface+            // still has to come up, so start it directly as well. Idempotent with the+            // ConnectionService path — the service collects the same manager state.+            appContext?.let { ctx ->+                runCatching {+                    com.vayunmathur.communicate.telephony.GoogleVoiceCallForegroundService.start(ctx)+                }+            }         }     } 
communicate/src/main/java/com/vayunmathur/communicate/data/signal/SignalCalls.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/data/signal/SignalCalls.kt b/communicate/src/main/java/com/vayunmathur/communicate/data/signal/SignalCalls.ktindex a262649cb1..16d251df71 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/data/signal/SignalCalls.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/data/signal/SignalCalls.kt@@ -128,6 +128,13 @@ private suspend fun SignalClient.handleCallOffer(     )     // Hand the call to the system so it owns ringing, audio focus and routing.     appContext?.let { ctx -> InAppCallTelecom.addIncoming(ctx, senderAci) }+    // Telecom can silently drop the mirror (no failure callback); the ringing surface still+    // has to come up, so start it directly as well. Idempotent with the ConnectionService path.+    appContext?.let { ctx ->+        runCatching {+            com.vayunmathur.communicate.telephony.InAppCallForegroundService.start(ctx)+        }+    }     manager.receivedOffer(         callId = offer.id,         senderAci = senderAci,
communicate/src/main/java/com/vayunmathur/communicate/data/whatsapp/call/WhatsAppCallBridge.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/data/whatsapp/call/WhatsAppCallBridge.kt b/communicate/src/main/java/com/vayunmathur/communicate/data/whatsapp/call/WhatsAppCallBridge.ktindex f06614b321..4e4a33b79b 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/data/whatsapp/call/WhatsAppCallBridge.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/data/whatsapp/call/WhatsAppCallBridge.kt@@ -66,6 +66,15 @@ object WhatsAppCallBridge {                             capabilities = CallCapabilities.AudioAndVideo,                         )                         InAppCallTelecom.addIncoming(appContext, state.peerJid)+                        // Telecom can silently drop the mirror (no callback); the ringing+                        // surface still has to come up, so start it directly as well.+                        // Idempotent with the ConnectionService path — the service collects+                        // the same registry state and just re-posts the same notification.+                        runCatching {+                            com.vayunmathur.communicate.telephony.InAppCallForegroundService.start(+                                appContext,+                            )+                        }                     }                     WhatsAppCallPhase.Connecting -> InAppCallRegistry.onPhase(InAppCallPhase.Connecting)                     WhatsAppCallPhase.Active -> InAppCallRegistry.onPhase(InAppCallPhase.Active)
communicate/src/main/java/com/vayunmathur/communicate/telephony/CallRinger.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/telephony/CallRinger.kt b/communicate/src/main/java/com/vayunmathur/communicate/telephony/CallRinger.ktnew file mode 100644index 0000000000..ed4cd91582--- /dev/null+++ b/communicate/src/main/java/com/vayunmathur/communicate/telephony/CallRinger.kt@@ -0,0 +1,104 @@+package com.vayunmathur.communicate.telephony++import android.content.Context+import android.media.AudioAttributes+import android.media.MediaPlayer+import android.media.RingtoneManager+import android.os.VibrationEffect+import android.os.Vibrator+import android.os.VibratorManager+import com.vayunmathur.library.log.Log++/**+ * Audible + haptic ringing for incoming calls, shared by every line.+ *+ * Self-managed Telecom connections ([InAppCallConnectionService],+ * [GoogleVoiceConnectionService]) post an incoming-call notification — but no notification (even a+ * `CallStyle` one) loops the ringtone by itself, and none of the call paths+ * played anything. The result was exactly the reported bug: a silent heads-up+ * notification instead of a ringing call. Carrier/SIM calls are excluded: the+ * platform already plays the ringtone for dialer-role calls, and a second+ * loop would double it.+ *+ * One singleton rather than one per service because only one call can ring at+ * a time, and because answer/decline can arrive from the system surface, the+ * notification action, or the in-app screen — whichever path leaves+ * `Incoming` first stops the same ringer. Start is idempotent; stop always+ * releases.+ *+ * Sound is the user's default ringtone looped through+ * `USAGE_NOTIFICATION_RINGTONE` (so silent/DND modes are honoured by the platform), plus the+ * standard ring-vibrate waveform. The incoming-call notifications themselves stay+ * silent — the ringer owns audio, otherwise the channel's ding would double+ * up with the loop.+ */+object CallRinger {+    private const val TAG = "CallRinger"++    @Volatile+    private var player: MediaPlayer? = null++    @Volatile+    private var vibrator: Vibrator? = null++    /** Idempotent: a second incoming call while ringing keeps the same loop. */+    @Synchronized+    fun start(context: Context) {+        if (player != null) return+        val app = context.applicationContext+        startVibration(app)+        startSound(app)+    }++    @Synchronized+    fun stop() {+        runCatching { player?.stop() }+        runCatching { player?.release() }+        player = null+        runCatching { vibrator?.cancel() }+        vibrator = null+    }++    private fun startVibration(app: Context) {+        runCatching {+            val vib = app.getSystemService(VibratorManager::class.java)?.defaultVibrator ?: return+            vibrator = vib+            vib.vibrate(VibrationEffect.createWaveform(longArrayOf(0, 1000, 1000), 0))+        }.onFailure {+            Log.status(TAG, "could not start call vibration", it)+        }+    }++    private fun startSound(app: Context) {+        val uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE)+            ?: RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)+            ?: return+        runCatching {+            MediaPlayer().apply {+                setDataSource(app, uri)+                setAudioAttributes(+                    AudioAttributes.Builder()+                        .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)+                        .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)+                        .build(),+                )+                isLooping = true+                setOnPreparedListener { mp ->+                    // stop() may have run while prepare was in flight; only start the+                    // current generation, otherwise a stale callback re-rings after hangup.+                    if (mp === player) runCatching { mp.start() } else runCatching { mp.release() }+                }+                setOnErrorListener { _, _, _ ->+                    Log.status(TAG, "ringtone playback failed for $uri")+                    true+                }+                // Async: prepare() blocks (content-resolver IO) and this is+                // called from the service's main-thread state collector.+                prepareAsync()+            }.also { player = it }+        }.onFailure {+            Log.status(TAG, "could not start ringtone for $uri", it)+            player = null+        }+    }+}
communicate/src/main/java/com/vayunmathur/communicate/telephony/CommunicateInCallService.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/telephony/CommunicateInCallService.kt b/communicate/src/main/java/com/vayunmathur/communicate/telephony/CommunicateInCallService.ktindex 7fc086a15a..7f90304f00 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/telephony/CommunicateInCallService.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/telephony/CommunicateInCallService.kt@@ -13,6 +13,7 @@ import com.vayunmathur.communicate.MainActivity import com.vayunmathur.communicate.R import com.vayunmathur.communicate.data.CommunicateRepository import com.vayunmathur.communicate.data.findContactName+import com.vayunmathur.library.util.deleteNotificationChannel import com.vayunmathur.library.util.ensureNotificationChannel  /**@@ -76,10 +77,14 @@ class CommunicateInCallService : InCallService() {     private fun showOrClearNotification(call: Call) {         when (call.details.state) {             Call.STATE_RINGING -> showNotification(call, incoming = true)-            Call.STATE_DIALING, Call.STATE_CONNECTING, Call.STATE_ACTIVE, Call.STATE_HOLDING -> showNotification(-                call,-                incoming = false)-            else -> clearNotification()+            Call.STATE_DIALING, Call.STATE_CONNECTING, Call.STATE_ACTIVE, Call.STATE_HOLDING -> {+                showNotification(+                    call,+                    incoming = false)+            }+            else -> {+                clearNotification()+            }         }     } @@ -93,6 +98,9 @@ class CommunicateInCallService : InCallService() {     }      private fun showNotification(call: Call, incoming: Boolean) {+        // Retired: the pre-CallStyle channel, whose hand-built actions read as an ordinary+        // notification rather than a ringing call.+        deleteNotificationChannel(LEGACY_CHANNEL_ID)         ensureNotificationChannel(             id = CHANNEL_ID,             name = getString(R.string.regular_call_channel_name),@@ -100,43 +108,80 @@ class CommunicateInCallService : InCallService() {             description = getString(R.string.regular_call_channel_desc),         ) {             lockscreenVisibility = Notification.VISIBILITY_PUBLIC+            // Telecom (the system phone stack) owns ringing audio for carrier calls; this+            // notification is only the answer/decline surface, so it stays silent and never+            // re-alerts — otherwise its ding would double up with the system ringtone.+            setSound(null, null)+            enableVibration(false)         } -        val title =-            if (incoming) getString(R.string.call_state_incoming_generic) else getString(R.string.inapp_ongoing_call)+        if (incoming) {+            showIncomingCallNotification(call)+            return+        }         val number = call.details.handle?.schemeSpecificPart.orEmpty()         val builder = Notification.Builder(this, CHANNEL_ID)-            .setContentTitle(title)+            .setContentTitle(getString(R.string.inapp_ongoing_call))             .setContentText(callerLabel(number).ifBlank { getString(R.string.app_name) })-            .setSmallIcon(if (incoming) android.R.drawable.sym_call_incoming else android.R.drawable.sym_action_call)+            .setSmallIcon(android.R.drawable.sym_action_call)             .setCategory(Notification.CATEGORY_CALL)             .setPriority(Notification.PRIORITY_HIGH)             .setVisibility(Notification.VISIBILITY_PUBLIC)             .setOngoing(true)             .setContentIntent(activityIntent())--        if (incoming) {-            builder-                .addAction(-                    android.R.drawable.sym_call_incoming,-                    getString(R.string.call_answer),-                    actionIntent(ACTION_ANSWER, 1))-                .addAction(-                    android.R.drawable.ic_menu_close_clear_cancel,-                    getString(R.string.call_decline),-                    actionIntent(ACTION_DECLINE, 2))-        } else {-            builder.addAction(+            .addAction(                 android.R.drawable.ic_menu_close_clear_cancel,                 getString(R.string.call_end),                 actionIntent(ACTION_DISCONNECT, DISCONNECT_REQUEST_CODE),             )-        }          val nm = getSystemService(NotificationManager::class.java) ?: return         nm.notify(NOTIFICATION_ID, builder.build())     } +    /**+     * Incoming-call notification using [Notification.CallStyle], which is what gives the system's+     * standard green answer / red decline buttons and full-screen ringing treatment. Hand-built+     * actions would render in the app's theme colours instead, which reads as an ordinary+     * notification rather than a ringing call.+     */+    private fun showIncomingCallNotification(call: Call) {+        val number = call.details.handle?.schemeSpecificPart.orEmpty()+        val caller = android.app.Person.Builder()+            .setName(callerLabel(number).ifBlank { getString(R.string.call_state_incoming_generic) })+            .setImportant(true)+            .build()+        val notification = Notification.Builder(this, CHANNEL_ID)+            .setStyle(+                Notification.CallStyle.forIncomingCall(+                    caller,+                    actionIntent(ACTION_DECLINE, 2),+                    actionIntent(ACTION_ANSWER, 1),+                ),+            )+            .setSmallIcon(android.R.drawable.sym_call_incoming)+            .setCategory(Notification.CATEGORY_CALL)+            // Colorized plus CallStyle is what promotes it to the ringing treatment.+            .setColorized(true)+            .setVisibility(Notification.VISIBILITY_PUBLIC)+            .setOngoing(true)+            .setAutoCancel(false)+            .setContentIntent(activityIntent())+            .setFullScreenIntent(fullScreenIntent(), true)+            .build()+        val nm = getSystemService(NotificationManager::class.java) ?: return+        nm.notify(NOTIFICATION_ID, notification)+    }++    private fun fullScreenIntent(): PendingIntent = PendingIntent.getActivity(+        this,+        4,+        Intent(this, MainActivity::class.java).apply {+            addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP)+        },+        PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,+    )+     /**      * Memoised because the notification is rebuilt on every state and details change, and the      * lookup is a synchronous provider query on the main thread.@@ -170,7 +215,10 @@ class CommunicateInCallService : InCallService() {     )      companion object {-        private const val CHANNEL_ID = "regular_calls"+        // Retired pre-CallStyle channel: the system keeps an existing channel's sound, so silencing+        // it in place would never take effect — the renamed channel below replaces it and this deletes it.+        private const val LEGACY_CHANNEL_ID = "regular_calls"+        private const val CHANNEL_ID = "regular_calls_v2"         private const val NOTIFICATION_ID = 4811         private const val ACTION_ANSWER = "com.vayunmathur.communicate.regularcall.ANSWER"         private const val ACTION_DECLINE = "com.vayunmathur.communicate.regularcall.DECLINE"
communicate/src/main/java/com/vayunmathur/communicate/telephony/GoogleVoiceCallForegroundService.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/telephony/GoogleVoiceCallForegroundService.kt b/communicate/src/main/java/com/vayunmathur/communicate/telephony/GoogleVoiceCallForegroundService.ktindex 27516cb78f..08beeb1897 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/telephony/GoogleVoiceCallForegroundService.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/telephony/GoogleVoiceCallForegroundService.kt@@ -14,6 +14,7 @@ import com.vayunmathur.communicate.MainActivity import com.vayunmathur.communicate.R import com.vayunmathur.communicate.data.googlevoice.call.CallPhase import com.vayunmathur.communicate.data.googlevoice.call.GoogleVoiceCallManager+import com.vayunmathur.library.util.deleteNotificationChannel import com.vayunmathur.library.util.ensureNotificationChannel import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job@@ -60,6 +61,11 @@ class GoogleVoiceCallForegroundService : Service() {     private fun startForegroundWithNotification() {         ensureChannels()         val state = GoogleVoiceCallManager.state.value+        if (state.phase == CallPhase.Incoming) {+            CallRinger.start(this)+        } else {+            CallRinger.stop()+        }         val contentIntent = callActivityIntent(0)         val notification = if (state.phase == CallPhase.Incoming) {             buildIncomingCallNotification(state.remoteNumber, contentIntent)@@ -75,6 +81,8 @@ class GoogleVoiceCallForegroundService : Service() {     }      private fun ensureChannels() {+        // Retired: the pre-ringer channel, whose system-kept sound would ding over the ringtone loop.+        deleteNotificationChannel(LEGACY_INCOMING_CHANNEL_ID)         ensureNotificationChannel(CHANNEL_ID, getString(R.string.gv_call_channel_name))         ensureNotificationChannel(             id = INCOMING_CHANNEL_ID,@@ -83,32 +91,40 @@ class GoogleVoiceCallForegroundService : Service() {             description = getString(R.string.gv_incoming_call_channel_desc),         ) {             lockscreenVisibility = Notification.VISIBILITY_PUBLIC+            // The ringer owns audio; a channel sound here would ding once over the loop.+            setSound(null, null)+            enableVibration(false)         }     } +    /**+     * Incoming-call notification using [Notification.CallStyle], which is what gives the system's+     * standard green answer / red decline buttons and full-screen ringing treatment. Hand-built+     * actions would render in the app's theme colours instead, which reads as an ordinary+     * notification rather than a ringing call.+     */     private fun buildIncomingCallNotification(remoteNumber: String, contentIntent: PendingIntent): Notification {-        val fullScreenIntent = callActivityIntent(1)+        val caller = android.app.Person.Builder()+            .setName(remoteNumber.ifBlank { getString(R.string.account_google_voice) })+            .setImportant(true)+            .build()         return Notification.Builder(this, INCOMING_CHANNEL_ID)-            .setContentTitle(getString(R.string.call_state_incoming))-            .setContentText(remoteNumber.ifBlank { getString(R.string.account_google_voice) })+            .setStyle(+                Notification.CallStyle.forIncomingCall(+                    caller,+                    serviceActionIntent(ACTION_HANGUP, HANGUP_REQUEST_CODE),+                    serviceActionIntent(ACTION_ANSWER, 2),+                ),+            )             .setSmallIcon(android.R.drawable.sym_call_incoming)             .setCategory(Notification.CATEGORY_CALL)-            .setPriority(Notification.PRIORITY_MAX)+            // Colorized plus CallStyle is what promotes it to the ringing treatment.+            .setColorized(true)             .setVisibility(Notification.VISIBILITY_PUBLIC)             .setOngoing(true)             .setAutoCancel(false)             .setContentIntent(contentIntent)-            .setFullScreenIntent(fullScreenIntent, true)-            .addAction(-                android.R.drawable.sym_call_incoming,-                getString(R.string.call_answer),-                serviceActionIntent(ACTION_ANSWER, 2),-            )-            .addAction(-                android.R.drawable.ic_menu_close_clear_cancel,-                getString(R.string.call_decline),-                serviceActionIntent(ACTION_HANGUP, HANGUP_REQUEST_CODE),-            )+            .setFullScreenIntent(callActivityIntent(1), true)             .build()     } @@ -154,6 +170,7 @@ class GoogleVoiceCallForegroundService : Service() {     )      private fun stopSelfSafely() {+        CallRinger.stop()         androidx.core.app.ServiceCompat.stopForeground(             this, androidx.core.app.ServiceCompat.STOP_FOREGROUND_REMOVE,         )@@ -161,13 +178,17 @@ class GoogleVoiceCallForegroundService : Service() {     }      override fun onDestroy() {+        CallRinger.stop()         observeJob?.cancel()         super.onDestroy()     }      companion object {         private const val CHANNEL_ID = "gv_calls"-        private const val INCOMING_CHANNEL_ID = "gv_calls_incoming"+        // Retired pre-ringer channel: the system keeps an existing channel's sound, so muting it+        // in place would never take effect — the renamed channel below replaces it and this deletes it.+        private const val LEGACY_INCOMING_CHANNEL_ID = "gv_calls_incoming"+        private const val INCOMING_CHANNEL_ID = "gv_calls_incoming_v2"         private const val NOTIFICATION_ID = 4711         private const val ACTION_ANSWER = "com.vayunmathur.communicate.googlevoice.ANSWER_CALL"         private const val ACTION_HANGUP = "com.vayunmathur.communicate.googlevoice.HANGUP_CALL"
communicate/src/main/java/com/vayunmathur/communicate/telephony/GoogleVoiceConnectionService.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/telephony/GoogleVoiceConnectionService.kt b/communicate/src/main/java/com/vayunmathur/communicate/telephony/GoogleVoiceConnectionService.ktindex a2f8a29181..7867578c1e 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/telephony/GoogleVoiceConnectionService.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/telephony/GoogleVoiceConnectionService.kt@@ -8,6 +8,7 @@ import android.telecom.PhoneAccountHandle import android.telecom.TelecomManager import android.telecom.VideoProfile import com.vayunmathur.communicate.data.googlevoice.call.GoogleVoiceCallManager+import com.vayunmathur.library.log.Log  /**  * Self-managed [ConnectionService] that makes Google Voice behave like a second line. Outgoing@@ -60,4 +61,18 @@ class GoogleVoiceConnectionService : ConnectionService() {     ) {         GoogleVoiceCallManager.hangup()     }++    override fun onCreateIncomingConnectionFailed(+        connectionManagerPhoneAccount: PhoneAccountHandle?,+        request: ConnectionRequest?,+    ) {+        Log.status(TAG, "Telecom could not create the incoming connection; the call continues without it")+        // The system surface is gone, but the line still owns a ringing call — surface it directly+        // so it still rings instead of degrading to a silent heads-up.+        runCatching { GoogleVoiceCallForegroundService.start(applicationContext) }+    }++    private companion object {+        const val TAG = "GoogleVoiceCallService"+    } }
communicate/src/main/java/com/vayunmathur/communicate/telephony/InAppCallForegroundService.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/telephony/InAppCallForegroundService.kt b/communicate/src/main/java/com/vayunmathur/communicate/telephony/InAppCallForegroundService.ktindex 667e7cc797..410cfb1ee8 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/telephony/InAppCallForegroundService.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/telephony/InAppCallForegroundService.kt@@ -16,6 +16,7 @@ import com.vayunmathur.communicate.MainActivity import com.vayunmathur.communicate.R import com.vayunmathur.communicate.data.call.InAppCallPhase import com.vayunmathur.communicate.data.call.InAppCallRegistry+import com.vayunmathur.library.util.deleteNotificationChannel import com.vayunmathur.library.util.ensureNotificationChannel import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job@@ -62,6 +63,11 @@ class InAppCallForegroundService : Service() {     private fun startForegroundWithNotification() {         ensureChannels()         val state = InAppCallRegistry.state.value+        if (state.phase == InAppCallPhase.Incoming) {+            CallRinger.start(this)+        } else {+            CallRinger.stop()+        }         val notification = if (state.phase == InAppCallPhase.Incoming) {             buildIncomingCallNotification(state.peerName)         } else {@@ -82,6 +88,8 @@ class InAppCallForegroundService : Service() {     }      private fun ensureChannels() {+        // Retired: the pre-ringer channel, whose system-kept sound would ding over the ringtone loop.+        deleteNotificationChannel(LEGACY_INCOMING_CHANNEL_ID)         ensureNotificationChannel(CHANNEL_ID, getString(R.string.inapp_call_channel_name))         ensureNotificationChannel(             id = INCOMING_CHANNEL_ID,@@ -90,6 +98,9 @@ class InAppCallForegroundService : Service() {             description = getString(R.string.inapp_incoming_call_channel_desc),         ) {             lockscreenVisibility = Notification.VISIBILITY_PUBLIC+            // The ringer owns audio; a channel sound here would ding once over the loop.+            setSound(null, null)+            enableVibration(false)         }     } @@ -159,18 +170,23 @@ class InAppCallForegroundService : Service() {     )      private fun stopSelfSafely() {+        CallRinger.stop()         ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)         stopSelf()     }      override fun onDestroy() {+        CallRinger.stop()         observeJob?.cancel()         super.onDestroy()     }      companion object {         private const val CHANNEL_ID = "inapp_calls"-        private const val INCOMING_CHANNEL_ID = "inapp_calls_incoming"+        // Retired pre-ringer channel: the system keeps an existing channel's sound, so muting it+        // in place would never take effect — the renamed channel below replaces it and this deletes it.+        private const val LEGACY_INCOMING_CHANNEL_ID = "inapp_calls_incoming"+        private const val INCOMING_CHANNEL_ID = "inapp_calls_incoming_v2"         private const val NOTIFICATION_ID = 4712          private const val ACTION_ANSWER = "com.vayunmathur.communicate.inappcall.ANSWER_CALL"
communicate/src/main/java/com/vayunmathur/communicate/telephony/InAppCallTelecom.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/telephony/InAppCallTelecom.kt b/communicate/src/main/java/com/vayunmathur/communicate/telephony/InAppCallTelecom.ktindex 35c3ff1064..c716270fad 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/telephony/InAppCallTelecom.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/telephony/InAppCallTelecom.kt@@ -198,6 +198,9 @@ class InAppCallConnectionService : ConnectionService() {         request: ConnectionRequest?,     ) {         Log.status(TAG, "Telecom could not create the incoming connection; the call continues without it")+        // The system surface is gone, but the line still owns a ringing call — surface it directly+        // so it still rings instead of degrading to a silent heads-up.+        runCatching { InAppCallForegroundService.start(applicationContext) }     }      private companion object {