diff options
author | Adam Lesinski <adamlesinski@google.com> | 2015-05-14 14:25:36 -0700 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2015-05-15 15:10:58 -0700 |
commit | 2738c96d998dedfae5b4670d588d0cd299c4ca0f (patch) | |
tree | 76b8571676d42a9c0b3bfa00f1937eebf2c05698 /libs/androidfw | |
parent | 038959e851603500eb39b52fef33cbe75dbd73e3 (diff) | |
download | frameworks_base-2738c96d998dedfae5b4670d588d0cd299c4ca0f.zip frameworks_base-2738c96d998dedfae5b4670d588d0cd299c4ca0f.tar.gz frameworks_base-2738c96d998dedfae5b4670d588d0cd299c4ca0f.tar.bz2 |
Add -round and -notround qualifier to android runtime/aapt
The round qualifier denotes a device with a screen shape that
is round. The qualifier shows up after the 'long/notlong' qualifier
and before the orientation 'port/land/square' qualifiers.
Change-Id: I3044258b2703a9165694b79725bade770fa6cea1
Diffstat (limited to 'libs/androidfw')
-rw-r--r-- | libs/androidfw/ResourceTypes.cpp | 43 | ||||
-rw-r--r-- | libs/androidfw/tests/Config_test.cpp | 78 |
2 files changed, 121 insertions, 0 deletions
diff --git a/libs/androidfw/ResourceTypes.cpp b/libs/androidfw/ResourceTypes.cpp index 2ae7b08..a95db9f 100644 --- a/libs/androidfw/ResourceTypes.cpp +++ b/libs/androidfw/ResourceTypes.cpp @@ -1894,6 +1894,8 @@ int ResTable_config::compare(const ResTable_config& o) const { if (diff != 0) return diff; diff = (int32_t)(screenLayout - o.screenLayout); if (diff != 0) return diff; + diff = (int32_t)(screenLayout2 - o.screenLayout2); + if (diff != 0) return diff; diff = (int32_t)(uiMode - o.uiMode); if (diff != 0) return diff; diff = (int32_t)(smallestScreenWidthDp - o.smallestScreenWidthDp); @@ -1951,6 +1953,9 @@ int ResTable_config::compareLogical(const ResTable_config& o) const { if (screenLayout != o.screenLayout) { return screenLayout < o.screenLayout ? -1 : 1; } + if (screenLayout2 != o.screenLayout2) { + return screenLayout2 < o.screenLayout2 ? -1 : 1; + } if (uiMode != o.uiMode) { return uiMode < o.uiMode ? -1 : 1; } @@ -1975,6 +1980,7 @@ int ResTable_config::diff(const ResTable_config& o) const { if (version != o.version) diffs |= CONFIG_VERSION; if ((screenLayout & MASK_LAYOUTDIR) != (o.screenLayout & MASK_LAYOUTDIR)) diffs |= CONFIG_LAYOUTDIR; if ((screenLayout & ~MASK_LAYOUTDIR) != (o.screenLayout & ~MASK_LAYOUTDIR)) diffs |= CONFIG_SCREEN_LAYOUT; + if ((screenLayout2 & MASK_SCREENROUND) != (o.screenLayout2 & MASK_SCREENROUND)) diffs |= CONFIG_SCREEN_ROUND; if (uiMode != o.uiMode) diffs |= CONFIG_UI_MODE; if (smallestScreenWidthDp != o.smallestScreenWidthDp) diffs |= CONFIG_SMALLEST_SCREEN_SIZE; if (screenSizeDp != o.screenSizeDp) diffs |= CONFIG_SCREEN_SIZE; @@ -2080,6 +2086,13 @@ bool ResTable_config::isMoreSpecificThan(const ResTable_config& o) const { } } + if (screenLayout2 || o.screenLayout2) { + if (((screenLayout2^o.screenLayout2) & MASK_SCREENROUND) != 0) { + if (!(screenLayout2 & MASK_SCREENROUND)) return false; + if (!(o.screenLayout2 & MASK_SCREENROUND)) return true; + } + } + if (orientation != o.orientation) { if (!orientation) return false; if (!o.orientation) return true; @@ -2267,6 +2280,13 @@ bool ResTable_config::isBetterThan(const ResTable_config& o, } } + if (screenLayout2 || o.screenLayout2) { + if (((screenLayout2^o.screenLayout2) & MASK_SCREENROUND) != 0 && + (requested->screenLayout2 & MASK_SCREENROUND)) { + return screenLayout2 & MASK_SCREENROUND; + } + } + if ((orientation != o.orientation) && requested->orientation) { return (orientation); } @@ -2480,6 +2500,15 @@ bool ResTable_config::match(const ResTable_config& settings) const { return false; } } + + if (screenConfig2 != 0) { + const int screenRound = screenLayout2 & MASK_SCREENROUND; + const int setScreenRound = settings.screenLayout2 & MASK_SCREENROUND; + if (screenRound != 0 && screenRound != setScreenRound) { + return false; + } + } + if (screenSizeDp != 0) { if (screenWidthDp != 0 && screenWidthDp > settings.screenWidthDp) { if (kDebugTableSuperNoisy) { @@ -2770,6 +2799,20 @@ String8 ResTable_config::toString() const { break; } } + if ((screenLayout2&MASK_SCREENROUND) != 0) { + if (res.size() > 0) res.append("-"); + switch (screenLayout2&MASK_SCREENROUND) { + case SCREENROUND_NO: + res.append("notround"); + break; + case SCREENROUND_YES: + res.append("round"); + break; + default: + res.appendFormat("screenRound=%d", dtohs(screenLayout2&MASK_SCREENROUND)); + break; + } + } if (orientation != ORIENTATION_ANY) { if (res.size() > 0) res.append("-"); switch (orientation) { diff --git a/libs/androidfw/tests/Config_test.cpp b/libs/androidfw/tests/Config_test.cpp index ef30df4..738947a 100644 --- a/libs/androidfw/tests/Config_test.cpp +++ b/libs/androidfw/tests/Config_test.cpp @@ -100,4 +100,82 @@ TEST(ConfigTest, shouldSelectBestDensityWhenNoneSpecified) { ASSERT_EQ(expectedBest, selectBest(deviceConfig, configs)); } +TEST(ConfigTest, shouldMatchRoundQualifier) { + ResTable_config deviceConfig; + memset(&deviceConfig, 0, sizeof(deviceConfig)); + + ResTable_config roundConfig; + memset(&roundConfig, 0, sizeof(roundConfig)); + roundConfig.screenLayout2 = ResTable_config::SCREENROUND_YES; + + EXPECT_FALSE(roundConfig.match(deviceConfig)); + + deviceConfig.screenLayout2 = ResTable_config::SCREENROUND_YES; + + EXPECT_TRUE(roundConfig.match(deviceConfig)); + + deviceConfig.screenLayout2 = ResTable_config::SCREENROUND_NO; + + EXPECT_FALSE(roundConfig.match(deviceConfig)); + + ResTable_config notRoundConfig; + memset(¬RoundConfig, 0, sizeof(notRoundConfig)); + notRoundConfig.screenLayout2 = ResTable_config::SCREENROUND_NO; + + EXPECT_TRUE(notRoundConfig.match(deviceConfig)); +} + +TEST(ConfigTest, RoundQualifierShouldHaveStableSortOrder) { + ResTable_config defaultConfig; + memset(&defaultConfig, 0, sizeof(defaultConfig)); + + ResTable_config longConfig = defaultConfig; + longConfig.screenLayout = ResTable_config::SCREENLONG_YES; + + ResTable_config longRoundConfig = longConfig; + longRoundConfig.screenLayout2 = ResTable_config::SCREENROUND_YES; + + ResTable_config longRoundPortConfig = longConfig; + longRoundPortConfig.orientation = ResTable_config::ORIENTATION_PORT; + + EXPECT_TRUE(longConfig.compare(longRoundConfig) < 0); + EXPECT_TRUE(longConfig.compareLogical(longRoundConfig) < 0); + EXPECT_TRUE(longRoundConfig.compare(longConfig) > 0); + EXPECT_TRUE(longRoundConfig.compareLogical(longConfig) > 0); + + EXPECT_TRUE(longRoundConfig.compare(longRoundPortConfig) < 0); + EXPECT_TRUE(longRoundConfig.compareLogical(longRoundPortConfig) < 0); + EXPECT_TRUE(longRoundPortConfig.compare(longRoundConfig) > 0); + EXPECT_TRUE(longRoundPortConfig.compareLogical(longRoundConfig) > 0); +} + +TEST(ConfigTest, ScreenShapeHasCorrectDiff) { + ResTable_config defaultConfig; + memset(&defaultConfig, 0, sizeof(defaultConfig)); + + ResTable_config roundConfig = defaultConfig; + roundConfig.screenLayout2 = ResTable_config::SCREENROUND_YES; + + EXPECT_EQ(defaultConfig.diff(roundConfig), ResTable_config::CONFIG_SCREEN_ROUND); +} + +TEST(ConfigTest, RoundIsMoreSpecific) { + ResTable_config deviceConfig; + memset(&deviceConfig, 0, sizeof(deviceConfig)); + deviceConfig.screenLayout2 = ResTable_config::SCREENROUND_YES; + deviceConfig.screenLayout = ResTable_config::SCREENLONG_YES; + + ResTable_config targetConfigA; + memset(&targetConfigA, 0, sizeof(targetConfigA)); + + ResTable_config targetConfigB = targetConfigA; + targetConfigB.screenLayout = ResTable_config::SCREENLONG_YES; + + ResTable_config targetConfigC = targetConfigB; + targetConfigC.screenLayout2 = ResTable_config::SCREENROUND_YES; + + EXPECT_TRUE(targetConfigB.isBetterThan(targetConfigA, &deviceConfig)); + EXPECT_TRUE(targetConfigC.isBetterThan(targetConfigB, &deviceConfig)); +} + } // namespace android. |