diff options
author | 2023-05-23 18:32:47 -0700 | |
---|---|---|
committer | 2023-05-23 18:32:47 -0700 | |
commit | bd1db5d3c28793d35b34db3dc4906163dd41fbda (patch) | |
tree | 69ce7781e27768b0e5b55c66f64927c652882e42 /libs/androidfw/AssetManager2.cpp | |
parent | 24fc837933176cf0086fa2bb74a9752f51fc7097 (diff) |
Only fail GetBag if there was an IO Error
AssetManager2::GetBag* functions may return "no value" for
the missing resources, that's not an error and shouldn't
result in java exceptions
+ fix the perf regression from extra level of indirection
Bug: 282264161
Test: libandroidfw_tests + boot
Change-Id: Iea32b248b1ca9f6a366b44a14866da16d6b2ef6b
Diffstat (limited to 'libs/androidfw/AssetManager2.cpp')
-rw-r--r-- | libs/androidfw/AssetManager2.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/libs/androidfw/AssetManager2.cpp b/libs/androidfw/AssetManager2.cpp index 61282a042370..e3f0c8fcf3bf 100644 --- a/libs/androidfw/AssetManager2.cpp +++ b/libs/androidfw/AssetManager2.cpp @@ -1097,7 +1097,7 @@ base::expected<const std::vector<uint32_t>*, NullOrIOError> AssetManager2::GetBa auto [it, inserted] = cached_bag_resid_stacks_.try_emplace(resid); if (inserted) { // This is a new entry in the cache, need to populate it. - if (auto maybe_bag = GetBag(resid, it->second); !maybe_bag.ok()) { + if (auto maybe_bag = GetBag(resid, it->second); UNLIKELY(IsIOError(maybe_bag))) { cached_bag_resid_stacks_.erase(it); return base::unexpected(maybe_bag.error()); } @@ -1119,9 +1119,13 @@ base::expected<const ResolvedBag*, NullOrIOError> AssetManager2::ResolveBag( } base::expected<const ResolvedBag*, NullOrIOError> AssetManager2::GetBag(uint32_t resid) const { - std::vector<uint32_t> found_resids; - const auto bag = GetBag(resid, found_resids); - cached_bag_resid_stacks_.try_emplace(resid, std::move(found_resids)); + auto [resid_stacks_it, _] = cached_bag_resid_stacks_.try_emplace(resid); + resid_stacks_it->second.clear(); + const auto bag = GetBag(resid, resid_stacks_it->second); + if (UNLIKELY(IsIOError(bag))) { + cached_bag_resid_stacks_.erase(resid_stacks_it); + return base::unexpected(bag.error()); + } return bag; } |