summaryrefslogtreecommitdiff
path: root/tools/aapt2/ResourceTable.cpp
diff options
context:
space:
mode:
authorShane Farmer <safarmer@google.com>2017-06-22 12:24:12 -0700
committerShane Farmer <safarmer@google.com>2017-08-16 19:19:54 +0000
commit0a5b201156f1dd01a7da7b7674798ed57cfafc5a (patch)
treec2682b213bb6f5c3bc390631dbc7e71ea6f527e2 /tools/aapt2/ResourceTable.cpp
parent8dbbdf0c370c56426ffde06ccdbe55d2ffb9fb8d (diff)
AAPT2: Add a APK filtering.
Allow resource files to be removed from the final artifact based on the density and locale configuration in the config file. The APK is split along the density, locale and ABI axis. Each split is generated from the original APK without modifying the original. The new resource table is written back to the file system with unneeded assets etc removed. Test: Unit tests Test: Manually run optimize command against an APK and inspect results Test: Installed split searchlite APK (after resigning) and ran on N6 Change-Id: If73597dcfd88c02d2616518585d0e25a5c6a84d1
Diffstat (limited to 'tools/aapt2/ResourceTable.cpp')
-rw-r--r--tools/aapt2/ResourceTable.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/tools/aapt2/ResourceTable.cpp b/tools/aapt2/ResourceTable.cpp
index ab59560d33a3..0304e21698df 100644
--- a/tools/aapt2/ResourceTable.cpp
+++ b/tools/aapt2/ResourceTable.cpp
@@ -546,4 +546,34 @@ Maybe<ResourceTable::SearchResult> ResourceTable::FindResource(const ResourceNam
return SearchResult{package, type, entry};
}
+std::unique_ptr<ResourceTable> ResourceTable::Clone() const {
+ std::unique_ptr<ResourceTable> new_table = util::make_unique<ResourceTable>();
+ for (const auto& pkg : packages) {
+ ResourceTablePackage* new_pkg = new_table->CreatePackage(pkg->name, pkg->id);
+ for (const auto& type : pkg->types) {
+ ResourceTableType* new_type = new_pkg->FindOrCreateType(type->type);
+ if (!new_type->id) {
+ new_type->id = type->id;
+ new_type->symbol_status = type->symbol_status;
+ }
+
+ for (const auto& entry : type->entries) {
+ ResourceEntry* new_entry = new_type->FindOrCreateEntry(entry->name);
+ if (!new_entry->id) {
+ new_entry->id = entry->id;
+ new_entry->symbol_status = entry->symbol_status;
+ }
+
+ for (const auto& config_value : entry->values) {
+ ResourceConfigValue* new_value =
+ new_entry->FindOrCreateValue(config_value->config, config_value->product);
+ Value* value = config_value->value->Clone(&new_table->string_pool);
+ new_value->value = std::unique_ptr<Value>(value);
+ }
+ }
+ }
+ }
+ return new_table;
+}
+
} // namespace aapt