diff --git a/telefon/app/build.gradle.kts b/telefon/app/build.gradle.kts index 5dac34d..4f872c4 100644 --- a/telefon/app/build.gradle.kts +++ b/telefon/app/build.gradle.kts @@ -16,8 +16,8 @@ android { applicationId = "app.telefon" minSdk = 29 targetSdk = 36 - versionCode = 2 - versionName = "0.1.1" + versionCode = 3 + versionName = "0.1.2" } // Release key lives outside the repo; without it, release builds fall back to the debug key (local only). diff --git a/telefon/app/src/main/java/app/telefon/call/CallService.kt b/telefon/app/src/main/java/app/telefon/call/CallService.kt index 3f5aebb..f98f4b4 100644 --- a/telefon/app/src/main/java/app/telefon/call/CallService.kt +++ b/telefon/app/src/main/java/app/telefon/call/CallService.kt @@ -25,7 +25,9 @@ class CallService : InCallService() { override fun onCallAdded(call: Call) { CallManager.added(call) - if (call.details.state == Call.STATE_RINGING) showIncoming(call) else startActivity(CallActivity.intent(this)) + // a crash here would make Telecom switch to the system phone app, so failures are logged, not thrown + runCatching { if (call.details.state == Call.STATE_RINGING) showIncoming(call) else startActivity(CallActivity.intent(this)) } + .onFailure { android.util.Log.e("Telefon", "onCallAdded", it); runCatching { startActivity(CallActivity.intent(this)) } } } override fun onCallRemoved(call: Call) = CallManager.removed(call) @@ -36,7 +38,9 @@ class CallService : InCallService() { updateProximity(audioState.route) } - internal fun onCallsChanged(calls: List) { + internal fun onCallsChanged(calls: List) = runCatching { updateNotification(calls) }.onFailure { android.util.Log.e("Telefon", "notification", it) } + + private fun updateNotification(calls: List) { val nm = getSystemService(NotificationManager::class.java) val ringing = calls.firstOrNull { it.phase == Phase.RINGING } val current = calls.firstOrNull { it.phase != Phase.RINGING && it.phase != Phase.DISCONNECTED } @@ -64,10 +68,11 @@ class CallService : InCallService() { private fun ongoing(c: CallUi): Notification { val name = Contacts.lookupName(this, c.number) ?: c.number - val person = Person.Builder().setName(name).build() + // not CallStyle: that style is only allowed with a foreground service or a full-screen intent + // and throws otherwise, which made Telecom fall back to the system phone app return NotificationCompat.Builder(this, CH_ONGOING).setSmallIcon(R.drawable.ic_stat_call) - .setContentTitle(name).setContentIntent(CallActivity.pending(this)).setOngoing(true).setSilent(true) - .setStyle(NotificationCompat.CallStyle.forOngoingCall(person, action(ACTION_HANGUP))) + .setContentTitle(name).setContentText(getString(R.string.ongoing_call)).setContentIntent(CallActivity.pending(this)).setOngoing(true).setSilent(true) + .addAction(0, getString(R.string.hang_up), action(ACTION_HANGUP)) .apply { c.connectedAt?.let { setUsesChronometer(true).setWhen(it).setShowWhen(true) } } .setCategory(NotificationCompat.CATEGORY_CALL).build() } diff --git a/telefon/app/src/main/res/values/strings.xml b/telefon/app/src/main/res/values/strings.xml index 074937b..355a44a 100644 --- a/telefon/app/src/main/res/values/strings.xml +++ b/telefon/app/src/main/res/values/strings.xml @@ -57,6 +57,7 @@ Fortsetzen Bluetooth Auflegen + Laufender Anruf Eingehende Anrufe Laufende Anrufe