Mitigate the races during installation

When handling post-install during the installation process, some
tasks are posted to PackageHandler and be executed after notifying
the install observer (install initiator). The task includes force-
stopping the package. If the install observer starts the app right
after being notified, the ongoing force-stop will kill the process.
The race happens. To mitigate the potential race, We should defer
the notification until these tasks are done.

Bug: 165012101
Test: atest -p services/core/java/com/android/server/pm
Change-Id: Ia6b32f72f3d75b8a40c42e11d21f21c459db5299
Merged-In: Ia6b32f72f3d75b8a40c42e11d21f21c459db5299
(cherry picked from commit bad03aa3c9d2d1a5a875222936ccb9215d7ee137)
5 files changed