Make notification destinations explicit in an analyzer-visible form while retaining immutable PendingIntent flags, resolving the high-severity CodeQL finding.
Two memory optimizations:
1. ImageDecoder FILL path: use setCrop() to crop to canvas during decode
instead of allocating the full fill-scale bitmap first. For a portrait
2000x3000 image on a 4032x2992 parallax canvas, this avoids a ~97MB
intermediate (4032x6048) — the output is directly 4032x2992 (~48MB).
2. BOTH mode: recycle the HOME bitmap before rendering the LOCK bitmap,
so they are never in memory simultaneously. Removes the fallback that
reused the HOME bitmap for LOCK (which kept it alive during LOCK
rendering). If LOCK rendering fails, the lock screen retains its
previous wallpaper rather than getting the oversized HOME bitmap.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
In BOTH mode, the same HOME-sized bitmap (wide parallax canvas, e.g.
4032x2992) was reused for the lock screen via setBitmap(FLAG_LOCK).
The lock screen has no parallax, so Android center-cropped the wide
bitmap — defeating FIT/NONE modes which should letterbox, not crop.
Fix: after setting HOME, sync the LOCK queue, then re-render the same
wallpaper via reapplyEffectsUseCase(ScreenType.LOCK) at the physical
screen dimensions. Falls back to the old behavior if re-render fails.
Applied to both WallpaperChangeService and WallpaperChangeWorker.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
retrieveBitmap previously returned bitmaps sized to the image content (e.g.
1994x2992 for FIT on a portrait image), leaving the launcher to scale/position
them — which silently broke the chosen scaling mode:
FIT → narrower than canvas → launcher scaled up → cropped height again
FILL → taller than canvas → launcher behaviour undefined / distorted
NONE → smaller than canvas → launcher stretched it
New finalizeToCanvas() step ensures every path returns a bitmap of exactly
canvasW×canvasH pixels:
FILL → center-crop the fill-scaled source to canvas size;
upscale first when BitmapFactory fallback returns a small source
FIT → center the fit-scaled source on a black canvas (letterbox/pillarbox)
NONE → center the original-size source on a black canvas
STRETCH → source was decoded to exact canvas dimensions; no-op
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Wallpapers were rendered at physical screen size (e.g. 1344x2992) then passed
to WallpaperManager.setBitmap() with a null visibleCropHint. The Pixel Launcher
(and others) declare a desired minimum width ~3x the screen width for horizontal
parallax across home-screen pages. Android scales the bitmap up to fill that
canvas, which proportionally enlarges the height and crops the top/bottom --
making FIT indistinguishable from FILL and always cutting off portrait subjects.
Fix: introduce getWallpaperRenderSize() which uses WallpaperManager
.getDesiredMinimumWidth/Height for HOME/BOTH screen types. The bitmap is now
rendered to fill the full parallax canvas upfront, so Android has nothing to
scale and the user's chosen scaling mode is preserved. LOCK screen is unchanged
(no parallax, physical screen size is correct).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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>
pendingSettings was stored in WallpaperScreen's remember{} scope — navigating
away (e.g. to AlbumView) cancelled the LaunchedEffect and silently discarded
in-flight slider/interval changes. Moved the debounce Job to viewModelScope so
pending updates survive composition changes.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
DataStore's edit lambda can be retried when a concurrent write conflict
is detected. wasCleared was captured from the outer scope and never reset
between retries, so a true from a failed first attempt could leak into the
final return value even if the condition no longer held on the retry.
Added wasCleared = false at the top of the lambda so each attempt starts
from a clean state.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
If Bitmap.createBitmap() or loadTexture() threw (e.g. OutOfMemoryError)
while building the GLPicture tiles Array, any textures already uploaded
to the GPU in previous iterations were abandoned because the tiles field
was never assigned and recycle() could not be called. Switched from the
Array{} lambda (which only exposes partial state through the exception)
to an explicit loop that tracks created tiles in a List, and added a
catch-rethrow that deletes all partial textures before propagating.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
If onStartCommand received a null intent (possible when START_STICKY
restarts a killed service) or an unrecognized action, the service would
start foreground (showing a persistent notification) but never call
stopSelf(), leaving it running indefinitely. Added an else branch to
call stopSelf(startId) immediately in these cases.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ChangeWallpaperUseCase and ReapplyEffectsUseCase both leaked the
processedBitmap when processBitmap() or adaptiveBrightnessAdjustment()
threw an exception — the outer catch returned Result.Error without
recycling the allocated bitmap. Added an inner try-catch-rethrow that
recycles whichever bitmap is live at the point of failure before
re-throwing so the outer handler can record the skip.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- QueueBuilder: convert List.contains to HashSet lookups in mergeWithExistingQueue
and mergeWithExistingQueueDeterministic (O(n²) → O(n))
- AlbumRefreshWorker: load existing folder URIs once per folder with
getExistingWallpaperUris() instead of one DB query per scanned wallpaper (N+1 → 1)
- WallpaperEntity: remove unused cropOffsetX/Y/Scale columns (always null, never read)
- DATABASE_VERSION bumped to 4; fallbackToDestructiveMigration handles upgrade
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Local `val wallpapers` shadowed the `StateFlow<List<Wallpaper>> wallpapers`
class property, making it hard to tell which was being referenced.
Renamed to `newWallpapers` for clarity.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- PaperizeLiveWallpaperService: stop permanently deleting wallpapers when
URI is transiently inaccessible; now skips the cycle like ChangeWallpaperUseCase does.
AlbumRefreshWorker handles authoritative URI pruning on its daily run.
- WallpaperEffects/PreferencesManager/WallpaperScreen: rename enableChangeOnScreenOn
→ enableChangeOnScreenOff to match actual trigger (ACTION_SCREEN_OFF).
DataStore key string is unchanged so existing user prefs are preserved.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This position-based delete was superseded by deleteQueueItem (which
deletes by wallpaperId) and has zero call sites. Removing it
eliminates confusion about which dequeue strategy is active.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
WallpaperChangeService already guards against the case where home and
lock albums diverge in BOTH mode. WallpaperChangeWorker was using
homeAlbumId unconditionally, silently applying the wrong album to the
lock screen during transient state transitions. Add the same guard
and fall back to independent per-screen changes when albums differ.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
fastRoundToInt() can round the inSampleSize ratio UP, causing the
decoded bitmap to be smaller than the target screen dimensions and
requiring upscaling. Integer division always floors, guaranteeing
the decoded bitmap is at least as large as needed.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
WallpaperChangeService and WallpaperChangeWorker each had their own
private companion-object Mutex, so simultaneous runs (manual change +
scheduled worker) were not mutually excluded. Extract a @Singleton
WallpaperChangeLock and inject it into both so the same Mutex is used
across all wallpaper-change entry points.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When user changes which screens are enabled (homeEnabled/lockEnabled),
clear all album selections to ensure clean state:
**Scenarios where albums are cleared:**
- Lock only → Both screens enabled
- Home only → Both screens enabled
- Both screens → Lock only
- Both screens → Home only
- Lock only → Home only (both toggles change)
**Why this is needed:**
- Album requirements change when switching between single/dual screen modes
- Both screens enabled requires TWO albums selected
- Single screen requires ONE album selected
- Clearing prevents invalid state where old selections don't match new requirements
**Implementation:**
- Detect when homeEnabled or lockEnabled changes in updateScheduleSettings()
- If screen toggles changed, clear both homeAlbumId and lockAlbumId
- Apply validation to cleared settings
- Auto-toggle logic will disable changer (no albums selected)
- User must select appropriate albums for new screen configuration
**User flow:**
1. User toggles screen on/off
2. Albums automatically cleared
3. Changer disabled (no albums)
4. User selects new albums
5. Changer re-enabled with correct albums
This ensures users always have the correct album setup for their
chosen screen configuration.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Prevent redundant WorkManager job rescheduling when app starts:
**Problem:**
- Every time app starts, wallpaper change workers were being rescheduled
- Same with album refresh worker
- This caused unnecessary database writes and WorkManager operations
- Even when jobs were already correctly scheduled
**Solution:**
Added `onlyIfNotScheduled` parameter throughout the scheduling chain:
1. **WallpaperScheduler:**
- Added `isWorkScheduled()` and `isAlbumRefreshScheduled()` helpers
- Check WorkInfo state (ENQUEUED or RUNNING) before scheduling
- Skip scheduling if work already exists and `onlyIfNotScheduled = true`
2. **HomeViewModel:**
- Added `onlyIfNotScheduled` parameter to `toggleWallpaperChanger()`
- Added `onlyIfNotScheduled` parameter to `scheduleAlarms()`
- Skip immediate wallpaper change when checking if scheduled
- Propagate parameter through scheduling chain
3. **BootReceiver:**
- Use `onlyIfNotScheduled = true` on device boot
- Prevents rescheduling if jobs survived device restart
4. **HomeScreen:**
- Auto-toggle uses `onlyIfNotScheduled = true`
- Prevents rescheduling on every app startup
- User actions still always reschedule (parameter defaults to false)
**Behavior:**
- App startup: Only schedule if not already scheduled
- Device boot: Only schedule if not already scheduled
- User actions (album selection, settings changes): Always reschedule
- Album refresh: Only schedule if not already scheduled
This improves app startup performance and reduces unnecessary
WorkManager operations while maintaining correct scheduling behavior.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Improve robustness of wallpaper queue management:
**Problem:**
When the queue runs out DURING the validation loop (all remaining
wallpapers are invalid), the code returned an error without trying
to rebuild the queue. This could happen when:
- Album has both valid and invalid wallpapers
- Queue contains only invalid wallpapers after valid ones are used
- Validation loop dequeues all invalid wallpapers
- Queue becomes empty but is never rebuilt
**Solution:**
When getAndDequeueWallpaper returns null during validation loop:
1. Try rebuilding the queue (up to 2 attempts)
2. Continue validation loop to get wallpaper from rebuilt queue
3. Only return "no wallpapers" error after 2 rebuild attempts fail
**Edge Cases Handled:**
- Queue runs out due to invalid wallpapers being removed: rebuild and retry
- Album truly has no valid wallpapers: error after 2 rebuild attempts
- Shuffle mode: queue rebuilt with correct shuffle order
- Sequential mode: queue rebuilt with correct display order
This ensures the wallpaper changer continues working even when
encountering invalid wallpapers, and properly cycles through the
album whether shuffle is enabled or not.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
When wallpaper effects are toggled on and individual scheduling is off,
hide the description text for a cleaner UI:
- Grayscale effect
- Adaptive brightness
- Shuffle
Changes:
- Make SettingSwitch description parameter nullable
- Conditionally hide description when:
- Effect is enabled (checked = true)
- AND individual scheduling is OFF (separateSchedules = false)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Multiple fixes for scheduling logic and UI behavior:
**Scheduling Fixes:**
- Add required albums validation before scheduling WorkManager jobs
- Only schedule when all required albums are selected based on enabled screens
- Prevent scheduling with incomplete album selection (both screens enabled requires both albums)
- Add hasRequiredAlbums check in HomeViewModel, WallpaperScreen, and BootReceiver
**Race Condition Fixes:**
- Fix toggleWallpaperChanger race condition with atomic updateEnableChanger()
- Prevent phantom album selections by using atomic DataStore updates
- Fix startup race condition - only cleanup stale album IDs after albums load
**Display Settings:**
- Separate scheduling changes from display changes (ScheduleSettings.kt)
- Add hasSchedulingChanges() - intervals, screen enable/disable, separate schedules
- Add hasDisplayChanges() - scaling, effects, adaptive brightness
- Reapply wallpaper immediately when display settings change (no reschedule needed)
- Prevent unnecessary WorkManager rescheduling for display-only changes
**Effect Sliders:**
- Fix effect sliders to respect separateSchedules setting
- Show synchronized slider when individual scheduling OFF
- Show separate sliders when individual scheduling ON
- Applies to brightness/darken, blur, and vignette sliders
**AlbumRefreshWorker:**
- Fix duplicate detection to check both direct and folder wallpapers
- Fix failure counting (increment failedCount on addWallpaper errors)
- Prevent false error logs and database constraint violations
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>