Fix the race between install and cleanup.

When installAndActivatePackage() and RemoveInactiveDataApex() mutate the
filesystem (/data/apex/activate) and MountedApexDatabase at the same
time, the apex being installed can be removed incorrectly.

This happens because RemoveInactiveDataApex() is called after "boot
completed" when PM thinks everything is up and running and okay to
invoke installAndActivatePackage().

In this change, RemoveInactiveDataApex() is moved to OnStart() (right
after activating APEXes). This should fix the issue because systemserver
won't start until apexd finishes OnStart() (and setting
apexd.status=activated).

Bug: 342840303
Test: atest ApexTestCases
Change-Id: I927e788a37f19107498485249bee12a049b55c73
2 files changed