communicate: show contact name in call notification (#649)
- Commit
2f33224ebbfaf9fa47a9faa67356a70be1bc31df- Author
- vayun-mathur <[email protected]>
- When
- 2026-09-07 01:13 UTC (3 months ago)
- Parents
d62186b
Diff
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 434bc46eed..535f8c3d92 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/telephony/CommunicateInCallService.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/telephony/CommunicateInCallService.kt@@ -10,6 +10,7 @@ import android.telecom.InCallService import android.telecom.VideoProfile import com.vayunmathur.communicate.MainActivity import com.vayunmathur.communicate.R+import com.vayunmathur.communicate.data.CommunicateRepository import com.vayunmathur.library.util.ensureNotificationChannel /** In-call bridge for carrier/SIM calls that lets Communicate expose notification controls. */@@ -74,7 +75,7 @@ class CommunicateInCallService : InCallService() { val number = call.details.handle?.schemeSpecificPart.orEmpty() val builder = Notification.Builder(this, CHANNEL_ID) .setContentTitle(title)- .setContentText(number.ifBlank { getString(R.string.app_name) })+ .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) .setCategory(Notification.CATEGORY_CALL) .setPriority(Notification.PRIORITY_HIGH)@@ -98,6 +99,18 @@ class CommunicateInCallService : InCallService() { nm.notify(NOTIFICATION_ID, builder.build()) } + /**+ * Memoised because the notification is rebuilt on every state and details change, and the+ * lookup is a synchronous provider query on the main thread.+ */+ private fun callerLabel(number: String): String {+ if (number != lookedUpNumber) {+ lookedUpNumber = number+ lookedUpName = CommunicateRepository.findContactName(this, number)+ }+ return lookedUpName ?: number+ }+ private fun clearNotification() { getSystemService(NotificationManager::class.java)?.cancel(NOTIFICATION_ID) }@@ -126,5 +139,7 @@ class CommunicateInCallService : InCallService() { private const val ACTION_DISCONNECT = "com.vayunmathur.communicate.regularcall.DISCONNECT" private var currentCall: Call? = null+ private var lookedUpNumber: String? = null+ private var lookedUpName: String? = null } }