AppCleaner: Make deleted item count match the scanned count#2480
Merged
Conversation
The scan card counts every expendable file it finds (sum of AppJunk.itemCount), but the post-deletion card showed affectedPaths.size. Caches cleared via the accessibility-service "Clear cache" tap contribute only their <=2 synthetic theoreticalPaths to affectedPaths, so a scan of e.g. 4876 found items could report as ~80 deleted — same work, two incompatible counting scales. Derive affectedCount from the pre/post-deletion scan totals (snapshot.totalCount - internalData.totalCount) so it counts ACS cache clears at scan scale instead of by recordable paths. affectedPaths is unchanged, so stats path records are unaffected; the lifetime items-processed stat now stops undercounting ACS deletions. Propagate affectedCount through the OneClick and Scheduler success wrappers too. Adds AppCleanerTest coverage for the ACS-cleared count, failed-clear (no overcount), includeInaccessible=false, and OneClick/Scheduler propagation.
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 changed
After cleaning with AppCleaner, the result could show far fewer "items deleted" than the scan reported as "found" — e.g. a scan finding 4876 items / 2.5 GB would show 80 items deleted / 2.6 GB freed. The freed space was correct and nothing was skipped, but the item counts looked wildly inconsistent and read like a bug.
The number now reflects the same thing the scan counted, so the "found" and "deleted" counts line up.
Technical Context
sum of AppJunk.itemCount), but the post-deletion result reportedaffectedPaths.size. On non-root devices, caches are cleared by the accessibility service tapping "Clear cache" per app — that whole-folder clear contributes only its ≤2 synthetictheoreticalPathstoaffectedPaths, so hundreds of scanned files collapse to ~1–2 counted paths. Two incompatible counting scales, not data loss.affectedCountfrom the before/after scan totals (snapshot.totalCount - internalData.totalCount) instead ofaffectedPaths.size. This reuses the exact counting the scan already does, so it can't drift from the "found" rules, and it counts ACS cache clears at scan scale. Chosen over a hand-rolled per-item counter (which would have to re-derive the accessible/inaccessible/public-cache rules and risk double-counting).affectedPathsis left unchanged, so the stats path-record subsystem is unaffected. Side effect: the lifetime "items processed" stat stops undercounting ACS deletions, and the stats detail header now shows the true item count above the (inherently shorter) recordable-path list — accepted, since inaccessible cache files have no enumerable paths.affectedCountthrough the OneClick and Scheduler success wrappers so background/one-tap runs report consistently too.toolLock;coerceAtLeast(0)guards the (not-expected) negative case. Tests cover the ACS-cleared count, a failed clear (no overcount),includeInaccessible=false, and OneClick/Scheduler propagation.