summaryrefslogtreecommitdiff
path: root/libs/androidfw/AssetManager2.cpp
diff options
context:
space:
mode:
author Yurii Zubrytskyi <zyy@google.com> 2023-05-10 13:22:55 -0700
committer Yurii Zubrytskyi <zyy@google.com> 2023-05-10 13:22:55 -0700
commit02a555f39bc7a4c489b6a2f7bff34c8bdc2e1bf9 (patch)
treed8174a714e6df273240810086c8c6f75d0c73561 /libs/androidfw/AssetManager2.cpp
parentbdcbf5583bfeaa7963c379b75aee9b4cba9cb897 (diff)
IO error reporting in the last AssetManager func
GetBagResIdStack() used to report no errors Bug: n/a Test: UTs Change-Id: I73c88715dff5ed9f621bcaea1910b05818e1d608
Diffstat (limited to 'libs/androidfw/AssetManager2.cpp')
-rw-r--r--libs/androidfw/AssetManager2.cpp21
1 files changed, 11 insertions, 10 deletions
diff --git a/libs/androidfw/AssetManager2.cpp b/libs/androidfw/AssetManager2.cpp
index fd5d07f22419..769e3268191b 100644
--- a/libs/androidfw/AssetManager2.cpp
+++ b/libs/androidfw/AssetManager2.cpp
@@ -1092,16 +1092,17 @@ base::expected<std::monostate, NullOrIOError> AssetManager2::ResolveReference(
}
}
-const std::vector<uint32_t> AssetManager2::GetBagResIdStack(uint32_t resid) const {
- auto cached_iter = cached_bag_resid_stacks_.find(resid);
- if (cached_iter != cached_bag_resid_stacks_.end()) {
- return cached_iter->second;
+base::expected<const std::vector<uint32_t>*, NullOrIOError> AssetManager2::GetBagResIdStack(
+ uint32_t resid) const {
+ 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()) {
+ cached_bag_resid_stacks_.erase(it);
+ return base::unexpected(maybe_bag.error());
+ }
}
-
- std::vector<uint32_t> found_resids;
- GetBag(resid, found_resids);
- cached_bag_resid_stacks_.emplace(resid, found_resids);
- return found_resids;
+ return &it->second;
}
base::expected<const ResolvedBag*, NullOrIOError> AssetManager2::ResolveBag(
@@ -1120,7 +1121,7 @@ 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_.emplace(resid, std::move(found_resids));
+ cached_bag_resid_stacks_.try_emplace(resid, std::move(found_resids));
return bag;
}