[res] Fix the bag resolution stack
Two different cache containers are tightly linked together, and
clearing only one of them breaks the expected link.
Test: build + atest android.view.cts.ViewAttributeTest
Bug: 282267185
Change-Id: I713aec60c02d559d8435e2f4a640718b21b1b45b
diff --git a/libs/androidfw/AssetManager2.cpp b/libs/androidfw/AssetManager2.cpp
index 4d43471..dcbaaec 100644
--- a/libs/androidfw/AssetManager2.cpp
+++ b/libs/androidfw/AssetManager2.cpp
@@ -1122,9 +1122,7 @@
base::expected<const ResolvedBag*, NullOrIOError> AssetManager2::GetBag(uint32_t resid) const {
auto resid_stacks_it = cached_bag_resid_stacks_.find(resid);
- if (resid_stacks_it != cached_bag_resid_stacks_.end()) {
- resid_stacks_it->second.clear();
- } else {
+ if (resid_stacks_it == cached_bag_resid_stacks_.end()) {
resid_stacks_it = cached_bag_resid_stacks_.emplace(resid, std::vector<uint32_t>{}).first;
}
const auto bag = GetBag(resid, resid_stacks_it->second);