Merge "Extended locales in AAPT / AssetManager."

This commit is contained in:
Narayan Kamath
2014-02-17 11:00:29 +00:00
committed by Gerrit Code Review
13 changed files with 667 additions and 291 deletions

View File

@ -1569,10 +1569,7 @@ public class Resources {
String locale = null; String locale = null;
if (mConfiguration.locale != null) { if (mConfiguration.locale != null) {
locale = mConfiguration.locale.getLanguage(); locale = mConfiguration.locale.toLanguageTag();
if (mConfiguration.locale.getCountry() != null) {
locale += "-" + mConfiguration.locale.getCountry();
}
} }
int width, height; int width, height;
if (mMetrics.widthPixels >= mMetrics.heightPixels) { if (mMetrics.widthPixels >= mMetrics.heightPixels) {

View File

@ -1053,7 +1053,7 @@ struct ResTable_config
// The ISO-15924 short name for the script corresponding to this // The ISO-15924 short name for the script corresponding to this
// configuration. (eg. Hant, Latn, etc.). Interpreted in conjunction with // configuration. (eg. Hant, Latn, etc.). Interpreted in conjunction with
// the locale field // the locale field.
char localeScript[4]; char localeScript[4];
// A single BCP-47 variant subtag. Will vary in length between 5 and 8 // A single BCP-47 variant subtag. Will vary in length between 5 and 8
@ -1118,14 +1118,23 @@ struct ResTable_config
bool match(const ResTable_config& settings) const; bool match(const ResTable_config& settings) const;
// Get the string representation of the locale component of this // Get the string representation of the locale component of this
// Config. This will contain the language along with the prefixed script, // Config. The maximum size of this representation will be
// region and variant of this config, separated by underscores. // |RESTABLE_MAX_LOCALE_LEN| (including a terminating '\0').
// //
// 'r' is the region prefix, 's' is the script prefix and 'v' is the // Example: en-US, en-Latn-US, en-POSIX.
// variant prefix. void getBcp47Locale(char* out) const;
//
// Example: en_rUS, en_sLatn_rUS, en_vPOSIX. // Sets the values of language, region, script and variant to the
void getLocale(char str[RESTABLE_MAX_LOCALE_LEN]) const; // well formed BCP-47 locale contained in |in|. The input locale is
// assumed to be valid and no validation is performed.
void setBcp47Locale(const char* in);
inline void clearLocale() {
locale = 0;
memset(localeScript, 0, sizeof(localeScript));
memset(localeVariant, 0, sizeof(localeVariant));
}
// Get the 2 or 3 letter language code of this configuration. Trailing // Get the 2 or 3 letter language code of this configuration. Trailing
// bytes are set to '\0'. // bytes are set to '\0'.
size_t unpackLanguage(char language[4]) const; size_t unpackLanguage(char language[4]) const;
@ -1133,12 +1142,16 @@ struct ResTable_config
// bytes are set to '\0'. // bytes are set to '\0'.
size_t unpackRegion(char region[4]) const; size_t unpackRegion(char region[4]) const;
// Sets the language code of this configuration from |language|. If |language| // Sets the language code of this configuration to the first three
// is a 2 letter code, the trailing byte is expected to be '\0'. // chars at |language|.
void packLanguage(const char language[3]); //
// Sets the region code of this configuration from |region|. If |region| // If |language| is a 2 letter code, the trailing byte must be '\0' or
// is a 2 letter code, the trailing byte is expected to be '\0'. // the BCP-47 separator '-'.
void packRegion(const char region[3]); void packLanguage(const char* language);
// Sets the region code of this configuration to the first three bytes
// at |region|. If |region| is a 2 letter code, the trailing byte must be '\0'
// or the BCP-47 separator '-'.
void packRegion(const char* region);
// Returns a positive integer if this config is more specific than |o| // Returns a positive integer if this config is more specific than |o|
// with respect to their locales, a negative integer if |o| is more specific // with respect to their locales, a negative integer if |o| is more specific

View File

@ -386,17 +386,8 @@ void AssetManager::setConfiguration(const ResTable_config& config, const char* l
if (locale) { if (locale) {
setLocaleLocked(locale); setLocaleLocked(locale);
} else if (config.language[0] != 0) { } else if (config.language[0] != 0) {
char spec[9]; char spec[RESTABLE_MAX_LOCALE_LEN];
spec[0] = config.language[0]; config.getBcp47Locale(spec);
spec[1] = config.language[1];
if (config.country[0] != 0) {
spec[2] = '_';
spec[3] = config.country[0];
spec[4] = config.country[1];
spec[5] = 0;
} else {
spec[3] = 0;
}
setLocaleLocked(spec); setLocaleLocked(spec);
} else { } else {
updateResourceParamsLocked(); updateResourceParamsLocked();
@ -668,20 +659,11 @@ void AssetManager::updateResourceParamsLocked() const
return; return;
} }
size_t llen = mLocale ? strlen(mLocale) : 0; if (mLocale) {
mConfig->language[0] = 0; mConfig->setBcp47Locale(mLocale);
mConfig->language[1] = 0; } else {
mConfig->country[0] = 0; mConfig->clearLocale();
mConfig->country[1] = 0;
if (llen >= 2) {
mConfig->language[0] = mLocale[0];
mConfig->language[1] = mLocale[1];
} }
if (llen >= 5) {
mConfig->country[0] = mLocale[3];
mConfig->country[1] = mLocale[4];
}
mConfig->size = sizeof(*mConfig);
res->setParameters(mConfig); res->setParameters(mConfig);
} }

View File

@ -1592,9 +1592,9 @@ void ResTable_config::copyFromDeviceNoSwap(const ResTable_config& o) {
return 0; return 0;
} }
/* static */ void packLanguageOrRegion(const char in[3], const char base, /* static */ void packLanguageOrRegion(const char* in, const char base,
char out[2]) { char out[2]) {
if (in[2] == 0) { if (in[2] == 0 || in[2] == '-') {
out[0] = in[0]; out[0] = in[0];
out[1] = in[1]; out[1] = in[1];
} else { } else {
@ -1608,11 +1608,11 @@ void ResTable_config::copyFromDeviceNoSwap(const ResTable_config& o) {
} }
void ResTable_config::packLanguage(const char language[3]) { void ResTable_config::packLanguage(const char* language) {
packLanguageOrRegion(language, 'a', this->language); packLanguageOrRegion(language, 'a', this->language);
} }
void ResTable_config::packRegion(const char region[3]) { void ResTable_config::packRegion(const char* region) {
packLanguageOrRegion(region, '0', this->country); packLanguageOrRegion(region, '0', this->country);
} }
@ -2320,7 +2320,7 @@ bool ResTable_config::match(const ResTable_config& settings) const {
return true; return true;
} }
void ResTable_config::getLocale(char str[RESTABLE_MAX_LOCALE_LEN]) const { void ResTable_config::getBcp47Locale(char str[RESTABLE_MAX_LOCALE_LEN]) const {
memset(str, 0, RESTABLE_MAX_LOCALE_LEN); memset(str, 0, RESTABLE_MAX_LOCALE_LEN);
// This represents the "any" locale value, which has traditionally been // This represents the "any" locale value, which has traditionally been
@ -2331,34 +2331,83 @@ void ResTable_config::getLocale(char str[RESTABLE_MAX_LOCALE_LEN]) const {
size_t charsWritten = 0; size_t charsWritten = 0;
if (language[0]) { if (language[0]) {
unpackLanguage(str); charsWritten += unpackLanguage(str);
}
if (country[0]) {
if (charsWritten) {
str[charsWritten++] = '_';
str[charsWritten++] = 'r';
}
charsWritten += unpackRegion(str + charsWritten);
} }
if (localeScript[0]) { if (localeScript[0]) {
if (charsWritten) { if (charsWritten) {
str[charsWritten++] = '_'; str[charsWritten++] = '-';
str[charsWritten++] = '_s';
} }
memcpy(str + charsWritten, localeScript, sizeof(localeScript)); memcpy(str + charsWritten, localeScript, sizeof(localeScript));
charsWritten += sizeof(localeScript);
}
if (country[0]) {
if (charsWritten) {
str[charsWritten++] = '-';
}
charsWritten += unpackRegion(str + charsWritten);
} }
if (localeVariant[0]) { if (localeVariant[0]) {
if (charsWritten) { if (charsWritten) {
str[charsWritten++] = '_'; str[charsWritten++] = '-';
str[charsWritten++] = 'v';
} }
memcpy(str + charsWritten, localeVariant, sizeof(localeVariant)); memcpy(str + charsWritten, localeVariant, sizeof(localeVariant));
} }
} }
/* static */ inline bool assignLocaleComponent(ResTable_config* config,
const char* start, size_t size) {
switch (size) {
case 0:
return false;
case 2:
case 3:
config->language[0] ? config->packRegion(start) : config->packLanguage(start);
break;
case 4:
config->localeScript[0] = toupper(start[0]);
for (size_t i = 1; i < 4; ++i) {
config->localeScript[i] = tolower(start[i]);
}
break;
case 5:
case 6:
case 7:
case 8:
for (size_t i = 0; i < size; ++i) {
config->localeVariant[i] = tolower(start[i]);
}
break;
default:
return false;
}
return true;
}
void ResTable_config::setBcp47Locale(const char* in) {
locale = 0;
memset(localeScript, 0, sizeof(localeScript));
memset(localeVariant, 0, sizeof(localeVariant));
const char* separator = in;
const char* start = in;
while ((separator = strchr(start, '-')) != NULL) {
const size_t size = separator - start;
if (!assignLocaleComponent(this, start, size)) {
fprintf(stderr, "Invalid BCP-47 locale string: %s", in);
}
start = (separator + 1);
}
const size_t size = in + strlen(in) - start;
assignLocaleComponent(this, start, size);
}
String8 ResTable_config::toString() const { String8 ResTable_config::toString() const {
String8 res; String8 res;
@ -2371,7 +2420,7 @@ String8 ResTable_config::toString() const {
res.appendFormat("%dmnc", dtohs(mnc)); res.appendFormat("%dmnc", dtohs(mnc));
} }
char localeStr[RESTABLE_MAX_LOCALE_LEN]; char localeStr[RESTABLE_MAX_LOCALE_LEN];
getLocale(localeStr); getBcp47Locale(localeStr);
res.append(localeStr); res.append(localeStr);
if ((screenLayout&MASK_LAYOUTDIR) != 0) { if ((screenLayout&MASK_LAYOUTDIR) != 0) {
@ -5126,18 +5175,20 @@ void ResTable::getConfigurations(Vector<ResTable_config>* configs) const
const size_t L = type->configs.size(); const size_t L = type->configs.size();
for (size_t l=0; l<L; l++) { for (size_t l=0; l<L; l++) {
const ResTable_type* config = type->configs[l]; const ResTable_type* config = type->configs[l];
const ResTable_config* cfg = &config->config; ResTable_config cfg;
memset(&cfg, 0, sizeof(ResTable_config));
cfg.copyFromDtoH(config->config);
// only insert unique // only insert unique
const size_t M = configs->size(); const size_t M = configs->size();
size_t m; size_t m;
for (m=0; m<M; m++) { for (m=0; m<M; m++) {
if (0 == (*configs)[m].compare(*cfg)) { if (0 == (*configs)[m].compare(cfg)) {
break; break;
} }
} }
// if we didn't find it // if we didn't find it
if (m == M) { if (m == M) {
configs->add(*cfg); configs->add(cfg);
} }
} }
} }
@ -5155,7 +5206,7 @@ void ResTable::getLocales(Vector<String8>* locales) const
char locale[RESTABLE_MAX_LOCALE_LEN]; char locale[RESTABLE_MAX_LOCALE_LEN];
for (size_t i=0; i<I; i++) { for (size_t i=0; i<I; i++) {
configs[i].getLocale(locale); configs[i].getBcp47Locale(locale);
const size_t J = locales->size(); const size_t J = locales->size();
size_t j; size_t j;
for (j=0; j<J; j++) { for (j=0; j<J; j++) {
@ -5815,7 +5866,7 @@ void ResTable::print(bool inclValues) const
} }
#if 0 #if 0
char localeStr[RESTABLE_MAX_LOCALE_LEN]; char localeStr[RESTABLE_MAX_LOCALE_LEN];
mParams.getLocale(localeStr); mParams.getBcp47Locale(localeStr);
printf("mParams=%s,\n" localeStr); printf("mParams=%s,\n" localeStr);
#endif #endif
size_t pgCount = mPackageGroups.size(); size_t pgCount = mPackageGroups.size();

View File

@ -146,5 +146,40 @@ TEST(ResourceTypesTest, IsMoreSpecificThan) {
EXPECT_TRUE(r.isMoreSpecificThan(l)); EXPECT_TRUE(r.isMoreSpecificThan(l));
} }
TEST(ResourceTypesTest, setLocale) {
ResTable_config test;
test.setBcp47Locale("en-US");
EXPECT_EQ('e', test.language[0]);
EXPECT_EQ('n', test.language[1]);
EXPECT_EQ('U', test.country[0]);
EXPECT_EQ('S', test.country[1]);
EXPECT_EQ(0, test.localeScript[0]);
EXPECT_EQ(0, test.localeVariant[0]);
test.setBcp47Locale("eng-419");
char out[4] = { 1, 1, 1, 1};
test.unpackLanguage(out);
EXPECT_EQ('e', out[0]);
EXPECT_EQ('n', out[1]);
EXPECT_EQ('g', out[2]);
EXPECT_EQ(0, out[3]);
memset(out, 1, 4);
test.unpackRegion(out);
EXPECT_EQ('4', out[0]);
EXPECT_EQ('1', out[1]);
EXPECT_EQ('9', out[2]);
test.setBcp47Locale("en-Latn-419");
memset(out, 1, 4);
EXPECT_EQ('e', test.language[0]);
EXPECT_EQ('n', test.language[1]);
EXPECT_EQ(0, memcmp("Latn", test.localeScript, 4));
test.unpackRegion(out);
EXPECT_EQ('4', out[0]);
EXPECT_EQ('1', out[1]);
EXPECT_EQ('9', out[2]);
}
} // namespace android. } // namespace android.

View File

@ -149,205 +149,506 @@ static bool isHidden(const char *root, const char *path)
// ========================================================================= // =========================================================================
// ========================================================================= // =========================================================================
status_t /* static */ void AaptLocaleValue::splitAndLowerCase(const char* const chars,
AaptGroupEntry::parseNamePart(const String8& part, int* axis, uint32_t* value) Vector<String8>* parts, const char separator) {
const char *p = chars;
const char *q;
while (NULL != (q = strchr(p, separator))) {
String8 val(p, q - p);
val.toLower();
parts->add(val);
p = q+1;
}
if (p < chars + strlen(chars)) {
String8 val(p);
val.toLower();
parts->add(val);
}
}
/* static */
inline bool isAlpha(const String8& string) {
const size_t length = string.length();
for (size_t i = 0; i < length; ++i) {
if (!isalpha(string[i])) {
return false;
}
}
return true;
}
/* static */
inline bool isNumber(const String8& string) {
const size_t length = string.length();
for (size_t i = 0; i < length; ++i) {
if (!isdigit(string[i])) {
return false;
}
}
return true;
}
void AaptLocaleValue::setLanguage(const char* languageChars) {
size_t i = 0;
while ((*languageChars) != '\0') {
language[i++] = tolower(*languageChars);
languageChars++;
}
}
void AaptLocaleValue::setRegion(const char* regionChars) {
size_t i = 0;
while ((*regionChars) != '\0') {
region[i++] = toupper(*regionChars);
regionChars++;
}
}
void AaptLocaleValue::setScript(const char* scriptChars) {
size_t i = 0;
while ((*scriptChars) != '\0') {
if (i == 0) {
script[i++] = toupper(*scriptChars);
} else {
script[i++] = tolower(*scriptChars);
}
scriptChars++;
}
}
void AaptLocaleValue::setVariant(const char* variantChars) {
size_t i = 0;
while ((*variantChars) != '\0') {
variant[i++] = *variantChars;
variantChars++;
}
}
bool AaptLocaleValue::initFromFilterString(const String8& str) {
// A locale (as specified in the filter) is an underscore separated name such
// as "en_US", "en_Latn_US", or "en_US_POSIX".
Vector<String8> parts;
splitAndLowerCase(str.string(), &parts, '_');
const int numTags = parts.size();
bool valid = false;
if (numTags >= 1) {
const String8& lang = parts[0];
if (isAlpha(lang) && (lang.length() == 2 || lang.length() == 3)) {
setLanguage(lang.string());
valid = true;
}
}
if (!valid || numTags == 1) {
return valid;
}
// At this point, valid == true && numTags > 1.
const String8& part2 = parts[1];
if ((part2.length() == 2 && isAlpha(part2)) ||
(part2.length() == 3 && isNumber(part2))) {
setRegion(part2.string());
} else if (part2.length() == 4 && isAlpha(part2)) {
setScript(part2.string());
} else if (part2.length() >= 5 && part2.length() <= 8) {
setVariant(part2.string());
} else {
valid = false;
}
if (!valid || numTags == 2) {
return valid;
}
// At this point, valid == true && numTags > 1.
const String8& part3 = parts[2];
if (((part3.length() == 2 && isAlpha(part3)) ||
(part3.length() == 3 && isNumber(part3))) && script[0]) {
setRegion(part3.string());
} else if (part3.length() >= 5 && part3.length() <= 8) {
setVariant(part3.string());
} else {
valid = false;
}
if (!valid || numTags == 3) {
return valid;
}
const String8& part4 = parts[3];
if (part4.length() >= 5 && part4.length() <= 8) {
setVariant(part4.string());
} else {
valid = false;
}
if (!valid || numTags > 4) {
return false;
}
return true;
}
int AaptLocaleValue::initFromDirName(const Vector<String8>& parts, const int startIndex) {
const int size = parts.size();
int currentIndex = startIndex;
String8 part = parts[currentIndex];
if (part[0] == 'b' && part[1] == '+') {
// This is a "modified" BCP-47 language tag. Same semantics as BCP-47 tags,
// except that the separator is "+" and not "-".
Vector<String8> subtags;
AaptLocaleValue::splitAndLowerCase(part.string(), &subtags, '+');
subtags.removeItemsAt(0);
if (subtags.size() == 1) {
setLanguage(subtags[0]);
} else if (subtags.size() == 2) {
setLanguage(subtags[0]);
// The second tag can either be a region, a variant or a script.
switch (subtags[1].size()) {
case 2:
case 3:
setRegion(subtags[1]);
break;
case 4:
setScript(subtags[1]);
break;
case 5:
case 6:
case 7:
case 8:
setVariant(subtags[1]);
break;
default:
fprintf(stderr, "ERROR: Invalid BCP-47 tag in directory name %s\n",
part.string());
return -1;
}
} else if (subtags.size() == 3) {
// The language is always the first subtag.
setLanguage(subtags[0]);
// The second subtag can either be a script or a region code.
// If its size is 4, it's a script code, else it's a region code.
bool hasRegion = false;
if (subtags[1].size() == 4) {
setScript(subtags[1]);
} else if (subtags[1].size() == 2 || subtags[1].size() == 3) {
setRegion(subtags[1]);
hasRegion = true;
} else {
fprintf(stderr, "ERROR: Invalid BCP-47 tag in directory name %s\n", part.string());
return -1;
}
// The third tag can either be a region code (if the second tag was
// a script), else a variant code.
if (subtags[2].size() > 4) {
setVariant(subtags[2]);
} else {
setRegion(subtags[2]);
}
} else if (subtags.size() == 4) {
setLanguage(subtags[0]);
setScript(subtags[1]);
setRegion(subtags[2]);
setVariant(subtags[3]);
} else {
fprintf(stderr, "ERROR: Invalid BCP-47 tag in directory name: %s\n", part.string());
return -1;
}
return ++currentIndex;
} else {
if ((part.length() == 2 || part.length() == 3) && isAlpha(part)) {
setLanguage(part);
if (++currentIndex == size) {
return size;
}
} else {
return currentIndex;
}
part = parts[currentIndex];
if (part.string()[0] == 'r' && part.length() == 3) {
setRegion(part.string() + 1);
if (++currentIndex == size) {
return size;
}
}
}
return currentIndex;
}
String8 AaptLocaleValue::toDirName() const {
String8 dirName("");
if (language[0]) {
dirName += language;
} else {
return dirName;
}
if (script[0]) {
dirName += "-s";
dirName += script;
}
if (region[0]) {
dirName += "-r";
dirName += region;
}
if (variant[0]) {
dirName += "-v";
dirName += variant;
}
return dirName;
}
void AaptLocaleValue::initFromResTable(const ResTable_config& config) {
config.unpackLanguage(language);
config.unpackRegion(region);
if (config.localeScript[0]) {
memcpy(script, config.localeScript, sizeof(config.localeScript));
}
if (config.localeVariant[0]) {
memcpy(variant, config.localeVariant, sizeof(config.localeVariant));
}
}
void AaptLocaleValue::writeTo(ResTable_config* out) const {
out->packLanguage(language);
out->packRegion(region);
if (script[0]) {
memcpy(out->localeScript, script, sizeof(out->localeScript));
}
if (variant[0]) {
memcpy(out->localeVariant, variant, sizeof(out->localeVariant));
}
}
/* static */ bool
AaptGroupEntry::parseFilterNamePart(const String8& part, int* axis, AxisValue* value)
{ {
ResTable_config config; ResTable_config config;
memset(&config, 0, sizeof(ResTable_config));
// IMSI - MCC // IMSI - MCC
if (getMccName(part.string(), &config)) { if (getMccName(part.string(), &config)) {
*axis = AXIS_MCC; *axis = AXIS_MCC;
*value = config.mcc; value->intValue = config.mcc;
return 0; return true;
} }
// IMSI - MNC // IMSI - MNC
if (getMncName(part.string(), &config)) { if (getMncName(part.string(), &config)) {
*axis = AXIS_MNC; *axis = AXIS_MNC;
*value = config.mnc; value->intValue = config.mnc;
return 0; return true;
} }
// locale - language // locale - language
if (part.length() == 2 && isalpha(part[0]) && isalpha(part[1])) { if (value->localeValue.initFromFilterString(part)) {
*axis = AXIS_LANGUAGE; *axis = AXIS_LOCALE;
*value = part[1] << 8 | part[0]; return true;
return 0;
}
// locale - language_REGION
if (part.length() == 5 && isalpha(part[0]) && isalpha(part[1])
&& part[2] == '_' && isalpha(part[3]) && isalpha(part[4])) {
*axis = AXIS_LANGUAGE;
*value = (part[4] << 24) | (part[3] << 16) | (part[1] << 8) | (part[0]);
return 0;
} }
// layout direction // layout direction
if (getLayoutDirectionName(part.string(), &config)) { if (getLayoutDirectionName(part.string(), &config)) {
*axis = AXIS_LAYOUTDIR; *axis = AXIS_LAYOUTDIR;
*value = (config.screenLayout&ResTable_config::MASK_LAYOUTDIR); value->intValue = (config.screenLayout&ResTable_config::MASK_LAYOUTDIR);
return 0; return true;
} }
// smallest screen dp width // smallest screen dp width
if (getSmallestScreenWidthDpName(part.string(), &config)) { if (getSmallestScreenWidthDpName(part.string(), &config)) {
*axis = AXIS_SMALLESTSCREENWIDTHDP; *axis = AXIS_SMALLESTSCREENWIDTHDP;
*value = config.smallestScreenWidthDp; value->intValue = config.smallestScreenWidthDp;
return 0; return true;
} }
// screen dp width // screen dp width
if (getScreenWidthDpName(part.string(), &config)) { if (getScreenWidthDpName(part.string(), &config)) {
*axis = AXIS_SCREENWIDTHDP; *axis = AXIS_SCREENWIDTHDP;
*value = config.screenWidthDp; value->intValue = config.screenWidthDp;
return 0; return true;
} }
// screen dp height // screen dp height
if (getScreenHeightDpName(part.string(), &config)) { if (getScreenHeightDpName(part.string(), &config)) {
*axis = AXIS_SCREENHEIGHTDP; *axis = AXIS_SCREENHEIGHTDP;
*value = config.screenHeightDp; value->intValue = config.screenHeightDp;
return 0; return true;
} }
// screen layout size // screen layout size
if (getScreenLayoutSizeName(part.string(), &config)) { if (getScreenLayoutSizeName(part.string(), &config)) {
*axis = AXIS_SCREENLAYOUTSIZE; *axis = AXIS_SCREENLAYOUTSIZE;
*value = (config.screenLayout&ResTable_config::MASK_SCREENSIZE); value->intValue = (config.screenLayout&ResTable_config::MASK_SCREENSIZE);
return 0; return true;
} }
// screen layout long // screen layout long
if (getScreenLayoutLongName(part.string(), &config)) { if (getScreenLayoutLongName(part.string(), &config)) {
*axis = AXIS_SCREENLAYOUTLONG; *axis = AXIS_SCREENLAYOUTLONG;
*value = (config.screenLayout&ResTable_config::MASK_SCREENLONG); value->intValue = (config.screenLayout&ResTable_config::MASK_SCREENLONG);
return 0; return true;
} }
// orientation // orientation
if (getOrientationName(part.string(), &config)) { if (getOrientationName(part.string(), &config)) {
*axis = AXIS_ORIENTATION; *axis = AXIS_ORIENTATION;
*value = config.orientation; value->intValue = config.orientation;
return 0; return true;
} }
// ui mode type // ui mode type
if (getUiModeTypeName(part.string(), &config)) { if (getUiModeTypeName(part.string(), &config)) {
*axis = AXIS_UIMODETYPE; *axis = AXIS_UIMODETYPE;
*value = (config.uiMode&ResTable_config::MASK_UI_MODE_TYPE); value->intValue = (config.uiMode&ResTable_config::MASK_UI_MODE_TYPE);
return 0; return true;
} }
// ui mode night // ui mode night
if (getUiModeNightName(part.string(), &config)) { if (getUiModeNightName(part.string(), &config)) {
*axis = AXIS_UIMODENIGHT; *axis = AXIS_UIMODENIGHT;
*value = (config.uiMode&ResTable_config::MASK_UI_MODE_NIGHT); value->intValue = (config.uiMode&ResTable_config::MASK_UI_MODE_NIGHT);
return 0; return true;
} }
// density // density
if (getDensityName(part.string(), &config)) { if (getDensityName(part.string(), &config)) {
*axis = AXIS_DENSITY; *axis = AXIS_DENSITY;
*value = config.density; value->intValue = config.density;
return 0; return true;
} }
// touchscreen // touchscreen
if (getTouchscreenName(part.string(), &config)) { if (getTouchscreenName(part.string(), &config)) {
*axis = AXIS_TOUCHSCREEN; *axis = AXIS_TOUCHSCREEN;
*value = config.touchscreen; value->intValue = config.touchscreen;
return 0; return true;
} }
// keyboard hidden // keyboard hidden
if (getKeysHiddenName(part.string(), &config)) { if (getKeysHiddenName(part.string(), &config)) {
*axis = AXIS_KEYSHIDDEN; *axis = AXIS_KEYSHIDDEN;
*value = config.inputFlags; value->intValue = config.inputFlags;
return 0; return true;
} }
// keyboard // keyboard
if (getKeyboardName(part.string(), &config)) { if (getKeyboardName(part.string(), &config)) {
*axis = AXIS_KEYBOARD; *axis = AXIS_KEYBOARD;
*value = config.keyboard; value->intValue = config.keyboard;
return 0; return true;
} }
// navigation hidden // navigation hidden
if (getNavHiddenName(part.string(), &config)) { if (getNavHiddenName(part.string(), &config)) {
*axis = AXIS_NAVHIDDEN; *axis = AXIS_NAVHIDDEN;
*value = config.inputFlags; value->intValue = config.inputFlags;
return 0; return 0;
} }
// navigation // navigation
if (getNavigationName(part.string(), &config)) { if (getNavigationName(part.string(), &config)) {
*axis = AXIS_NAVIGATION; *axis = AXIS_NAVIGATION;
*value = config.navigation; value->intValue = config.navigation;
return 0; return true;
} }
// screen size // screen size
if (getScreenSizeName(part.string(), &config)) { if (getScreenSizeName(part.string(), &config)) {
*axis = AXIS_SCREENSIZE; *axis = AXIS_SCREENSIZE;
*value = config.screenSize; value->intValue = config.screenSize;
return 0; return true;
} }
// version // version
if (getVersionName(part.string(), &config)) { if (getVersionName(part.string(), &config)) {
*axis = AXIS_VERSION; *axis = AXIS_VERSION;
*value = config.version; value->intValue = config.version;
return 0; return true;
} }
return 1; return false;
} }
uint32_t AxisValue
AaptGroupEntry::getConfigValueForAxis(const ResTable_config& config, int axis) AaptGroupEntry::getConfigValueForAxis(const ResTable_config& config, int axis)
{ {
AxisValue value;
switch (axis) { switch (axis) {
case AXIS_MCC: case AXIS_MCC:
return config.mcc; value.intValue = config.mcc;
break;
case AXIS_MNC: case AXIS_MNC:
return config.mnc; value.intValue = config.mnc;
case AXIS_LANGUAGE: break;
return (((uint32_t)config.country[1]) << 24) | (((uint32_t)config.country[0]) << 16) case AXIS_LOCALE:
| (((uint32_t)config.language[1]) << 8) | (config.language[0]); value.localeValue.initFromResTable(config);
break;
case AXIS_LAYOUTDIR: case AXIS_LAYOUTDIR:
return config.screenLayout&ResTable_config::MASK_LAYOUTDIR; value.intValue = config.screenLayout&ResTable_config::MASK_LAYOUTDIR;
break;
case AXIS_SCREENLAYOUTSIZE: case AXIS_SCREENLAYOUTSIZE:
return config.screenLayout&ResTable_config::MASK_SCREENSIZE; value.intValue = config.screenLayout&ResTable_config::MASK_SCREENSIZE;
break;
case AXIS_ORIENTATION: case AXIS_ORIENTATION:
return config.orientation; value.intValue = config.orientation;
break;
case AXIS_UIMODETYPE: case AXIS_UIMODETYPE:
return (config.uiMode&ResTable_config::MASK_UI_MODE_TYPE); value.intValue = (config.uiMode&ResTable_config::MASK_UI_MODE_TYPE);
break;
case AXIS_UIMODENIGHT: case AXIS_UIMODENIGHT:
return (config.uiMode&ResTable_config::MASK_UI_MODE_NIGHT); value.intValue = (config.uiMode&ResTable_config::MASK_UI_MODE_NIGHT);
break;
case AXIS_DENSITY: case AXIS_DENSITY:
return config.density; value.intValue = config.density;
break;
case AXIS_TOUCHSCREEN: case AXIS_TOUCHSCREEN:
return config.touchscreen; value.intValue = config.touchscreen;
break;
case AXIS_KEYSHIDDEN: case AXIS_KEYSHIDDEN:
return config.inputFlags; value.intValue = config.inputFlags;
break;
case AXIS_KEYBOARD: case AXIS_KEYBOARD:
return config.keyboard; value.intValue = config.keyboard;
break;
case AXIS_NAVIGATION: case AXIS_NAVIGATION:
return config.navigation; value.intValue = config.navigation;
break;
case AXIS_SCREENSIZE: case AXIS_SCREENSIZE:
return config.screenSize; value.intValue = config.screenSize;
break;
case AXIS_SMALLESTSCREENWIDTHDP: case AXIS_SMALLESTSCREENWIDTHDP:
return config.smallestScreenWidthDp; value.intValue = config.smallestScreenWidthDp;
break;
case AXIS_SCREENWIDTHDP: case AXIS_SCREENWIDTHDP:
return config.screenWidthDp; value.intValue = config.screenWidthDp;
break;
case AXIS_SCREENHEIGHTDP: case AXIS_SCREENHEIGHTDP:
return config.screenHeightDp; value.intValue = config.screenHeightDp;
break;
case AXIS_VERSION: case AXIS_VERSION:
return config.version; value.intValue = config.version;
break;
} }
return 0;
return value;
} }
bool bool
@ -371,24 +672,14 @@ AaptGroupEntry::initFromDirName(const char* dir, String8* resType)
mParamsChanged = true; mParamsChanged = true;
Vector<String8> parts; Vector<String8> parts;
AaptLocaleValue::splitAndLowerCase(dir, &parts, '-');
String8 mcc, mnc, loc, layoutsize, layoutlong, orient, den; String8 mcc, mnc, layoutsize, layoutlong, orient, den;
String8 touch, key, keysHidden, nav, navHidden, size, layoutDir, vers; String8 touch, key, keysHidden, nav, navHidden, size, layoutDir, vers;
String8 uiModeType, uiModeNight, smallestwidthdp, widthdp, heightdp; String8 uiModeType, uiModeNight, smallestwidthdp, widthdp, heightdp;
const char *p = dir; AaptLocaleValue locale;
const char *q; int numLocaleComponents = 0;
while (NULL != (q = strchr(p, '-'))) {
String8 val(p, q-p);
val.toLower();
parts.add(val);
//printf("part: %s\n", parts[parts.size()-1].string());
p = q+1;
}
String8 val(p);
val.toLower();
parts.add(val);
//printf("part: %s\n", parts[parts.size()-1].string());
const int N = parts.size(); const int N = parts.size();
int index = 0; int index = 0;
@ -429,38 +720,18 @@ AaptGroupEntry::initFromDirName(const char* dir, String8* resType)
} }
part = parts[index]; part = parts[index];
} else { } else {
//printf("not mcc: %s\n", part.string()); //printf("not mnc: %s\n", part.string());
} }
// locale - language index = locale.initFromDirName(parts, index);
if (part.length() == 2 && isalpha(part[0]) && isalpha(part[1])) { if (index == -1) {
loc = part; return false;
}
index++; if (index >= N){
if (index == N) {
goto success; goto success;
} }
part = parts[index]; part = parts[index];
} else {
//printf("not language: %s\n", part.string());
}
// locale - region
if (loc.length() > 0
&& part.length() == 3 && part[0] == 'r' && part[0] && part[1]) {
loc += "-";
part.toUpper();
loc += part.string() + 1;
index++;
if (index == N) {
goto success;
}
part = parts[index];
} else {
//printf("not region: %s\n", part.string());
}
if (getLayoutDirectionName(part.string())) { if (getLayoutDirectionName(part.string())) {
layoutDir = part; layoutDir = part;
@ -679,7 +950,7 @@ AaptGroupEntry::initFromDirName(const char* dir, String8* resType)
success: success:
this->mcc = mcc; this->mcc = mcc;
this->mnc = mnc; this->mnc = mnc;
this->locale = loc; this->locale = locale;
this->screenLayoutSize = layoutsize; this->screenLayoutSize = layoutsize;
this->screenLayoutLong = layoutlong; this->screenLayoutLong = layoutlong;
this->smallestScreenWidthDp = smallestwidthdp; this->smallestScreenWidthDp = smallestwidthdp;
@ -711,7 +982,7 @@ AaptGroupEntry::toString() const
s += ","; s += ",";
s += this->mnc; s += this->mnc;
s += ","; s += ",";
s += this->locale; s += locale.toDirName();
s += ","; s += ",";
s += layoutDirection; s += layoutDirection;
s += ","; s += ",";
@ -765,12 +1036,15 @@ AaptGroupEntry::toDirName(const String8& resType) const
} }
s += mnc; s += mnc;
} }
if (this->locale != "") {
const String8 localeComponent = locale.toDirName();
if (localeComponent != "") {
if (s.length() > 0) { if (s.length() > 0) {
s += "-"; s += "-";
} }
s += locale; s += localeComponent;
} }
if (this->layoutDirection != "") { if (this->layoutDirection != "") {
if (s.length() > 0) { if (s.length() > 0) {
s += "-"; s += "-";
@ -942,55 +1216,6 @@ bool AaptGroupEntry::getMncName(const char* name,
return true; return true;
} }
/*
* Does this directory name fit the pattern of a locale dir ("en-rUS" or
* "default")?
*
* TODO: Should insist that the first two letters are lower case, and the
* second two are upper.
*/
bool AaptGroupEntry::getLocaleName(const char* fileName,
ResTable_config* out)
{
if (strcmp(fileName, kWildcardName) == 0
|| strcmp(fileName, kDefaultLocale) == 0) {
if (out) {
out->language[0] = 0;
out->language[1] = 0;
out->country[0] = 0;
out->country[1] = 0;
}
return true;
}
if (strlen(fileName) == 2 && isalpha(fileName[0]) && isalpha(fileName[1])) {
if (out) {
out->language[0] = fileName[0];
out->language[1] = fileName[1];
out->country[0] = 0;
out->country[1] = 0;
}
return true;
}
if (strlen(fileName) == 5 &&
isalpha(fileName[0]) &&
isalpha(fileName[1]) &&
fileName[2] == '-' &&
isalpha(fileName[3]) &&
isalpha(fileName[4])) {
if (out) {
out->language[0] = fileName[0];
out->language[1] = fileName[1];
out->country[0] = fileName[3];
out->country[1] = fileName[4];
}
return true;
}
return false;
}
bool AaptGroupEntry::getLayoutDirectionName(const char* name, ResTable_config* out) bool AaptGroupEntry::getLayoutDirectionName(const char* name, ResTable_config* out)
{ {
if (strcmp(name, kWildcardName) == 0) { if (strcmp(name, kWildcardName) == 0) {
@ -1496,18 +1721,18 @@ int AaptGroupEntry::compare(const AaptGroupEntry& o) const
return v; return v;
} }
const ResTable_config& AaptGroupEntry::toParams() const const ResTable_config AaptGroupEntry::toParams() const
{ {
if (!mParamsChanged) { if (!mParamsChanged) {
return mParams; return mParams;
} }
mParamsChanged = false; mParamsChanged = false;
ResTable_config& params(mParams); ResTable_config& params = mParams;
memset(&params, 0, sizeof(params)); memset(&params, 0, sizeof(ResTable_config));
getMccName(mcc.string(), &params); getMccName(mcc.string(), &params);
getMncName(mnc.string(), &params); getMncName(mnc.string(), &params);
getLocaleName(locale.string(), &params); locale.writeTo(&params);
getLayoutDirectionName(layoutDirection.string(), &params); getLayoutDirectionName(layoutDirection.string(), &params);
getSmallestScreenWidthDpName(smallestScreenWidthDp.string(), &params); getSmallestScreenWidthDpName(smallestScreenWidthDp.string(), &params);
getScreenWidthDpName(screenWidthDp.string(), &params); getScreenWidthDpName(screenWidthDp.string(), &params);
@ -1982,7 +2207,9 @@ status_t AaptSymbols::applyJavaSymbols(const sp<AaptSymbols>& javaSymbols)
AaptAssets::AaptAssets() AaptAssets::AaptAssets()
: AaptDir(String8(), String8()), : AaptDir(String8(), String8()),
mChanged(false), mHaveIncludedAssets(false), mRes(NULL) mHavePrivateSymbols(false),
mChanged(false), mHaveIncludedAssets(false),
mRes(NULL)
{ {
} }
@ -2491,9 +2718,9 @@ status_t AaptAssets::filter(Bundle* bundle)
// If our preferred density is hdpi but we only have mdpi and xhdpi resources, we // If our preferred density is hdpi but we only have mdpi and xhdpi resources, we
// pick xhdpi. // pick xhdpi.
uint32_t preferredDensity = 0; uint32_t preferredDensity = 0;
const SortedVector<uint32_t>* preferredConfigs = prefFilter.configsForAxis(AXIS_DENSITY); const SortedVector<AxisValue>* preferredConfigs = prefFilter.configsForAxis(AXIS_DENSITY);
if (preferredConfigs != NULL && preferredConfigs->size() > 0) { if (preferredConfigs != NULL && preferredConfigs->size() > 0) {
preferredDensity = (*preferredConfigs)[0]; preferredDensity = (*preferredConfigs)[0].intValue;
} }
// Now deal with preferred configurations. // Now deal with preferred configurations.

View File

@ -13,7 +13,6 @@
#include <utils/RefBase.h> #include <utils/RefBase.h>
#include <utils/SortedVector.h> #include <utils/SortedVector.h>
#include <utils/String8.h> #include <utils/String8.h>
#include <utils/String8.h>
#include <utils/Vector.h> #include <utils/Vector.h>
#include "ZipFile.h" #include "ZipFile.h"
@ -34,8 +33,7 @@ enum {
AXIS_NONE = 0, AXIS_NONE = 0,
AXIS_MCC = 1, AXIS_MCC = 1,
AXIS_MNC, AXIS_MNC,
AXIS_LANGUAGE, AXIS_LOCALE,
AXIS_REGION,
AXIS_SCREENLAYOUTSIZE, AXIS_SCREENLAYOUTSIZE,
AXIS_SCREENLAYOUTLONG, AXIS_SCREENLAYOUTLONG,
AXIS_ORIENTATION, AXIS_ORIENTATION,
@ -58,6 +56,73 @@ enum {
AXIS_END = AXIS_VERSION, AXIS_END = AXIS_VERSION,
}; };
struct AaptLocaleValue {
char language[4];
char region[4];
char script[4];
char variant[8];
AaptLocaleValue() {
memset(this, 0, sizeof(AaptLocaleValue));
}
// Initialize this AaptLocaleValue from a config string.
bool initFromFilterString(const String8& config);
int initFromDirName(const Vector<String8>& parts, const int startIndex);
// Initialize this AaptLocaleValue from a ResTable_config.
void initFromResTable(const ResTable_config& config);
void writeTo(ResTable_config* out) const;
String8 toDirName() const;
int compare(const AaptLocaleValue& other) const {
return memcmp(this, &other, sizeof(AaptLocaleValue));
}
static void splitAndLowerCase(const char* const chars, Vector<String8>* parts,
const char separator);
inline bool operator<(const AaptLocaleValue& o) const { return compare(o) < 0; }
inline bool operator<=(const AaptLocaleValue& o) const { return compare(o) <= 0; }
inline bool operator==(const AaptLocaleValue& o) const { return compare(o) == 0; }
inline bool operator!=(const AaptLocaleValue& o) const { return compare(o) != 0; }
inline bool operator>=(const AaptLocaleValue& o) const { return compare(o) >= 0; }
inline bool operator>(const AaptLocaleValue& o) const { return compare(o) > 0; }
private:
void setLanguage(const char* language);
void setRegion(const char* language);
void setScript(const char* script);
void setVariant(const char* variant);
};
struct AxisValue {
// Used for all axes except AXIS_LOCALE, which is represented
// as a AaptLocaleValue value.
int intValue;
AaptLocaleValue localeValue;
AxisValue() : intValue(0) {
}
inline int compare(const AxisValue &other) const {
if (intValue != other.intValue) {
return intValue - other.intValue;
}
return localeValue.compare(other.localeValue);
}
inline bool operator<(const AxisValue& o) const { return compare(o) < 0; }
inline bool operator<=(const AxisValue& o) const { return compare(o) <= 0; }
inline bool operator==(const AxisValue& o) const { return compare(o) == 0; }
inline bool operator!=(const AxisValue& o) const { return compare(o) != 0; }
inline bool operator>=(const AxisValue& o) const { return compare(o) >= 0; }
inline bool operator>(const AxisValue& o) const { return compare(o) > 0; }
};
/** /**
* This structure contains a specific variation of a single file out * This structure contains a specific variation of a single file out
* of all the variations it can have that we can have. * of all the variations it can have that we can have.
@ -65,22 +130,38 @@ enum {
struct AaptGroupEntry struct AaptGroupEntry
{ {
public: public:
AaptGroupEntry() : mParamsChanged(true) { } AaptGroupEntry() : mParamsChanged(true) {
AaptGroupEntry(const String8& _locale, const String8& _vendor) memset(&mParams, 0, sizeof(ResTable_config));
: locale(_locale), vendor(_vendor), mParamsChanged(true) { } }
bool initFromDirName(const char* dir, String8* resType); bool initFromDirName(const char* dir, String8* resType);
static status_t parseNamePart(const String8& part, int* axis, uint32_t* value); static bool parseFilterNamePart(const String8& part, int* axis, AxisValue* value);
static uint32_t getConfigValueForAxis(const ResTable_config& config, int axis); static AxisValue getConfigValueForAxis(const ResTable_config& config, int axis);
static bool configSameExcept(const ResTable_config& config, static bool configSameExcept(const ResTable_config& config,
const ResTable_config& otherConfig, int axis); const ResTable_config& otherConfig, int axis);
int compare(const AaptGroupEntry& o) const;
const ResTable_config toParams() const;
inline bool operator<(const AaptGroupEntry& o) const { return compare(o) < 0; }
inline bool operator<=(const AaptGroupEntry& o) const { return compare(o) <= 0; }
inline bool operator==(const AaptGroupEntry& o) const { return compare(o) == 0; }
inline bool operator!=(const AaptGroupEntry& o) const { return compare(o) != 0; }
inline bool operator>=(const AaptGroupEntry& o) const { return compare(o) >= 0; }
inline bool operator>(const AaptGroupEntry& o) const { return compare(o) > 0; }
String8 toString() const;
String8 toDirName(const String8& resType) const;
const String8& getVersionString() const { return version; }
private:
static bool getMccName(const char* name, ResTable_config* out = NULL); static bool getMccName(const char* name, ResTable_config* out = NULL);
static bool getMncName(const char* name, ResTable_config* out = NULL); static bool getMncName(const char* name, ResTable_config* out = NULL);
static bool getLocaleName(const char* name, ResTable_config* out = NULL);
static bool getScreenLayoutSizeName(const char* name, ResTable_config* out = NULL); static bool getScreenLayoutSizeName(const char* name, ResTable_config* out = NULL);
static bool getScreenLayoutLongName(const char* name, ResTable_config* out = NULL); static bool getScreenLayoutLongName(const char* name, ResTable_config* out = NULL);
static bool getOrientationName(const char* name, ResTable_config* out = NULL); static bool getOrientationName(const char* name, ResTable_config* out = NULL);
@ -99,26 +180,9 @@ public:
static bool getLayoutDirectionName(const char* name, ResTable_config* out = NULL); static bool getLayoutDirectionName(const char* name, ResTable_config* out = NULL);
static bool getVersionName(const char* name, ResTable_config* out = NULL); static bool getVersionName(const char* name, ResTable_config* out = NULL);
int compare(const AaptGroupEntry& o) const;
const ResTable_config& toParams() const;
inline bool operator<(const AaptGroupEntry& o) const { return compare(o) < 0; }
inline bool operator<=(const AaptGroupEntry& o) const { return compare(o) <= 0; }
inline bool operator==(const AaptGroupEntry& o) const { return compare(o) == 0; }
inline bool operator!=(const AaptGroupEntry& o) const { return compare(o) != 0; }
inline bool operator>=(const AaptGroupEntry& o) const { return compare(o) >= 0; }
inline bool operator>(const AaptGroupEntry& o) const { return compare(o) > 0; }
String8 toString() const;
String8 toDirName(const String8& resType) const;
const String8& getVersionString() const { return version; }
private:
String8 mcc; String8 mcc;
String8 mnc; String8 mnc;
String8 locale; AaptLocaleValue locale;
String8 vendor; String8 vendor;
String8 smallestScreenWidthDp; String8 smallestScreenWidthDp;
String8 screenWidthDp; String8 screenWidthDp;

View File

@ -517,6 +517,7 @@ int doDump(Bundle* bundle)
// the API version because key resources like icons will have an implicit // the API version because key resources like icons will have an implicit
// version if they are using newer config types like density. // version if they are using newer config types like density.
ResTable_config config; ResTable_config config;
memset(&config, 0, sizeof(ResTable_config));
config.language[0] = 'e'; config.language[0] = 'e';
config.language[1] = 'n'; config.language[1] = 'n';
config.country[0] = 'U'; config.country[0] = 'U';

View File

@ -80,6 +80,7 @@ public:
ResourceDirIterator(const sp<ResourceTypeSet>& set, const String8& resType) ResourceDirIterator(const sp<ResourceTypeSet>& set, const String8& resType)
: mResType(resType), mSet(set), mSetPos(0), mGroupPos(0) : mResType(resType), mSet(set), mSetPos(0), mGroupPos(0)
{ {
memset(&mParams, 0, sizeof(ResTable_config));
} }
inline const sp<AaptGroup>& getGroup() const { return mGroup; } inline const sp<AaptGroup>& getGroup() const { return mGroup; }

View File

@ -28,8 +28,8 @@ ResourceFilter::parse(const char* arg)
mContainsPseudo = true; mContainsPseudo = true;
} }
int axis; int axis;
uint32_t value; AxisValue value;
if (AaptGroupEntry::parseNamePart(part, &axis, &value)) { if (!AaptGroupEntry::parseFilterNamePart(part, &axis, &value)) {
fprintf(stderr, "Invalid configuration: %s\n", arg); fprintf(stderr, "Invalid configuration: %s\n", arg);
fprintf(stderr, " "); fprintf(stderr, " ");
for (int i=0; i<p-arg; i++) { for (int i=0; i<p-arg; i++) {
@ -44,15 +44,20 @@ ResourceFilter::parse(const char* arg)
ssize_t index = mData.indexOfKey(axis); ssize_t index = mData.indexOfKey(axis);
if (index < 0) { if (index < 0) {
mData.add(axis, SortedVector<uint32_t>()); mData.add(axis, SortedVector<AxisValue>());
} }
SortedVector<uint32_t>& sv = mData.editValueFor(axis); SortedVector<AxisValue>& sv = mData.editValueFor(axis);
sv.add(value); sv.add(value);
// if it's a locale with a region, also match an unmodified locale of the
// same language // If it's a locale with a region, script or variant, we should also match an
if (axis == AXIS_LANGUAGE) { // unmodified locale of the same language
if (value & 0xffff0000) { if (axis == AXIS_LOCALE) {
sv.add(value & 0x0000ffff); if (value.localeValue.region[0] || value.localeValue.script[0] ||
value.localeValue.variant[0]) {
AxisValue copy;
memcpy(copy.localeValue.language, value.localeValue.language,
sizeof(value.localeValue.language));
sv.add(copy);
} }
} }
p = q; p = q;
@ -70,9 +75,9 @@ ResourceFilter::isEmpty() const
} }
bool bool
ResourceFilter::match(int axis, uint32_t value) const ResourceFilter::match(int axis, const AxisValue& value) const
{ {
if (value == 0) { if (value.intValue == 0 && (value.localeValue.language[0] == 0)) {
// they didn't specify anything so take everything // they didn't specify anything so take everything
return true; return true;
} }
@ -81,7 +86,7 @@ ResourceFilter::match(int axis, uint32_t value) const
// we didn't request anything on this axis so take everything // we didn't request anything on this axis so take everything
return true; return true;
} }
const SortedVector<uint32_t>& sv = mData.valueAt(index); const SortedVector<AxisValue>& sv = mData.valueAt(index);
return sv.indexOf(value) >= 0; return sv.indexOf(value) >= 0;
} }
@ -102,7 +107,7 @@ ResourceFilter::match(const ResTable_config& config) const
return true; return true;
} }
const SortedVector<uint32_t>* ResourceFilter::configsForAxis(int axis) const const SortedVector<AxisValue>* ResourceFilter::configsForAxis(int axis) const
{ {
ssize_t index = mData.indexOfKey(axis); ssize_t index = mData.indexOfKey(axis);
if (index < 0) { if (index < 0) {

View File

@ -19,14 +19,15 @@ public:
ResourceFilter() : mData(), mContainsPseudo(false) {} ResourceFilter() : mData(), mContainsPseudo(false) {}
status_t parse(const char* arg); status_t parse(const char* arg);
bool isEmpty() const; bool isEmpty() const;
bool match(int axis, uint32_t value) const;
bool match(int axis, const ResTable_config& config) const; bool match(int axis, const ResTable_config& config) const;
bool match(const ResTable_config& config) const; bool match(const ResTable_config& config) const;
const SortedVector<uint32_t>* configsForAxis(int axis) const; const SortedVector<AxisValue>* configsForAxis(int axis) const;
inline bool containsPseudo() const { return mContainsPseudo; } inline bool containsPseudo() const { return mContainsPseudo; }
private: private:
KeyedVector<int,SortedVector<uint32_t> > mData; bool match(int axis, const AxisValue& value) const;
KeyedVector<int,SortedVector<AxisValue> > mData;
bool mContainsPseudo; bool mContainsPseudo;
}; };

View File

@ -7,7 +7,6 @@
#define RESOURCE_ID_CACHE_H #define RESOURCE_ID_CACHE_H
namespace android { namespace android {
class android::String16;
class ResourceIdCache { class ResourceIdCache {
public: public:

View File

@ -1292,8 +1292,8 @@ status_t compileResourceFile(Bundle* bundle,
curIsStyled = true; curIsStyled = true;
} else if (strcmp16(block.getElementName(&len), string16.string()) == 0) { } else if (strcmp16(block.getElementName(&len), string16.string()) == 0) {
// Note the existence and locale of every string we process // Note the existence and locale of every string we process
char rawLocale[16]; char rawLocale[RESTABLE_MAX_LOCALE_LEN];
curParams.getLocale(rawLocale); curParams.getBcp47Locale(rawLocale);
String8 locale(rawLocale); String8 locale(rawLocale);
String16 name; String16 name;
String16 translatable; String16 translatable;