diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 19ff772..84c8ae7 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -7,6 +7,7 @@
+
= Build.VERSION_CODES.S) {
val vibratorManager = getSystemService(VIBRATOR_MANAGER_SERVICE) as VibratorManager
@@ -89,6 +94,7 @@ class TimerService : Service() {
saveTimeToDb()
notificationManager.cancel(1)
alarm?.release()
+ wakeLock?.release()
}
super.onDestroy()
}
@@ -117,6 +123,7 @@ class TimerService : Service() {
return super.onStartCommand(intent, flags, startId)
}
+
private fun toggleTimer() {
updateProgressSegments()
@@ -157,6 +164,20 @@ class TimerService : Service() {
if (iterations == 0) showTimerNotification(time.toInt())
if (time < 0) {
+ val powerManager = this@TimerService.getSystemService(POWER_SERVICE) as PowerManager
+ wakeLock = powerManager.newWakeLock(
+ PowerManager.SCREEN_BRIGHT_WAKE_LOCK or
+ PowerManager.ACQUIRE_CAUSES_WAKEUP or
+ PowerManager.ON_AFTER_RELEASE,
+ "PomodoroApp:AlarmWakeLock"
+ )
+ wakeLock?.acquire(2 * 60 * 1000L)
+ val intent = Intent(this@TimerService, MainActivity::class.java).apply {
+ addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP)
+ }
+ startActivity(intent)
+
+
skipTimer()
_timerState.update { currentState ->
currentState.copy(timerRunning = false)
@@ -176,7 +197,7 @@ class TimerService : Service() {
}
}
- @SuppressLint("MissingPermission") // We check for the permission when pressing the Play button in the UI
+ @SuppressLint("MissingPermission", "StringFormatInvalid") // We check for the permission when pressing the Play button in the UI
fun showTimerNotification(
remainingTime: Int, paused: Boolean = false, complete: Boolean = false
) {
@@ -372,6 +393,9 @@ class TimerService : Service() {
vibrator.cancel()
}
+ wakeLock?.release()
+ wakeLock = null
+
_timerState.update { currentState ->
currentState.copy(alarmRinging = false)
}
diff --git a/app/src/main/java/org/nsh07/pomodoro/ui/timerScreen/AlarmDialog.kt b/app/src/main/java/org/nsh07/pomodoro/ui/timerScreen/AlarmDialog.kt
index 9b27779..ed39a73 100644
--- a/app/src/main/java/org/nsh07/pomodoro/ui/timerScreen/AlarmDialog.kt
+++ b/app/src/main/java/org/nsh07/pomodoro/ui/timerScreen/AlarmDialog.kt
@@ -7,6 +7,7 @@
package org.nsh07.pomodoro.ui.timerScreen
+import androidx.activity.compose.LocalActivity
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
@@ -24,6 +25,7 @@ import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
@@ -37,6 +39,21 @@ fun AlarmDialog(
modifier: Modifier = Modifier,
stopAlarm: () -> Unit
) {
+ val activity = LocalActivity.current
+
+ // Set lockscreen flags when dialog appears, remove when it disappears
+ DisposableEffect(Unit) {
+ // Show over lockscreen
+ activity?.setShowWhenLocked(true)
+ activity?.setTurnScreenOn(true)
+
+ onDispose {
+ // Remove lockscreen flags when dialog is dismissed
+ activity?.setShowWhenLocked(false)
+ activity?.setTurnScreenOn(false)
+ }
+ }
+
BasicAlertDialog(
onDismissRequest = stopAlarm,
modifier = modifier
@@ -75,4 +92,5 @@ fun AlarmDialog(
}
}
}
-}
\ No newline at end of file
+}
+