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
Merged-In: Ie9fba4c4b74af2b3bbf8fc6432539a99f8647634
Change-Id: Ie9fba4c4b74af2b3bbf8fc6432539a99f8647634
diff --git a/tools/aapt2/DominatorTree_test.cpp b/tools/aapt2/DominatorTree_test.cpp
index fe4f951..3e49034 100644
--- a/tools/aapt2/DominatorTree_test.cpp
+++ b/tools/aapt2/DominatorTree_test.cpp
@@ -173,4 +173,30 @@
   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