[AppsFilter] fix cache lock and rebuild cache if needed

Combining ag/18367541 and ag/18284940 and individual locks.

BUG: 231528435
BUG: 228712570
Fixes: 231528435
Test: atest android.appenumeration.cts.AppEnumerationTests
Test: atest com.android.tests.stagedinstall.host.StagedInstallTest#testInstallStagedApexAndApk
Change-Id: I35b0deeb6db4329cbd89bd56390c4b8b56a977c4
5 files changed