Skip to content

CorpseFinder: Avoid false leftovers for data owned by installed apps#2472

Draft
d4rken wants to merge 1 commit into
mainfrom
worktree-corpse-uid-ownership
Draft

CorpseFinder: Avoid false leftovers for data owned by installed apps#2472
d4rken wants to merge 1 commit into
mainfrom
worktree-corpse-uid-ownership

Conversation

@d4rken

@d4rken d4rken commented Jun 17, 2026

Copy link
Copy Markdown
Member

What changed

CorpseFinder is now less likely to falsely flag leftover data on rooted devices. When a private-data folder is named after an app that isn't installed, but the folder is still actively owned and used by an app that is installed (for example after a system app is renamed and keeps writing to its old data folder), CorpseFinder now recognizes the real owner and stops reporting it as uninstall residue.

This is the general fix behind the earlier Samsung "Intelligent Wi-Fi" report (com.samsung.android.wifi.intelligence data kept alive by com.samsung.android.wifi.ai) — instead of needing a hand-written rule per case.

Technical Context

  • Until now PrivateDataCSI decided ownership purely from the directory name. If the name didn't match an installed package (and no clutter rule applied), the folder was reported as a corpse — even when a live, differently-named package owns the data.
  • New behaviour: when no installed owner is found by name or clutter rule, the folder's POSIX owner uid is resolved to the currently-installed package(s) holding it:
    • exactly one live package → attributed as the owner (not a corpse)
    • a shared system uid (e.g. 1000) mapping to many packages → reported as a known-but-unidentified owner (hasKnownUnknownOwner), so it's not a corpse without flooding installedOwners
    • nothing installed → still a corpse via the existing dirname fallback (genuine residue is unaffected)
  • getPkgsForUid resolves a uid against the in-memory PkgRepo cache only (no extra PackageManager/IPC calls); it decomposes uid = userId * 100000 + appId and matches live NormalPkg entries, so stale archived/uninstalled cache entries can't mask a real corpse.
  • A single-path lookupExtended was added to the APath gateway interface (LocalGateway/SAFGateway/GatewaySwitch); the root/ADB IPC side (lookUpExtended) already existed and is now wired through the client.
  • Cost is bounded: the extra stat only runs for corpse-suspect directories (no installed owner found), which are top-level dirs. Private-data scanning is already root-only, so the uid is authoritative. Lookup failures and cancellation fall through safely (cancellation is re-thrown, not swallowed).
  • The curated wifi.ai clutter marker from CorpseFinder: Fix false leftover for Samsung Intelligent Wi-Fi #2471 is kept as belt-and-suspenders.

Refs #2469

@d4rken d4rken added enhancement New feature, request, improvement or optimization c: CorpseFinder c: IO SAF/Normal/Root access Root c: CSI File ownership detection c: PKGS Package related operations. labels Jun 17, 2026
@d4rken d4rken marked this pull request as draft June 17, 2026 13:39
@d4rken d4rken force-pushed the worktree-corpse-uid-ownership branch from 533b579 to 58c5e34 Compare June 22, 2026 16:20
PrivateDataCSI previously decided ownership purely by directory name, so a
data_ce directory named after an uninstalled package was reported as a corpse
even when a live, differently-named package still owns and maintains it (e.g.
the Samsung Intelligent Wi-Fi rename wifi.intelligence -> wifi.ai).

When no installed owner is found by name or clutter, the directory's POSIX
owner uid is now resolved to the currently-installed package(s) that hold it:
- exactly one live package -> attributed as the owner (not a corpse)
- a shared system uid (e.g. 1000) mapping to many -> reported as a known
  unknown owner (not a corpse, without flooding installedOwners)
- nothing installed -> still a corpse via the existing dirname fallback

Adds a single-path lookupExtended to the APath gateway stack (the AIDL/host
side already existed) and PkgRepo.getPkgsForUid, which resolves a uid to live
NormalPkg entries from the in-memory cache (uid = userId * 100000 + appId).
@d4rken d4rken force-pushed the worktree-corpse-uid-ownership branch from 58c5e34 to ec77e72 Compare June 22, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: CorpseFinder c: CSI File ownership detection c: IO SAF/Normal/Root access c: PKGS Package related operations. enhancement New feature, request, improvement or optimization Root

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant