diff --git a/libs/androidfw/include/androidfw/ConfigDescription.h b/libs/androidfw/include/androidfw/ConfigDescription.h index acf413aeaf912c042390445045704590b6d27f36..61d10cd4e55bc32097b26f2ee249e32f0fe657e8 100644 --- a/libs/androidfw/include/androidfw/ConfigDescription.h +++ b/libs/androidfw/include/androidfw/ConfigDescription.h @@ -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 { diff --git a/tools/aapt2/DominatorTree_test.cpp b/tools/aapt2/DominatorTree_test.cpp index fe4f951a5cd0dc77307dec1476d0ff56c718daec..3e49034310c3ee52d84e5fe116c056838042c3af 100644 --- a/tools/aapt2/DominatorTree_test.cpp +++ b/tools/aapt2/DominatorTree_test.cpp @@ -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