Loading core/jni/android_util_AssetManager.cpp +14 −6 Original line number Diff line number Diff line Loading @@ -1127,20 +1127,28 @@ static jintArray NativeAttributeResolutionStack(JNIEnv* env, jclass /*clazz*/, j } auto style_stack = assetmanager->GetBagResIdStack(xml_style_res); if (!style_stack.ok()) { jniThrowIOException(env, EBADMSG); return nullptr; } auto def_style_stack = assetmanager->GetBagResIdStack(def_style_resid); if (!def_style_stack.ok()) { jniThrowIOException(env, EBADMSG); return nullptr; } jintArray array = env->NewIntArray(style_stack.size() + def_style_stack.size()); jintArray array = env->NewIntArray(style_stack.value()->size() + def_style_stack.value()->size()); if (env->ExceptionCheck()) { return nullptr; } for (uint32_t i = 0; i < style_stack.size(); i++) { jint attr_resid = style_stack[i]; for (uint32_t i = 0; i < style_stack.value()->size(); i++) { jint attr_resid = (*style_stack.value())[i]; env->SetIntArrayRegion(array, i, 1, &attr_resid); } for (uint32_t i = 0; i < def_style_stack.size(); i++) { jint attr_resid = def_style_stack[i]; env->SetIntArrayRegion(array, style_stack.size() + i, 1, &attr_resid); for (uint32_t i = 0; i < def_style_stack.value()->size(); i++) { jint attr_resid = (*def_style_stack.value())[i]; env->SetIntArrayRegion(array, style_stack.value()->size() + i, 1, &attr_resid); } return array; } Loading libs/androidfw/AssetManager2.cpp +11 −10 Original line number Diff line number Diff line Loading @@ -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( Loading @@ -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; } Loading libs/androidfw/include/androidfw/AssetManager2.h +10 −4 Original line number Diff line number Diff line Loading @@ -243,9 +243,14 @@ class AssetManager2 { friend AssetManager2; friend Theme; SelectedValue() = default; SelectedValue(const ResolvedBag* bag, const ResolvedBag::Entry& entry) : cookie(entry.cookie), data(entry.value.data), type(entry.value.dataType), flags(bag->type_spec_flags), resid(0U), config({}) {}; SelectedValue(const ResolvedBag* bag, const ResolvedBag::Entry& entry) : cookie(entry.cookie), data(entry.value.data), type(entry.value.dataType), flags(bag->type_spec_flags), resid(0U), config() { } // The cookie representing the ApkAssets in which the value resides. ApkAssetsCookie cookie = kInvalidCookie; Loading Loading @@ -327,7 +332,8 @@ class AssetManager2 { // resource data failed. base::expected<uint32_t, NullOrIOError> GetResourceTypeSpecFlags(uint32_t resid) const; const std::vector<uint32_t> GetBagResIdStack(uint32_t resid) const; base::expected<const std::vector<uint32_t>*, NullOrIOError> GetBagResIdStack( uint32_t resid) const; // Resets the resource resolution structures in preparation for the next resource retrieval. void ResetResourceResolution() const; Loading Loading
core/jni/android_util_AssetManager.cpp +14 −6 Original line number Diff line number Diff line Loading @@ -1127,20 +1127,28 @@ static jintArray NativeAttributeResolutionStack(JNIEnv* env, jclass /*clazz*/, j } auto style_stack = assetmanager->GetBagResIdStack(xml_style_res); if (!style_stack.ok()) { jniThrowIOException(env, EBADMSG); return nullptr; } auto def_style_stack = assetmanager->GetBagResIdStack(def_style_resid); if (!def_style_stack.ok()) { jniThrowIOException(env, EBADMSG); return nullptr; } jintArray array = env->NewIntArray(style_stack.size() + def_style_stack.size()); jintArray array = env->NewIntArray(style_stack.value()->size() + def_style_stack.value()->size()); if (env->ExceptionCheck()) { return nullptr; } for (uint32_t i = 0; i < style_stack.size(); i++) { jint attr_resid = style_stack[i]; for (uint32_t i = 0; i < style_stack.value()->size(); i++) { jint attr_resid = (*style_stack.value())[i]; env->SetIntArrayRegion(array, i, 1, &attr_resid); } for (uint32_t i = 0; i < def_style_stack.size(); i++) { jint attr_resid = def_style_stack[i]; env->SetIntArrayRegion(array, style_stack.size() + i, 1, &attr_resid); for (uint32_t i = 0; i < def_style_stack.value()->size(); i++) { jint attr_resid = (*def_style_stack.value())[i]; env->SetIntArrayRegion(array, style_stack.value()->size() + i, 1, &attr_resid); } return array; } Loading
libs/androidfw/AssetManager2.cpp +11 −10 Original line number Diff line number Diff line Loading @@ -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( Loading @@ -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; } Loading
libs/androidfw/include/androidfw/AssetManager2.h +10 −4 Original line number Diff line number Diff line Loading @@ -243,9 +243,14 @@ class AssetManager2 { friend AssetManager2; friend Theme; SelectedValue() = default; SelectedValue(const ResolvedBag* bag, const ResolvedBag::Entry& entry) : cookie(entry.cookie), data(entry.value.data), type(entry.value.dataType), flags(bag->type_spec_flags), resid(0U), config({}) {}; SelectedValue(const ResolvedBag* bag, const ResolvedBag::Entry& entry) : cookie(entry.cookie), data(entry.value.data), type(entry.value.dataType), flags(bag->type_spec_flags), resid(0U), config() { } // The cookie representing the ApkAssets in which the value resides. ApkAssetsCookie cookie = kInvalidCookie; Loading Loading @@ -327,7 +332,8 @@ class AssetManager2 { // resource data failed. base::expected<uint32_t, NullOrIOError> GetResourceTypeSpecFlags(uint32_t resid) const; const std::vector<uint32_t> GetBagResIdStack(uint32_t resid) const; base::expected<const std::vector<uint32_t>*, NullOrIOError> GetBagResIdStack( uint32_t resid) const; // Resets the resource resolution structures in preparation for the next resource retrieval. void ResetResourceResolution() const; Loading