@@ -4,10 +4,7 @@ import android.app.AlarmManager
4
4
import android.app.PendingIntent
5
5
import android.content.Context
6
6
import android.content.Intent
7
- import android.os.Build
8
- import android.provider.Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM
9
7
import android.text.format.DateUtils
10
- import android.widget.Toast
11
8
import au.com.shiftyjelly.pocketcasts.analytics.AnalyticsEvent.PLAYER_SLEEP_TIMER_RESTARTED
12
9
import au.com.shiftyjelly.pocketcasts.analytics.AnalyticsTracker
13
10
import au.com.shiftyjelly.pocketcasts.utils.log.LogBuffer
@@ -18,7 +15,6 @@ import javax.inject.Singleton
18
15
import kotlin.time.Duration
19
16
import kotlin.time.Duration.Companion.milliseconds
20
17
import kotlin.time.Duration.Companion.minutes
21
- import au.com.shiftyjelly.pocketcasts.localization.R as LR
22
18
23
19
@Singleton
24
20
class SleepTimer @Inject constructor(
@@ -134,26 +130,15 @@ class SleepTimer @Inject constructor(
134
130
val sleepIntent = getSleepIntent()
135
131
val alarmManager = getAlarmManager()
136
132
alarmManager.cancel(sleepIntent)
137
-
138
- return if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . S && ! alarmManager.canScheduleExactAlarms()) {
139
- Toast .makeText(context, LR .string.player_sleep_timer_start_failed, Toast . LENGTH_LONG ).show( )
140
- context.startActivity(
141
- Intent ( ACTION_REQUEST_SCHEDULE_EXACT_ALARM )
142
- // Because we're not launching this from an activity context, we must add the FLAG_ACTIVITY_NEW_TASK flag
143
- .addFlags( Intent . FLAG_ACTIVITY_NEW_TASK ),
144
- )
133
+ return try {
134
+ LogBuffer .i( TAG , " Starting... " )
135
+ alarmManager.setAndAllowWhileIdle( AlarmManager . RTC_WAKEUP , timeMs, sleepIntent )
136
+ sleepTimeMs = timeMs
137
+ lastTimeSleepTimeHasFinished = timeMs.milliseconds
138
+ true
139
+ } catch (e : Exception ) {
140
+ LogBuffer .e( LogBuffer . TAG_CRASH , e, " Unable to start sleep timer. " )
145
141
false
146
- } else {
147
- return try {
148
- LogBuffer .i(TAG , " Starting..." )
149
- alarmManager.setExactAndAllowWhileIdle(AlarmManager .RTC_WAKEUP , timeMs, sleepIntent)
150
- sleepTimeMs = timeMs
151
- lastTimeSleepTimeHasFinished = timeMs.milliseconds
152
- true
153
- } catch (e: Exception ) {
154
- LogBuffer .e(LogBuffer .TAG_CRASH , e, " Unable to start sleep timer." )
155
- false
156
- }
157
142
}
158
143
}
159
144
0 commit comments