Make configs differing only in density siblings

Configurations differing only in density value will match the same
device configuration at runtime; therefore, they should be considered
sibling configurations in the dominator tree.

So, given configurations A and B:
1) If A has a density defined and B does not, A must never dominate B.
2) If A and B both have densities defined, neither must dominate the
   other.

Previous behavior:
<default>
  sw600dp-v13
    sw600dp-hdpi-v13
       sw800dp-hdpi-v13
    sw800dp-xxhdpi-v13

New behavior:
<default>
  sw600dp-v13
    sw600dp-hdpi-v13
      sw800dp-hdpi-v13
      sw800dp-xxhdpi-v13

Bug: 167944889
Test: aapt2_tests
Change-Id: Ie9fba4c4b74af2b3bbf8fc6432539a99f8647634
This commit is contained in:
Ryan Mitchell
2020-09-14 13:11:22 -07:00
parent 3141524bb9
commit 7b7085cc54
2 changed files with 28 additions and 3 deletions

View File

@@ -177,9 +177,8 @@ inline ConfigDescription& ConfigDescription::operator=(ConfigDescription&& o) no
return *this;
}
inline bool ConfigDescription::MatchWithDensity(
const ConfigDescription& o) const {
return match(o) && (density == 0 || density == o.density);
inline bool ConfigDescription::MatchWithDensity(const ConfigDescription& o) const {
return match(o) && (density == 0 || o.density != 0);
}
inline bool ConfigDescription::operator<(const ConfigDescription& o) const {

View File

@@ -173,4 +173,30 @@ TEST(DominatorTreeTest, LocalesAreNeverDominated) {
EXPECT_EQ(expected, printer.ToString(&tree));
}
TEST(DominatorTreeTest, NonZeroDensitiesMatch) {
const ConfigDescription sw600_config = test::ParseConfigOrDie("sw600dp");
const ConfigDescription sw600_hdpi_config = test::ParseConfigOrDie("sw600dp-hdpi");
const ConfigDescription sw800_hdpi_config = test::ParseConfigOrDie("sw800dp-hdpi");
const ConfigDescription sw800_xxhdpi_config = test::ParseConfigOrDie("sw800dp-xxhdpi");
std::vector<std::unique_ptr<ResourceConfigValue>> configs;
configs.push_back(util::make_unique<ResourceConfigValue>(ConfigDescription::DefaultConfig(), ""));
configs.push_back(util::make_unique<ResourceConfigValue>(sw600_config, ""));
configs.push_back(util::make_unique<ResourceConfigValue>(sw600_hdpi_config, ""));
configs.push_back(util::make_unique<ResourceConfigValue>(sw800_hdpi_config, ""));
configs.push_back(util::make_unique<ResourceConfigValue>(sw800_xxhdpi_config, ""));
DominatorTree tree(configs);
PrettyPrinter printer;
std::string expected =
"<default>\n"
" sw600dp-v13\n"
" sw600dp-hdpi-v13\n"
" sw800dp-hdpi-v13\n"
" sw800dp-xxhdpi-v13\n";
EXPECT_EQ(expected, printer.ToString(&tree));
}
} // namespace aapt