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
Change-Id: Ia45d0c9236474841d0ba63b5265b3b835cf9f6f5
2 files changed