summaryrefslogtreecommitdiff
path: root/libs/androidfw/AssetManager2.cpp
diff options
context:
space:
mode:
authorAdam Lesinski <adamlesinski@google.com>2017-09-25 13:10:14 -0700
committerAdam Lesinski <adamlesinski@google.com>2017-09-25 18:24:41 -0700
commit03ebac8c68f9925592a172fcfd11d56f48cadaeb (patch)
tree65f977d44096c415c580614dd43a158d3b96aa23 /libs/androidfw/AssetManager2.cpp
parent6833a07a078af8eeb868aee269bbb1860c01f244 (diff)
A few fixes to AssetManager2 for compat
Theme copying should behave the way it did with the old AssetManager (copy only the framework attributes when copying from a Theme object from a different AssetManager). Cleanup the dependencies on libziparchive in ApkAssets. Test: make libandroidfw_tests Test: out/host/<platform>/nativetests64/libandroidfw_tests/libandroidfw_tests --testdata=frameworks/base/libs/androidfw/tests/data Change-Id: I973f7e6eb14ce311306e2ec66a623a4790c8d233
Diffstat (limited to 'libs/androidfw/AssetManager2.cpp')
-rw-r--r--libs/androidfw/AssetManager2.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/libs/androidfw/AssetManager2.cpp b/libs/androidfw/AssetManager2.cpp
index ab7e14de48fb..f1f2e2d1417e 100644
--- a/libs/androidfw/AssetManager2.cpp
+++ b/libs/androidfw/AssetManager2.cpp
@@ -902,26 +902,32 @@ bool Theme::SetTo(const Theme& o) {
return true;
}
- if (asset_manager_ != o.asset_manager_) {
- return false;
- }
-
type_spec_flags_ = o.type_spec_flags_;
+ const bool copy_only_system = asset_manager_ != o.asset_manager_;
+
for (size_t p = 0; p < packages_.size(); p++) {
const Package* package = o.packages_[p].get();
- if (package == nullptr) {
+ if (package == nullptr || (copy_only_system && p != 0x01)) {
+ // The other theme doesn't have this package, clear ours.
packages_[p].reset();
continue;
}
+ if (packages_[p] == nullptr) {
+ // The other theme has this package, but we don't. Make one.
+ packages_[p].reset(new Package());
+ }
+
for (size_t t = 0; t < package->types.size(); t++) {
const Type* type = package->types[t].get();
if (type == nullptr) {
+ // The other theme doesn't have this type, clear ours.
packages_[p]->types[t].reset();
continue;
}
+ // Create a new type and update it to theirs.
const size_t type_alloc_size = sizeof(Type) + (type->entry_capacity * sizeof(Entry));
void* copied_data = malloc(type_alloc_size);
memcpy(copied_data, type, type_alloc_size);