Optional auto-cleanup of recordings older than N days (engine only)#148
Open
dsremo wants to merge 1 commit into
Open
Optional auto-cleanup of recordings older than N days (engine only)#148dsremo wants to merge 1 commit into
dsremo wants to merge 1 commit into
Conversation
Adds an opt-in retention engine that deletes recording files older than a user-set number of days. Disabled by default (max_age_days = 0); no behavior change for existing users. How it works ------------ - New util/RecordingsRetention object exposes setMaxAgeDays/getMaxAgeDays and sweepIfDue(context, dir). - ARApplication.onCreate calls sweepIfDue() with the recording dir; the sweep no-ops when max_age_days is 0 or when last_run < 24h ago. - Storage: a single SharedPreferences file (recordings_retention) holds max_age_days (int) and last_run (long). Independent of the app's main prefs — restoring main prefs from a backup won't unexpectedly arm this. What is NOT in this PR ---------------------- A Settings UI to expose max_age_days. I'm intentionally keeping this PR to the engine — the UX (a number field in SettingsActivity? a duration picker?) is a maintainer choice. Until a UI lands the feature is dormant (the engine is already wired in ARApplication). If you'd prefer me to add a Settings row in this same PR, happy to. Safety ------ - 24h throttle prevents repeat scans on rapid app re-launches. - File deletion is wrapped in runCatching — a stuck file doesn't break sweep on remaining files. - Only files with lastModified < cutoff are deleted; never the directory itself, never subfolders. 35 LOC of Kotlin + 5-line hook in ARApplication.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this is
An opt-in retention engine that deletes recording files older than a user-set number of days. Disabled by default (
max_age_days = 0); zero behavior change for existing users.How it works
util/RecordingsRetentionobject exposes:setMaxAgeDays(context, days)— set the thresholdgetMaxAgeDays(context)— read itsweepIfDue(context, recordingDir)— delete files older than the threshold, throttled to one run per 24hARApplication.onCreatecallssweepIfDue()with the active recording directory. Whenmax_age_days = 0it short-circuits, so the patch is dormant unless the user opts in.recordings_retention) holdsmax_age_days(Int) andlast_run(Long). Kept separate from the app's main prefs so restoring main prefs from a backup doesn't unexpectedly arm this feature.What is not in this PR
A Settings UI to expose
max_age_days. I'm intentionally keeping this PR to the engine — the UX call (a number field inSettingsActivity? A duration picker? A dropdown with presets like 30/90/365 days?) is a maintainer choice. Until a UI lands the feature is dormant (the engine is already wired inARApplication.onCreate).If you'd prefer me to bundle a Settings row in this same PR, happy to extend. I left it out because:
Safety properties
max_age_days = 0is the initial value; no sweep ever runs unless the user explicitly sets a non-zero value.last_runtimestamp prevents repeat scans on rapid app re-launches or process restarts.runCatchingper file — a single file that can't be deleted (FS busy, permission edge-case) doesn't abort sweep on the remaining files.file.isFile && file.lastModified() < cutoffare deleted. Never the directory itself, never subfolders.Files
app/src/main/java/com/dimowner/audiorecorder/util/RecordingsRetention.kt(new, 57 lines)app/src/main/java/com/dimowner/audiorecorder/ARApplication.kt(+5 lines — the call site)Tested
max_age_days = 0(default): launching the app shows no log output for the sweep path, no files touched. ✓max_age_days = 30set viaRecordingsRetention.setMaxAgeDays(ctx, 30): launching the app deletes files older than 30 days from the recording dir, leaves newer ones alone. ✓Why this exists
A long-running user accumulates a lot of voice notes over months; many become irrelevant after a few weeks. Manual cleanup is friction. Other recorder apps in the same niche have offered this for years (Easy Voice Recorder, Smart Voice Recorder); it's a known-good UX. This PR brings the same primitive without forcing a UX choice on you.