Add hibernation NPE check and unhibernate only if hibernating

Rather than depend strictly on "leaving" force-stop (i.e. stopped to not
stopped), we unhibernate when setting stopped to false and the app is
hibernating. This prevents situations where an app is not stopped but
hibernating and can never exit hibernation because the app never
"leaves" force-stop.

With this, we can add the NPE check without risk of putting the app into
a permanent hibernation state.

Bug: 205774141
Test: atest AppHibernationIntegrationTest
Test: atest PackageManagerServiceHibernationTests
Merged-In: Ia45d0c9236474841d0ba63b5265b3b835cf9f6f5
Change-Id: Ia45d0c9236474841d0ba63b5265b3b835cf9f6f5
(cherry picked from commit 2e8b4013072f30ee96f77cd691a52a98240c1b71)
2 files changed