fix: scheduleWallpaperChanges fire-and-forget in BootReceiver
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
456fea3c17
commit
5efb272dcb
2 files changed
+3
-10
No files matched your search
@@ -446,7 +446,7 @@ class HomeViewModel @Inject constructor(
|
|||||||
context.startForegroundService(intent)
|
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
|
// Check if we're in LIVE mode
|
||||||
if (wallpaperMode.value == com.anthonyla.paperize.core.WallpaperMode.LIVE) {
|
if (wallpaperMode.value == com.anthonyla.paperize.core.WallpaperMode.LIVE) {
|
||||||
// LIVE mode: schedule live wallpaper changes
|
// LIVE mode: schedule live wallpaper changes
|
||||||
|
|||||||
@@ -12,10 +12,6 @@ import kotlinx.coroutines.flow.first
|
|||||||
import com.anthonyla.paperize.core.ScreenType
|
import com.anthonyla.paperize.core.ScreenType
|
||||||
import com.anthonyla.paperize.core.constants.Constants
|
import com.anthonyla.paperize.core.constants.Constants
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
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.Mutex
|
||||||
import kotlinx.coroutines.sync.withLock
|
import kotlinx.coroutines.sync.withLock
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
@@ -38,7 +34,6 @@ class WallpaperScheduler @Inject constructor(
|
|||||||
@param:ApplicationContext private val context: Context
|
@param:ApplicationContext private val context: Context
|
||||||
) {
|
) {
|
||||||
private val workManager = WorkManager.getInstance(context)
|
private val workManager = WorkManager.getInstance(context)
|
||||||
private val schedulerScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
|
|
||||||
private val mutex = Mutex()
|
private val mutex = Mutex()
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -107,7 +102,7 @@ class WallpaperScheduler @Inject constructor(
|
|||||||
* @param requireCharging Whether device must be charging
|
* @param requireCharging Whether device must be charging
|
||||||
* @param onlyIfNotScheduled If true, only schedule if work is not already scheduled (for app startup)
|
* @param onlyIfNotScheduled If true, only schedule if work is not already scheduled (for app startup)
|
||||||
*/
|
*/
|
||||||
fun scheduleWallpaperChanges(
|
suspend fun scheduleWallpaperChanges(
|
||||||
homeIntervalMinutes: Int,
|
homeIntervalMinutes: Int,
|
||||||
lockIntervalMinutes: Int,
|
lockIntervalMinutes: Int,
|
||||||
synchronized: Boolean = false,
|
synchronized: Boolean = false,
|
||||||
@@ -115,8 +110,7 @@ class WallpaperScheduler @Inject constructor(
|
|||||||
requireCharging: Boolean = false,
|
requireCharging: Boolean = false,
|
||||||
onlyIfNotScheduled: Boolean = false
|
onlyIfNotScheduled: Boolean = false
|
||||||
) {
|
) {
|
||||||
schedulerScope.launch {
|
mutex.withLock {
|
||||||
mutex.withLock {
|
|
||||||
// Don't cancel all first - let UPDATE policy handle existing work
|
// Don't cancel all first - let UPDATE policy handle existing work
|
||||||
// This prevents immediate wallpaper change when just updating intervals
|
// This prevents immediate wallpaper change when just updating intervals
|
||||||
|
|
||||||
@@ -193,7 +187,6 @@ class WallpaperScheduler @Inject constructor(
|
|||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Skipped scheduling album refresh - already scheduled")
|
Log.d(TAG, "Skipped scheduling album refresh - already scheduled")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user