summaryrefslogtreecommitdiff
path: root/tools/aapt2/optimize/MultiApkGenerator.cpp
diff options
context:
space:
mode:
authorShane Farmer <safarmer@google.com>2017-09-25 14:19:03 -0700
committerShane Farmer <safarmer@google.com>2017-10-03 16:14:07 +0000
commite17993597e149ddaf27e9b9604c9f10a9d1a16a9 (patch)
tree16c6f2a2341a4855900ecdaeea8aac96a98b25e3 /tools/aapt2/optimize/MultiApkGenerator.cpp
parent810fd184356a76fc0fa35d07212df10b7e058063 (diff)
AAPT2: Set compatible-screens in manifest for multi-APK
If an artifact in a multi-apk set is for a scpecific set of screen densities then update the manifest to set the compatible-screens element to match. Test: ran unit tests Test: manually ran optimize command Change-Id: I07e90850ab2f4647a8623acbeaccbebbe81c3a6a
Diffstat (limited to 'tools/aapt2/optimize/MultiApkGenerator.cpp')
-rw-r--r--tools/aapt2/optimize/MultiApkGenerator.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/tools/aapt2/optimize/MultiApkGenerator.cpp b/tools/aapt2/optimize/MultiApkGenerator.cpp
index fb150e204167..8e4b82c6c261 100644
--- a/tools/aapt2/optimize/MultiApkGenerator.cpp
+++ b/tools/aapt2/optimize/MultiApkGenerator.cpp
@@ -324,7 +324,30 @@ bool MultiApkGenerator::UpdateManifest(const Artifact& artifact,
}
}
- // TODO(safarmer): Check if we changed the supported screens and update the manifest.
+ if (artifact.screen_density_group) {
+ auto densities = config.screen_density_groups.find(artifact.screen_density_group.value());
+ CHECK(densities != config.screen_density_groups.end()) << "Missing density group";
+
+ xml::Element* screens_el = manifest_el->FindChild({}, "compatible-screens");
+ if (!screens_el) {
+ // create a new element.
+ std::unique_ptr<xml::Element> new_screens_el = util::make_unique<xml::Element>();
+ new_screens_el->name = "compatible-screens";
+ screens_el = new_screens_el.get();
+ manifest_el->InsertChild(0, std::move(new_screens_el));
+ } else {
+ // clear out the old element.
+ screens_el->GetChildElements().clear();
+ }
+
+ for (const auto& density : densities->second) {
+ std::unique_ptr<xml::Element> screen_el = util::make_unique<xml::Element>();
+ screen_el->name = "screen";
+ const char* density_str = density.toString().string();
+ screen_el->attributes.push_back(xml::Attribute{kSchemaAndroid, "screenDensity", density_str});
+ screens_el->AppendChild(std::move(screen_el));
+ }
+ }
return true;
}