From 5efb272dcb3f678e04d8eebdea645abbabf1c535 Mon Sep 17 00:00:00 2001 From: Anthonyy232 Date: Sat, 28 Mar 2026 14:43:21 -0700 Subject: [PATCH] fix: scheduleWallpaperChanges fire-and-forget in BootReceiver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit scheduleWallpaperChanges internally launched on schedulerScope and returned immediately, so BootReceiver called pendingResult.finish() before WorkManager enqueued the jobs — the process could be recycled before the scheduling ran. Converted to a suspend function so callers await completion. Co-Authored-By: Claude Sonnet 4.6 --- .../presentation/screens/home/HomeViewModel.kt | 2 +- .../paperize/service/worker/WallpaperScheduler.kt | 11 ++--------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/anthonyla/paperize/presentation/screens/home/HomeViewModel.kt b/app/src/main/java/com/anthonyla/paperize/presentation/screens/home/HomeViewModel.kt index 11e52eb..ea281ff 100644 --- a/app/src/main/java/com/anthonyla/paperize/presentation/screens/home/HomeViewModel.kt +++ b/app/src/main/java/com/anthonyla/paperize/presentation/screens/home/HomeViewModel.kt @@ -446,7 +446,7 @@ class HomeViewModel @Inject constructor( context.startForegroundService(intent) } - private fun scheduleAlarms(settings: ScheduleSettings, onlyIfNotScheduled: Boolean = false) { + private suspend fun scheduleAlarms(settings: ScheduleSettings, onlyIfNotScheduled: Boolean = false) { // Check if we're in LIVE mode if (wallpaperMode.value == com.anthonyla.paperize.core.WallpaperMode.LIVE) { // LIVE mode: schedule live wallpaper changes diff --git a/app/src/main/java/com/anthonyla/paperize/service/worker/WallpaperScheduler.kt b/app/src/main/java/com/anthonyla/paperize/service/worker/WallpaperScheduler.kt index 436a5f9..c9baa1a 100644 --- a/app/src/main/java/com/anthonyla/paperize/service/worker/WallpaperScheduler.kt +++ b/app/src/main/java/com/anthonyla/paperize/service/worker/WallpaperScheduler.kt @@ -12,10 +12,6 @@ import kotlinx.coroutines.flow.first import com.anthonyla.paperize.core.ScreenType import com.anthonyla.paperize.core.constants.Constants import dagger.hilt.android.qualifiers.ApplicationContext -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.SupervisorJob -import kotlinx.coroutines.launch import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import java.util.Calendar @@ -38,7 +34,6 @@ class WallpaperScheduler @Inject constructor( @param:ApplicationContext private val context: Context ) { private val workManager = WorkManager.getInstance(context) - private val schedulerScope = CoroutineScope(SupervisorJob() + Dispatchers.Default) private val mutex = Mutex() companion object { @@ -107,7 +102,7 @@ class WallpaperScheduler @Inject constructor( * @param requireCharging Whether device must be charging * @param onlyIfNotScheduled If true, only schedule if work is not already scheduled (for app startup) */ - fun scheduleWallpaperChanges( + suspend fun scheduleWallpaperChanges( homeIntervalMinutes: Int, lockIntervalMinutes: Int, synchronized: Boolean = false, @@ -115,8 +110,7 @@ class WallpaperScheduler @Inject constructor( requireCharging: Boolean = false, onlyIfNotScheduled: Boolean = false ) { - schedulerScope.launch { - mutex.withLock { + mutex.withLock { // Don't cancel all first - let UPDATE policy handle existing work // This prevents immediate wallpaper change when just updating intervals @@ -193,7 +187,6 @@ class WallpaperScheduler @Inject constructor( } else { Log.d(TAG, "Skipped scheduling album refresh - already scheduled") } - } } }