@@ -33,6 +33,7 @@ import androidx.core.app.NotificationCompat
3333import androidx.core.app.NotificationManagerCompat
3434import kotlinx.coroutines.CoroutineScope
3535import kotlinx.coroutines.Dispatchers
36+ import kotlinx.coroutines.Job
3637import kotlinx.coroutines.SupervisorJob
3738import kotlinx.coroutines.delay
3839import kotlinx.coroutines.flow.asStateFlow
@@ -71,9 +72,11 @@ class TimerService : Service() {
7172 private var pauseDuration = 0L
7273
7374 private var job = SupervisorJob ()
74- private val scope = CoroutineScope (Dispatchers .IO + job)
75+ private val timerScope = CoroutineScope (Dispatchers .IO + job)
7576 private val skipScope = CoroutineScope (Dispatchers .IO + job)
7677
78+ private var autoAlarmStopScope: Job ? = null
79+
7780 private var alarm: MediaPlayer ? = null
7881 private val vibrator by lazy {
7982 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .S ) {
@@ -154,7 +157,7 @@ class TimerService : Service() {
154157
155158 var iterations = - 1
156159
157- scope .launch {
160+ timerScope .launch {
158161 while (true ) {
159162 if (! timerState.value.timerRunning) break
160163 if (startTime == 0L ) startTime = SystemClock .elapsedRealtime()
@@ -372,6 +375,11 @@ class TimerService : Service() {
372375
373376 appContainer.activityTurnScreenOn(true )
374377
378+ autoAlarmStopScope = CoroutineScope (Dispatchers .IO ).launch {
379+ delay(1 * 60 * 1000 )
380+ stopAlarm()
381+ }
382+
375383 if (timerRepository.vibrateEnabled) {
376384 if (! vibrator.hasVibrator()) {
377385 return
@@ -384,6 +392,8 @@ class TimerService : Service() {
384392 }
385393
386394 fun stopAlarm () {
395+ autoAlarmStopScope?.cancel()
396+
387397 if (timerRepository.alarmEnabled) {
388398 alarm?.pause()
389399 alarm?.seekTo(0 )
0 commit comments