Skip to content

Commit 1f0430c

Browse files
committed
Fail the scheduler if we can't set exact alarms
1 parent 22eec67 commit 1f0430c

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎data/src/main/java/xyz/aprildown/timer/data/repositories/SchedulerExecutorImpl.kt‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package xyz.aprildown.timer.data.repositories
22

3+
import android.app.AlarmManager
34
import android.content.Context
5+
import android.os.Build
6+
import androidx.core.content.getSystemService
47
import dagger.Reusable
58
import dagger.hilt.android.qualifiers.ApplicationContext
69
import xyz.aprildown.timer.data.job.SchedulerJob
@@ -19,6 +22,14 @@ class SchedulerExecutorImpl @Inject constructor(
1922
) : SchedulerExecutor {
2023

2124
override fun schedule(scheduler: SchedulerEntity): SetSchedulerEnable.Result {
25+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
26+
val am = context.getSystemService<AlarmManager>()
27+
// The permission seems to have been granted by default.
28+
if (am?.canScheduleExactAlarms() == false) {
29+
// TODO: 2022/3/19 Better error message
30+
return SetSchedulerEnable.Result.Failed
31+
}
32+
}
2233
return when (scheduler.action) {
2334
SchedulerEntity.ACTION_START, SchedulerEntity.ACTION_END -> {
2435
SetSchedulerEnable.Result.Scheduled(SchedulerJob.scheduleAJob(scheduler))

0 commit comments

Comments
 (0)