From 87acfae06970e1b686108aba8eb510442adb3e5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Bautista=20Fern=C3=A1ndez?= Date: Fri, 24 Jul 2026 11:16:24 +0200 Subject: [PATCH] fix(alarm): declare pendingMissedIntent nullable to stop STOP_NATIVE NPE cancelAutoSilence calls pendingMissedIntent with FLAG_NO_CREATE, the one Android flag whose entire purpose is to make getBroadcast() return null on no match. The Kotlin signature declared a non-null return type, so the compiler-inserted assertion threw NPE inside onStartCommand, crashing the process before the Dart-side postpone flow could reach its actual +N-minute reschedule call. --- .../main/kotlin/es/freetimelab/pluriwave/AlarmScheduler.kt | 5 ++++- .../es/freetimelab/pluriwave/PluriWaveAlarmReceiver.kt | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/android/app/src/main/kotlin/es/freetimelab/pluriwave/AlarmScheduler.kt b/android/app/src/main/kotlin/es/freetimelab/pluriwave/AlarmScheduler.kt index ba6f513..699396b 100644 --- a/android/app/src/main/kotlin/es/freetimelab/pluriwave/AlarmScheduler.kt +++ b/android/app/src/main/kotlin/es/freetimelab/pluriwave/AlarmScheduler.kt @@ -741,7 +741,10 @@ class AlarmScheduler(private val context: Context) { appContext, id, PendingIntent.FLAG_UPDATE_CURRENT - ) + ) ?: run { + Log.w(tag, "alarm.autoSilence arm failed: pendingMissedIntent returned null id=$id") + return + } try { alarmManager.setExactAndAllowWhileIdle( AlarmManager.RTC_WAKEUP, diff --git a/android/app/src/main/kotlin/es/freetimelab/pluriwave/PluriWaveAlarmReceiver.kt b/android/app/src/main/kotlin/es/freetimelab/pluriwave/PluriWaveAlarmReceiver.kt index ac6400d..c5f8105 100644 --- a/android/app/src/main/kotlin/es/freetimelab/pluriwave/PluriWaveAlarmReceiver.kt +++ b/android/app/src/main/kotlin/es/freetimelab/pluriwave/PluriWaveAlarmReceiver.kt @@ -286,7 +286,7 @@ class PluriWaveAlarmReceiver : BroadcastReceiver() { private fun requestCode(id: String, slot: Int): Int = 47 * id.hashCode() + slot /** Shared PendingIntent factory for the MISSED transition alarm (Decision 3). */ - fun pendingMissedIntent(context: Context, alarmId: String, flags: Int): PendingIntent = + fun pendingMissedIntent(context: Context, alarmId: String, flags: Int): PendingIntent? = PendingIntent.getBroadcast( context, requestCode(alarmId, 4),