1+ /*
2+ * Copyright (c) 2025 Nishant Mishra
3+ *
4+ * This file is part of Tomato - a minimalist pomodoro timer for Android.
5+ *
6+ * Tomato is free software: you can redistribute it and/or modify it under the terms of the GNU
7+ * General Public License as published by the Free Software Foundation, either version 3 of the
8+ * License, or (at your option) any later version.
9+ *
10+ * Tomato is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
11+ * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
12+ * Public License for more details.
13+ *
14+ * You should have received a copy of the GNU General Public License along with Tomato.
15+ * If not, see <https://www.gnu.org/licenses/>.
16+ */
17+
118package org.nsh07.pomodoro.service
219
320import android.annotation.SuppressLint
@@ -7,7 +24,6 @@ import android.media.AudioAttributes
724import android.media.MediaPlayer
825import android.os.Build
926import android.os.IBinder
10- import android.os.PowerManager
1127import android.os.SystemClock
1228import android.os.VibrationEffect
1329import android.os.Vibrator
@@ -23,7 +39,6 @@ import kotlinx.coroutines.flow.asStateFlow
2339import kotlinx.coroutines.flow.update
2440import kotlinx.coroutines.launch
2541import kotlinx.coroutines.runBlocking
26- import org.nsh07.pomodoro.MainActivity
2742import org.nsh07.pomodoro.R
2843import org.nsh07.pomodoro.TomatoApplication
2944import org.nsh07.pomodoro.ui.timerScreen.viewModel.TimerMode
@@ -60,10 +75,6 @@ class TimerService : Service() {
6075 private val skipScope = CoroutineScope (Dispatchers .IO + job)
6176
6277 private var alarm: MediaPlayer ? = null
63-
64-
65- private var wakeLock: PowerManager .WakeLock ? = null
66-
6778 private val vibrator by lazy {
6879 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .S ) {
6980 val vibratorManager = getSystemService(VIBRATOR_MANAGER_SERVICE ) as VibratorManager
@@ -94,7 +105,6 @@ class TimerService : Service() {
94105 saveTimeToDb()
95106 notificationManager.cancel(1 )
96107 alarm?.release()
97- wakeLock?.release()
98108 }
99109 super .onDestroy()
100110 }
@@ -123,7 +133,6 @@ class TimerService : Service() {
123133 return super .onStartCommand(intent, flags, startId)
124134 }
125135
126-
127136 private fun toggleTimer () {
128137 updateProgressSegments()
129138
@@ -164,20 +173,6 @@ class TimerService : Service() {
164173 if (iterations == 0 ) showTimerNotification(time.toInt())
165174
166175 if (time < 0 ) {
167- val powerManager = this @TimerService.getSystemService(POWER_SERVICE ) as PowerManager
168- wakeLock = powerManager.newWakeLock(
169- PowerManager .SCREEN_BRIGHT_WAKE_LOCK or
170- PowerManager .ACQUIRE_CAUSES_WAKEUP or
171- PowerManager .ON_AFTER_RELEASE ,
172- " PomodoroApp:AlarmWakeLock"
173- )
174- wakeLock?.acquire(2 * 60 * 1000L )
175- val intent = Intent (this @TimerService, MainActivity ::class .java).apply {
176- addFlags(Intent .FLAG_ACTIVITY_NEW_TASK or Intent .FLAG_ACTIVITY_SINGLE_TOP )
177- }
178- startActivity(intent)
179-
180-
181176 skipTimer()
182177 _timerState .update { currentState ->
183178 currentState.copy(timerRunning = false )
@@ -197,7 +192,10 @@ class TimerService : Service() {
197192 }
198193 }
199194
200- @SuppressLint(" MissingPermission" , " StringFormatInvalid" ) // We check for the permission when pressing the Play button in the UI
195+ @SuppressLint(
196+ " MissingPermission" ,
197+ " StringFormatInvalid"
198+ ) // We check for the permission when pressing the Play button in the UI
201199 fun showTimerNotification (
202200 remainingTime : Int , paused : Boolean = false, complete : Boolean = false
203201 ) {
@@ -372,6 +370,8 @@ class TimerService : Service() {
372370 fun startAlarm () {
373371 if (timerRepository.alarmEnabled) alarm?.start()
374372
373+ appContainer.activityTurnScreenOn(true )
374+
375375 if (timerRepository.vibrateEnabled) {
376376 if (! vibrator.hasVibrator()) {
377377 return
@@ -393,8 +393,7 @@ class TimerService : Service() {
393393 vibrator.cancel()
394394 }
395395
396- wakeLock?.release()
397- wakeLock = null
396+ appContainer.activityTurnScreenOn(false )
398397
399398 _timerState .update { currentState ->
400399 currentState.copy(alarmRinging = false )
0 commit comments