Clean up ownership transfer metadata on user removal

A malicious profile owner can exploit a TOCTOU race condition during transferOwnership() to leave a stale, device-global metadata file pointing to their own profile. By subsequently wiping its own profile, the attacker causes an unguarded boot-time revert attempt that throws an uncaught exception, leading to a permanent system_server crash loop (persistent DoS).

This commit addresses the vulnerability by ensuring the ownership transfer metadata file is deleted when the associated user is removed. In `DevicePolicyManagerService#removeUserData()`, the system now checks if the metadata file exists and matches the ID of the user being removed. If so, the file is deleted, tying the journal's lifetime to the user and preventing the boot-time crash loop.

Test: m services && atest FrameworksServicesTests:com.android.server.devicepolicy.DevicePolicyManagerTest

Bug: 515039372
Flag: EXEMPT BUGFIX
This was autogenerated by MendIt (go/androidmendit)
Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:611b45aa58842575af3ffd0c34472e5456062900
Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:cfc2067289c2889a3ee337ed9c795c25d3e64988
Merged-In: I6323b1cbbf068d0939fd1d7f98662326482b5824
Change-Id: I6323b1cbbf068d0939fd1d7f98662326482b5824
1 file changed