From d4f4f8b4a95dc7ee238636e5c107b9a8a90d144d Mon Sep 17 00:00:00 2001 From: "Alinson S. Xavier" Date: Mon, 5 Jun 2023 20:25:00 -0500 Subject: [PATCH] Prevent crash if exact alarm permission is revoked --- .../main/java/org/isoron/uhabits/intents/IntentScheduler.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/intents/IntentScheduler.kt b/uhabits-android/src/main/java/org/isoron/uhabits/intents/IntentScheduler.kt index 089af4af2..007b7f08d 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/intents/IntentScheduler.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/intents/IntentScheduler.kt @@ -25,6 +25,7 @@ import android.app.AlarmManager.RTC_WAKEUP import android.app.PendingIntent import android.content.Context import android.content.Context.ALARM_SERVICE +import android.os.Build import android.util.Log import org.isoron.uhabits.core.AppScope import org.isoron.uhabits.core.models.Habit @@ -56,6 +57,10 @@ class IntentScheduler ) return SchedulerResult.IGNORED } + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && !manager.canScheduleExactAlarms()) { + Log.e("IntentScheduler", "No permission to schedule exact alarms") + return SchedulerResult.IGNORED + } manager.setExactAndAllowWhileIdle(alarmType, timestamp, intent) return SchedulerResult.OK }