diff options
author | 2021-11-05 22:44:59 +0000 | |
---|---|---|
committer | 2021-11-09 22:00:17 +0000 | |
commit | 3a619c86ee8498873aa42b13580205753063e72b (patch) | |
tree | 87859b0dc20d24d947dccd4fad69c086f01f249c | |
parent | b778bc5ad9381e2f0982b1942083305da1c513b8 (diff) |
Always select the next higher density bucket when picking resources
This reverts commit 30715f3afc061bd25a5f251554efc56c412d02d5.
Reason for revert: roll forward with fix
Change-Id: I6d63e6fa508501f2d029eeb4647d4d70c152ceb3
Test: ran all previously failing tests locally
Fixes: 183136881
-rw-r--r-- | libs/androidfw/ResourceTypes.cpp | 23 | ||||
-rw-r--r-- | libs/androidfw/tests/Config_test.cpp | 3 |
2 files changed, 13 insertions, 13 deletions
diff --git a/libs/androidfw/ResourceTypes.cpp b/libs/androidfw/ResourceTypes.cpp index cae2d0bc16b3..5e8a623d4205 100644 --- a/libs/androidfw/ResourceTypes.cpp +++ b/libs/androidfw/ResourceTypes.cpp @@ -2677,30 +2677,27 @@ bool ResTable_config::isBetterThan(const ResTable_config& o, // DENSITY_ANY is now dealt with. We should look to // pick a density bucket and potentially scale it. // Any density is potentially useful - // because the system will scale it. Scaling down - // is generally better than scaling up. + // because the system will scale it. Always prefer + // scaling down. int h = thisDensity; int l = otherDensity; bool bImBigger = true; if (l > h) { - int t = h; - h = l; - l = t; + std::swap(l, h); bImBigger = false; } - if (requestedDensity >= h) { - // requested value higher than both l and h, give h + if (h == requestedDensity) { + // This handles the case where l == h == requestedDensity. + // In that case, this and o are equally good so both + // true and false are valid. This preserves previous + // behavior. return bImBigger; - } - if (l >= requestedDensity) { + } else if (l >= requestedDensity) { // requested value lower than both l and h, give l return !bImBigger; - } - // saying that scaling down is 2x better than up - if (((2 * l) - requestedDensity) * h > requestedDensity * requestedDensity) { - return !bImBigger; } else { + // otherwise give h return bImBigger; } } diff --git a/libs/androidfw/tests/Config_test.cpp b/libs/androidfw/tests/Config_test.cpp index b54915f03c29..698c36f09301 100644 --- a/libs/androidfw/tests/Config_test.cpp +++ b/libs/androidfw/tests/Config_test.cpp @@ -75,6 +75,9 @@ TEST(ConfigTest, shouldSelectBestDensity) { configs.add(buildDensityConfig(int(ResTable_config::DENSITY_HIGH) + 20)); ASSERT_EQ(expectedBest, selectBest(deviceConfig, configs)); + configs.add(buildDensityConfig(int(ResTable_config::DENSITY_XHIGH) - 1)); + ASSERT_EQ(expectedBest, selectBest(deviceConfig, configs)); + expectedBest = buildDensityConfig(ResTable_config::DENSITY_XHIGH); configs.add(expectedBest); ASSERT_EQ(expectedBest, selectBest(deviceConfig, configs)); |