CleanForge deletes files. The design goal is that it can never delete something you did not see, understand and confirm.
SCAN -> CLASSIFY -> VALIDATE -> PLAN -> USER CONFIRMATION -> REVALIDATE -> DELETE -> VERIFY -> REPORT
| Step | Where | What it guarantees |
|---|---|---|
| SCAN / CLASSIFY | core/scanner/* |
A finding is a proposal with evidence, never a command. |
| VALIDATE / PLAN | SafetyValidator, PlanBuilder |
Path policy, mode policy, overlap rules, and the duplicate rule: the copy that stays is one the user did NOT tick; a group whose every copy is ticked is refused. Refused items are kept with their reason. |
| USER CONFIRMATION | ConfirmDialog |
Lists EVERY item with its full path, why it was flagged, confidence, risk, exactly what is deleted, “no undo”, Shizuku need, and for duplicates KEEP / DELETE CANDIDATE; refusals too. CleaningEngine accepts only a ConfirmedPlan. |
| REVALIDATE | CleaningEngine.processItem |
Policy again, live permissions, fresh package-state check (app cache: package currently installed; leftover: package not known and not installed), scan-time fingerprint, kept-copy check. |
| DELETE | SafeDeleter (app or Shizuku service) |
No symlink following, no mount crossing, bounded depth/entries, directory identity re-checked, and every entry re-lstated and identity-compared immediately before it is removed. |
| VERIFY / REPORT | CleaningEngine, ReportDialog |
Re-stat after deletion; freed bytes come from what was really removed. |
/storage/emulated/0 is accepted. Aliases (/sdcard, /storage/self/primary) are refused..., ., empty segments, trailing slash, NUL/control characters, or over 4096 chars are refused.Android/data/<pkg>/cache (contents), Android/{data,obb}/<pkg> (uninstalled app, TREE), DCIM/.thumbnails (contents).Android/data, Android/obb, Android/media and every top-level storage folder can never be deleted.Runtime.exec, ProcessBuilder or Shizuku.newProcess appear.FileServiceCore, which also refuses any path whose ancestors below the storage root are not real directories (a symlink in the middle of a path is not followed), refuses a tree delete for any package in the installed-apps guard (any letter case) or for CleanForge itself, and refuses every tree delete until the app has pushed that guard./, .., spaces, control characters or shell metacharacters have no target.Unavailable/Denied/Failed, not “not found” and not “empty”; a failed package-manager query is UNKNOWN, not “not installed”.MIN_PLAUSIBLE_PACKAGES is only a fail-closed guard, not proof the query worked), leftover and cache findings are not produced and deletion is skipped.knownPackageNames() = “Android still has an identity for this name” (includes apps uninstalled with their data kept); isCurrentlyInstalled() = “installed right now”. An app cache is only ever offered, and only ever deleted, for a package that is currently installed. A data-kept uninstalled package is neither an app cache nor a leftover: it is left alone. Both checks cover the current Android user/profile only; other users and work profiles are not enumerated.Forensic scanners target known app-specific cache/media patterns. They are strictly narrower than a general walk:
FORENSIC_MEDIA, isQuick = false (on-demand only), requiresShizuku = true, isPreselected = false, DeleteMode.FILE only.SafetyValidator.isKnownForensicPath(). No wildcard Android/data or Android/media access.Android/media/<pkg>/WhatsApp/Media/.Statuses/*, .../Sent/*, .../Databases/msgstore-*, Android/media/<pkg>/Telegram/Telegram {Video,Audio,Images,Documents}/*, and Android/data/<pkg>/cache/* for TikTok / Twitter-X / Instagram.ProtectedApps.MESSAGING) are never pre-selected and get an extra caution layer./proc/meminfo (world-readable, no permission needed). Nothing is estimated or faked; if the file can’t be read the UI shows “unknown”, never zero.ActivityManager.killBackgroundProcesses and requires the KILL_BACKGROUND_PROCESSES permission.MemAvailable delta before/after and clamped to ≥ 0. If memory did not actually increase, the app reports 0 freed — it never invents a number.UNKNOWN (failed query) are never killed (fail-closed).PolicyGuardTest.MANAGE_EXTERNAL_STORAGE (list and delete what you select), QUERY_ALL_PACKAGES (know which apps are installed for the current user/profile), and KILL_BACKGROUND_PROCESSES (honest RAM clear, Part 4).allowBackup=false.Shizuku is not root. By default its user service runs as the shell user and it executes no commands: the service has a fixed set of file operations and no shell. If you start it in root mode, CleanForge shows that and applies exactly the same path rules. It is optional: without it, only the Android/data cleaners are disabled.
unlinkat/openat to Kotlin, so a process with write access to the same folder could swap an entry between our last lstat and remove. Mitigations: identity (type, device, inode) of each folder is re-checked before its entries are removed, and of every single entry again immediately before its own remove (a swapped entry is left untouched and reported), remove never recurses, and symlinks are unlinked as links only, so a swap can never make deletion follow a link. The two calls are still separate, so the window is narrowed, not closed. Shared storage does not allow apps to create symlinks, which makes this hard to exploit. Covered by SafeDeleterTest.killBackgroundProcesses only trims processes Android already considers reclaimable; it cannot free memory held by foreground or persistent apps, and Android may reload the apps afterwards.BUILD.md. Treat every statement in this file as a design claim until CI has run the tests.Report privately to the maintainer, Aman. Add a contact address or issue-tracker link here before publishing: <contact: TODO by Aman>.