UsageStatsService: ignore removed users in persistPendingEventsLocked()
If a pre-created user is removed before it becomes a full user, the
ACTION_USER_REMOVED intent is never sent, so UsageStatsService is never
notified that the user's pending events should be discarded. It will
eventually try to persist the events. As the first step, it tries to
create /data/system_de/$userId/usagestats and the parent directory
/data/system_de/$userId if it doesn't already exist.
However, due to https://r.android.com/2078213 the SELinux policy no
longer allows system_server to create /data/system_de/$userId. The
failure to create this directory is causing UsageStatsService to throw
an IllegalStateException which crashes system_server.
(Before the sepolicy change, system_server could create
/data/system_de/$userId, so the crash wouldn't have happened. But
problems still might have occurred if the user ID was reused.)
The underlying user state tracking bug still needs to be fixed. For
now, just avoid crashing system_server unnecessarily, and avoid an
SELinux denial by using mkdir() instead of mkdirs().
Test: pm create-user --pre-create-only
pm remove-user 10
# Wait 20 minutes and check logcat.
Bug: 234059731
Change-Id: Ic5efc19cda6b820a2c07f77b4f316d501acb9e80
1 file changed