From 6425497f4129a40e75569328525c0dcbaa6e3f22 Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Tue, 3 Nov 2015 16:16:17 -0800 Subject: [PATCH] AAPT2: Add round qualifer support Change-Id: Id5a1331198e01be7ca4d87b8833900e51f82ece5 --- tools/aapt2/ConfigDescription.cpp | 31 ++++++++++++++++++++++++++++++- tools/aapt2/ConfigDescription_test.cpp | 17 +++++++++++++++++ tools/aapt2/SdkConstants.h | 1 + 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/tools/aapt2/ConfigDescription.cpp b/tools/aapt2/ConfigDescription.cpp index 8120fa709b3c..64353deb204d 100644 --- a/tools/aapt2/ConfigDescription.cpp +++ b/tools/aapt2/ConfigDescription.cpp @@ -164,6 +164,26 @@ static bool parseScreenLayoutLong(const char* name, ResTable_config* out) { return false; } +static bool parseScreenRound(const char* name, ResTable_config* out) { + if (strcmp(name, kWildcardName) == 0) { + if (out) out->screenLayout2 = + (out->screenLayout2&~ResTable_config::MASK_SCREENROUND) + | ResTable_config::SCREENROUND_ANY; + return true; + } else if (strcmp(name, "round") == 0) { + if (out) out->screenLayout2 = + (out->screenLayout2&~ResTable_config::MASK_SCREENROUND) + | ResTable_config::SCREENROUND_YES; + return true; + } else if (strcmp(name, "notround") == 0) { + if (out) out->screenLayout2 = + (out->screenLayout2&~ResTable_config::MASK_SCREENROUND) + | ResTable_config::SCREENROUND_NO; + return true; + } + return false; +} + static bool parseOrientation(const char* name, ResTable_config* out) { if (strcmp(name, kWildcardName) == 0) { if (out) out->orientation = out->ORIENTATION_ANY; @@ -635,6 +655,13 @@ bool ConfigDescription::parse(const StringPiece& str, ConfigDescription* out) { } } + if (parseScreenRound(partIter->c_str(), &config)) { + ++partIter; + if (partIter == partsEnd) { + goto success; + } + } + if (parseOrientation(partIter->c_str(), &config)) { ++partIter; if (partIter == partsEnd) { @@ -725,7 +752,9 @@ success: void ConfigDescription::applyVersionForCompatibility(ConfigDescription* config) { uint16_t minSdk = 0; - if (config->density == ResTable_config::DENSITY_ANY) { + if (config->screenLayout2 & ResTable_config::MASK_SCREENROUND) { + minSdk = SDK_MARSHMALLOW; + } else if (config->density == ResTable_config::DENSITY_ANY) { minSdk = SDK_LOLLIPOP; } else if (config->smallestScreenWidthDp != ResTable_config::SCREENWIDTH_ANY || config->screenWidthDp != ResTable_config::SCREENWIDTH_ANY diff --git a/tools/aapt2/ConfigDescription_test.cpp b/tools/aapt2/ConfigDescription_test.cpp index 83708165a6d7..e68d6be536df 100644 --- a/tools/aapt2/ConfigDescription_test.cpp +++ b/tools/aapt2/ConfigDescription_test.cpp @@ -15,6 +15,8 @@ */ #include "ConfigDescription.h" +#include "SdkConstants.h" + #include "util/StringPiece.h" #include @@ -79,4 +81,19 @@ TEST(ConfigDescriptionTest, ParseCarAttribute) { EXPECT_EQ(android::ResTable_config::UI_MODE_TYPE_CAR, config.uiMode); } +TEST(ConfigDescriptionTest, TestParsingRoundQualifier) { + ConfigDescription config; + EXPECT_TRUE(TestParse("round", &config)); + EXPECT_EQ(android::ResTable_config::SCREENROUND_YES, + config.screenLayout2 & android::ResTable_config::MASK_SCREENROUND); + EXPECT_EQ(SDK_MARSHMALLOW, config.sdkVersion); + EXPECT_EQ(std::string("round-v23"), config.toString().string()); + + EXPECT_TRUE(TestParse("notround", &config)); + EXPECT_EQ(android::ResTable_config::SCREENROUND_NO, + config.screenLayout2 & android::ResTable_config::MASK_SCREENROUND); + EXPECT_EQ(SDK_MARSHMALLOW, config.sdkVersion); + EXPECT_EQ(std::string("notround-v23"), config.toString().string()); +} + } // namespace aapt diff --git a/tools/aapt2/SdkConstants.h b/tools/aapt2/SdkConstants.h index 803da03743c5..282ed9a56f5c 100644 --- a/tools/aapt2/SdkConstants.h +++ b/tools/aapt2/SdkConstants.h @@ -42,6 +42,7 @@ enum { SDK_KITKAT_WATCH = 20, SDK_LOLLIPOP = 21, SDK_LOLLIPOP_MR1 = 22, + SDK_MARSHMALLOW = 23, }; size_t findAttributeSdkLevel(ResourceId id); -- 2.11.0