diff options
Diffstat (limited to 'tools')
21 files changed, 678 insertions, 387 deletions
diff --git a/tools/aapt/AaptAssets.cpp b/tools/aapt/AaptAssets.cpp index 729a048..1f17316 100644 --- a/tools/aapt/AaptAssets.cpp +++ b/tools/aapt/AaptAssets.cpp @@ -149,205 +149,506 @@ static bool isHidden(const char *root, const char *path) // ========================================================================= // ========================================================================= -status_t -AaptGroupEntry::parseNamePart(const String8& part, int* axis, uint32_t* value) +/* static */ void AaptLocaleValue::splitAndLowerCase(const char* const chars, + 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; + memset(&config, 0, sizeof(ResTable_config)); // IMSI - MCC if (getMccName(part.string(), &config)) { *axis = AXIS_MCC; - *value = config.mcc; - return 0; + value->intValue = config.mcc; + return true; } // IMSI - MNC if (getMncName(part.string(), &config)) { *axis = AXIS_MNC; - *value = config.mnc; - return 0; + value->intValue = config.mnc; + return true; } // locale - language - if (part.length() == 2 && isalpha(part[0]) && isalpha(part[1])) { - *axis = AXIS_LANGUAGE; - *value = part[1] << 8 | part[0]; - 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; + if (value->localeValue.initFromFilterString(part)) { + *axis = AXIS_LOCALE; + return true; } // layout direction if (getLayoutDirectionName(part.string(), &config)) { *axis = AXIS_LAYOUTDIR; - *value = (config.screenLayout&ResTable_config::MASK_LAYOUTDIR); - return 0; + value->intValue = (config.screenLayout&ResTable_config::MASK_LAYOUTDIR); + return true; } // smallest screen dp width if (getSmallestScreenWidthDpName(part.string(), &config)) { *axis = AXIS_SMALLESTSCREENWIDTHDP; - *value = config.smallestScreenWidthDp; - return 0; + value->intValue = config.smallestScreenWidthDp; + return true; } // screen dp width if (getScreenWidthDpName(part.string(), &config)) { *axis = AXIS_SCREENWIDTHDP; - *value = config.screenWidthDp; - return 0; + value->intValue = config.screenWidthDp; + return true; } // screen dp height if (getScreenHeightDpName(part.string(), &config)) { *axis = AXIS_SCREENHEIGHTDP; - *value = config.screenHeightDp; - return 0; + value->intValue = config.screenHeightDp; + return true; } // screen layout size if (getScreenLayoutSizeName(part.string(), &config)) { *axis = AXIS_SCREENLAYOUTSIZE; - *value = (config.screenLayout&ResTable_config::MASK_SCREENSIZE); - return 0; + value->intValue = (config.screenLayout&ResTable_config::MASK_SCREENSIZE); + return true; } // screen layout long if (getScreenLayoutLongName(part.string(), &config)) { *axis = AXIS_SCREENLAYOUTLONG; - *value = (config.screenLayout&ResTable_config::MASK_SCREENLONG); - return 0; + value->intValue = (config.screenLayout&ResTable_config::MASK_SCREENLONG); + return true; } // orientation if (getOrientationName(part.string(), &config)) { *axis = AXIS_ORIENTATION; - *value = config.orientation; - return 0; + value->intValue = config.orientation; + return true; } // ui mode type if (getUiModeTypeName(part.string(), &config)) { *axis = AXIS_UIMODETYPE; - *value = (config.uiMode&ResTable_config::MASK_UI_MODE_TYPE); - return 0; + value->intValue = (config.uiMode&ResTable_config::MASK_UI_MODE_TYPE); + return true; } // ui mode night if (getUiModeNightName(part.string(), &config)) { *axis = AXIS_UIMODENIGHT; - *value = (config.uiMode&ResTable_config::MASK_UI_MODE_NIGHT); - return 0; + value->intValue = (config.uiMode&ResTable_config::MASK_UI_MODE_NIGHT); + return true; } // density if (getDensityName(part.string(), &config)) { *axis = AXIS_DENSITY; - *value = config.density; - return 0; + value->intValue = config.density; + return true; } // touchscreen if (getTouchscreenName(part.string(), &config)) { *axis = AXIS_TOUCHSCREEN; - *value = config.touchscreen; - return 0; + value->intValue = config.touchscreen; + return true; } // keyboard hidden if (getKeysHiddenName(part.string(), &config)) { *axis = AXIS_KEYSHIDDEN; - *value = config.inputFlags; - return 0; + value->intValue = config.inputFlags; + return true; } // keyboard if (getKeyboardName(part.string(), &config)) { *axis = AXIS_KEYBOARD; - *value = config.keyboard; - return 0; + value->intValue = config.keyboard; + return true; } // navigation hidden if (getNavHiddenName(part.string(), &config)) { *axis = AXIS_NAVHIDDEN; - *value = config.inputFlags; + value->intValue = config.inputFlags; return 0; } // navigation if (getNavigationName(part.string(), &config)) { *axis = AXIS_NAVIGATION; - *value = config.navigation; - return 0; + value->intValue = config.navigation; + return true; } // screen size if (getScreenSizeName(part.string(), &config)) { *axis = AXIS_SCREENSIZE; - *value = config.screenSize; - return 0; + value->intValue = config.screenSize; + return true; } // version if (getVersionName(part.string(), &config)) { *axis = AXIS_VERSION; - *value = config.version; - return 0; + value->intValue = config.version; + return true; } - return 1; + return false; } -uint32_t +AxisValue AaptGroupEntry::getConfigValueForAxis(const ResTable_config& config, int axis) { + AxisValue value; switch (axis) { case AXIS_MCC: - return config.mcc; + value.intValue = config.mcc; + break; case AXIS_MNC: - return config.mnc; - case AXIS_LANGUAGE: - return (((uint32_t)config.country[1]) << 24) | (((uint32_t)config.country[0]) << 16) - | (((uint32_t)config.language[1]) << 8) | (config.language[0]); + value.intValue = config.mnc; + break; + case AXIS_LOCALE: + value.localeValue.initFromResTable(config); + break; case AXIS_LAYOUTDIR: - return config.screenLayout&ResTable_config::MASK_LAYOUTDIR; + value.intValue = config.screenLayout&ResTable_config::MASK_LAYOUTDIR; + break; case AXIS_SCREENLAYOUTSIZE: - return config.screenLayout&ResTable_config::MASK_SCREENSIZE; + value.intValue = config.screenLayout&ResTable_config::MASK_SCREENSIZE; + break; case AXIS_ORIENTATION: - return config.orientation; + value.intValue = config.orientation; + break; 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: - return (config.uiMode&ResTable_config::MASK_UI_MODE_NIGHT); + value.intValue = (config.uiMode&ResTable_config::MASK_UI_MODE_NIGHT); + break; case AXIS_DENSITY: - return config.density; + value.intValue = config.density; + break; case AXIS_TOUCHSCREEN: - return config.touchscreen; + value.intValue = config.touchscreen; + break; case AXIS_KEYSHIDDEN: - return config.inputFlags; + value.intValue = config.inputFlags; + break; case AXIS_KEYBOARD: - return config.keyboard; + value.intValue = config.keyboard; + break; case AXIS_NAVIGATION: - return config.navigation; + value.intValue = config.navigation; + break; case AXIS_SCREENSIZE: - return config.screenSize; + value.intValue = config.screenSize; + break; case AXIS_SMALLESTSCREENWIDTHDP: - return config.smallestScreenWidthDp; + value.intValue = config.smallestScreenWidthDp; + break; case AXIS_SCREENWIDTHDP: - return config.screenWidthDp; + value.intValue = config.screenWidthDp; + break; case AXIS_SCREENHEIGHTDP: - return config.screenHeightDp; + value.intValue = config.screenHeightDp; + break; case AXIS_VERSION: - return config.version; + value.intValue = config.version; + break; } - return 0; + + return value; } bool @@ -371,24 +672,14 @@ AaptGroupEntry::initFromDirName(const char* dir, String8* resType) mParamsChanged = true; 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 uiModeType, uiModeNight, smallestwidthdp, widthdp, heightdp; - const char *p = dir; - const char *q; - 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()); + AaptLocaleValue locale; + int numLocaleComponents = 0; const int N = parts.size(); int index = 0; @@ -429,38 +720,18 @@ AaptGroupEntry::initFromDirName(const char* dir, String8* resType) } part = parts[index]; } else { - //printf("not mcc: %s\n", part.string()); + //printf("not mnc: %s\n", part.string()); } - // locale - language - if (part.length() == 2 && isalpha(part[0]) && isalpha(part[1])) { - loc = part; - - index++; - if (index == N) { - goto success; - } - part = parts[index]; - } else { - //printf("not language: %s\n", part.string()); + index = locale.initFromDirName(parts, index); + if (index == -1) { + return false; } - - // 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 (index >= N){ + goto success; } + part = parts[index]; if (getLayoutDirectionName(part.string())) { layoutDir = part; @@ -679,7 +950,7 @@ AaptGroupEntry::initFromDirName(const char* dir, String8* resType) success: this->mcc = mcc; this->mnc = mnc; - this->locale = loc; + this->locale = locale; this->screenLayoutSize = layoutsize; this->screenLayoutLong = layoutlong; this->smallestScreenWidthDp = smallestwidthdp; @@ -711,7 +982,7 @@ AaptGroupEntry::toString() const s += ","; s += this->mnc; s += ","; - s += this->locale; + s += locale.toDirName(); s += ","; s += layoutDirection; s += ","; @@ -765,12 +1036,15 @@ AaptGroupEntry::toDirName(const String8& resType) const } s += mnc; } - if (this->locale != "") { - if (s.length() > 0) { - s += "-"; - } - s += locale; + + const String8 localeComponent = locale.toDirName(); + if (localeComponent != "") { + if (s.length() > 0) { + s += "-"; + } + s += localeComponent; } + if (this->layoutDirection != "") { if (s.length() > 0) { s += "-"; @@ -942,55 +1216,6 @@ bool AaptGroupEntry::getMncName(const char* name, 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) { if (strcmp(name, kWildcardName) == 0) { @@ -1501,18 +1726,18 @@ int AaptGroupEntry::compare(const AaptGroupEntry& o) const return v; } -const ResTable_config& AaptGroupEntry::toParams() const +const ResTable_config AaptGroupEntry::toParams() const { if (!mParamsChanged) { return mParams; } mParamsChanged = false; - ResTable_config& params(mParams); - memset(¶ms, 0, sizeof(params)); + ResTable_config& params = mParams; + memset(¶ms, 0, sizeof(ResTable_config)); getMccName(mcc.string(), ¶ms); getMncName(mnc.string(), ¶ms); - getLocaleName(locale.string(), ¶ms); + locale.writeTo(¶ms); getLayoutDirectionName(layoutDirection.string(), ¶ms); getSmallestScreenWidthDpName(smallestScreenWidthDp.string(), ¶ms); getScreenWidthDpName(screenWidthDp.string(), ¶ms); @@ -1997,7 +2222,9 @@ status_t AaptSymbols::applyJavaSymbols(const sp<AaptSymbols>& javaSymbols) AaptAssets::AaptAssets() : AaptDir(String8(), String8()), - mChanged(false), mHaveIncludedAssets(false), mRes(NULL) + mHavePrivateSymbols(false), + mChanged(false), mHaveIncludedAssets(false), + mRes(NULL) { } @@ -2507,9 +2734,9 @@ status_t AaptAssets::filter(Bundle* bundle) // If our preferred density is hdpi but we only have mdpi and xhdpi resources, we // pick xhdpi. 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) { - preferredDensity = (*preferredConfigs)[0]; + preferredDensity = (*preferredConfigs)[0].intValue; } // Now deal with preferred configurations. @@ -2667,7 +2894,7 @@ status_t AaptAssets::addIncludedResources(const sp<AaptFile>& file) { const ResTable& res = getIncludedResources(); // XXX dirty! - return const_cast<ResTable&>(res).add(file->getData(), file->getSize(), NULL); + return const_cast<ResTable&>(res).add(file->getData(), file->getSize()); } const ResTable& AaptAssets::getIncludedResources() const diff --git a/tools/aapt/AaptAssets.h b/tools/aapt/AaptAssets.h index 9cc9007..336d08b 100644 --- a/tools/aapt/AaptAssets.h +++ b/tools/aapt/AaptAssets.h @@ -13,7 +13,6 @@ #include <utils/RefBase.h> #include <utils/SortedVector.h> #include <utils/String8.h> -#include <utils/String8.h> #include <utils/Vector.h> #include "ZipFile.h" @@ -34,8 +33,7 @@ enum { AXIS_NONE = 0, AXIS_MCC = 1, AXIS_MNC, - AXIS_LANGUAGE, - AXIS_REGION, + AXIS_LOCALE, AXIS_SCREENLAYOUTSIZE, AXIS_SCREENLAYOUTLONG, AXIS_ORIENTATION, @@ -58,6 +56,73 @@ enum { 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 * of all the variations it can have that we can have. @@ -65,22 +130,38 @@ enum { struct AaptGroupEntry { public: - AaptGroupEntry() : mParamsChanged(true) { } - AaptGroupEntry(const String8& _locale, const String8& _vendor) - : locale(_locale), vendor(_vendor), mParamsChanged(true) { } + AaptGroupEntry() : mParamsChanged(true) { + memset(&mParams, 0, sizeof(ResTable_config)); + } 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, 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 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 getScreenLayoutLongName(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 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 mnc; - String8 locale; + AaptLocaleValue locale; String8 vendor; String8 smallestScreenWidthDp; String8 screenWidthDp; diff --git a/tools/aapt/Command.cpp b/tools/aapt/Command.cpp index d9e2dc5..fe8bb68 100644 --- a/tools/aapt/Command.cpp +++ b/tools/aapt/Command.cpp @@ -518,6 +518,7 @@ int doDump(Bundle* bundle) // the API version because key resources like icons will have an implicit // version if they are using newer config types like density. ResTable_config config; + memset(&config, 0, sizeof(ResTable_config)); config.language[0] = 'e'; config.language[1] = 'n'; config.country[0] = 'U'; diff --git a/tools/aapt/Images.cpp b/tools/aapt/Images.cpp index 25a948d..db74831 100644 --- a/tools/aapt/Images.cpp +++ b/tools/aapt/Images.cpp @@ -35,7 +35,9 @@ png_flush_aapt_file(png_structp png_ptr) // This holds an image as 8bpp RGBA. struct image_info { - image_info() : rows(NULL), is9Patch(false), allocRows(NULL) { } + image_info() : rows(NULL), is9Patch(false), + xDivs(NULL), yDivs(NULL), colors(NULL), allocRows(NULL) { } + ~image_info() { if (rows && rows != allocRows) { free(rows); @@ -46,9 +48,15 @@ struct image_info } free(allocRows); } - free(info9Patch.xDivs); - free(info9Patch.yDivs); - free(info9Patch.colors); + free(xDivs); + free(yDivs); + free(colors); + } + + void* serialize9patch() { + void* serialized = Res_png_9patch::serialize(info9Patch, xDivs, yDivs, colors); + reinterpret_cast<Res_png_9patch*>(serialized)->deviceToFile(); + return serialized; } png_uint_32 width; @@ -58,6 +66,9 @@ struct image_info // 9-patch info. bool is9Patch; Res_png_9patch info9Patch; + int32_t* xDivs; + int32_t* yDivs; + uint32_t* colors; // Layout padding, if relevant bool haveLayoutBounds; @@ -430,10 +441,10 @@ static uint32_t get_color(image_info* image, int hpatch, int vpatch) { int left, right, top, bottom; select_patch( - hpatch, image->info9Patch.xDivs[0], image->info9Patch.xDivs[1], + hpatch, image->xDivs[0], image->xDivs[1], image->width, &left, &right); select_patch( - vpatch, image->info9Patch.yDivs[0], image->info9Patch.yDivs[1], + vpatch, image->yDivs[0], image->yDivs[1], image->height, &top, &bottom); //printf("Selecting h=%d v=%d: (%d,%d)-(%d,%d)\n", // hpatch, vpatch, left, top, right, bottom); @@ -452,8 +463,8 @@ static status_t do_9patch(const char* imageName, image_info* image) int maxSizeXDivs = W * sizeof(int32_t); int maxSizeYDivs = H * sizeof(int32_t); - int32_t* xDivs = image->info9Patch.xDivs = (int32_t*) malloc(maxSizeXDivs); - int32_t* yDivs = image->info9Patch.yDivs = (int32_t*) malloc(maxSizeYDivs); + int32_t* xDivs = image->xDivs = (int32_t*) malloc(maxSizeXDivs); + int32_t* yDivs = image->yDivs = (int32_t*) malloc(maxSizeYDivs); uint8_t numXDivs = 0; uint8_t numYDivs = 0; @@ -609,7 +620,7 @@ static status_t do_9patch(const char* imageName, image_info* image) numColors = numRows * numCols; image->info9Patch.numColors = numColors; - image->info9Patch.colors = (uint32_t*)malloc(numColors * sizeof(uint32_t)); + image->colors = (uint32_t*)malloc(numColors * sizeof(uint32_t)); // Fill in color information for each patch. @@ -652,7 +663,7 @@ static status_t do_9patch(const char* imageName, image_info* image) right = xDivs[i]; } c = get_color(image->rows, left, top, right - 1, bottom - 1); - image->info9Patch.colors[colorIndex++] = c; + image->colors[colorIndex++] = c; NOISY(if (c != Res_png_9patch::NO_COLOR) hasColor = true); left = right; } @@ -664,14 +675,10 @@ static status_t do_9patch(const char* imageName, image_info* image) for (i=0; i<numColors; i++) { if (hasColor) { if (i == 0) printf("Colors in %s:\n ", imageName); - printf(" #%08x", image->info9Patch.colors[i]); + printf(" #%08x", image->colors[i]); if (i == numColors - 1) printf("\n"); } } - - image->is9Patch = true; - image->info9Patch.deviceToFile(); - getout: if (errorMsg) { fprintf(stderr, @@ -691,14 +698,10 @@ getout: return NO_ERROR; } -static void checkNinePatchSerialization(Res_png_9patch* inPatch, void * data) +static void checkNinePatchSerialization(Res_png_9patch* inPatch, void* data) { - if (sizeof(void*) != sizeof(int32_t)) { - // can't deserialize on a non-32 bit system - return; - } size_t patchSize = inPatch->serializedSize(); - void * newData = malloc(patchSize); + void* newData = malloc(patchSize); memcpy(newData, data, patchSize); Res_png_9patch* outPatch = inPatch->deserialize(newData); // deserialization is done in place, so outPatch == newData @@ -721,34 +724,6 @@ static void checkNinePatchSerialization(Res_png_9patch* inPatch, void * data) free(newData); } -static bool patch_equals(Res_png_9patch& patch1, Res_png_9patch& patch2) { - if (!(patch1.numXDivs == patch2.numXDivs && - patch1.numYDivs == patch2.numYDivs && - patch1.numColors == patch2.numColors && - patch1.paddingLeft == patch2.paddingLeft && - patch1.paddingRight == patch2.paddingRight && - patch1.paddingTop == patch2.paddingTop && - patch1.paddingBottom == patch2.paddingBottom)) { - return false; - } - for (int i = 0; i < patch1.numColors; i++) { - if (patch1.colors[i] != patch2.colors[i]) { - return false; - } - } - for (int i = 0; i < patch1.numXDivs; i++) { - if (patch1.xDivs[i] != patch2.xDivs[i]) { - return false; - } - } - for (int i = 0; i < patch1.numYDivs; i++) { - if (patch1.yDivs[i] != patch2.yDivs[i]) { - return false; - } - } - return true; -} - static void dump_image(int w, int h, png_bytepp rows, int color_type) { int i, j, rr, gg, bb, aa; @@ -1061,7 +1036,7 @@ static void write_png(const char* imageName, : (png_byte*)"npTc"; NOISY(printf("Adding 9-patch info...\n")); strcpy((char*)unknowns[p_index].name, "npTc"); - unknowns[p_index].data = (png_byte*)imageInfo.info9Patch.serialize(); + unknowns[p_index].data = (png_byte*)imageInfo.serialize9patch(); unknowns[p_index].size = imageInfo.info9Patch.serializedSize(); // TODO: remove the check below when everything works checkNinePatchSerialization(&imageInfo.info9Patch, unknowns[p_index].data); diff --git a/tools/aapt/Resource.cpp b/tools/aapt/Resource.cpp index 386888b..4d29ff7 100644 --- a/tools/aapt/Resource.cpp +++ b/tools/aapt/Resource.cpp @@ -80,6 +80,7 @@ public: ResourceDirIterator(const sp<ResourceTypeSet>& set, const String8& resType) : mResType(resType), mSet(set), mSetPos(0), mGroupPos(0) { + memset(&mParams, 0, sizeof(ResTable_config)); } inline const sp<AaptGroup>& getGroup() const { return mGroup; } @@ -1320,8 +1321,7 @@ status_t buildResources(Bundle* bundle, const sp<AaptAssets>& assets) } // Read resources back in, - finalResTable.add(resFile->getData(), resFile->getSize(), NULL); - + finalResTable.add(resFile->getData(), resFile->getSize()); #if 0 NOISY( printf("Generated resources:\n"); diff --git a/tools/aapt/ResourceFilter.cpp b/tools/aapt/ResourceFilter.cpp index 8cfd2a5..e8a2be4 100644 --- a/tools/aapt/ResourceFilter.cpp +++ b/tools/aapt/ResourceFilter.cpp @@ -28,8 +28,8 @@ ResourceFilter::parse(const char* arg) mContainsPseudo = true; } int axis; - uint32_t value; - if (AaptGroupEntry::parseNamePart(part, &axis, &value)) { + AxisValue value; + if (!AaptGroupEntry::parseFilterNamePart(part, &axis, &value)) { fprintf(stderr, "Invalid configuration: %s\n", arg); fprintf(stderr, " "); for (int i=0; i<p-arg; i++) { @@ -44,15 +44,20 @@ ResourceFilter::parse(const char* arg) ssize_t index = mData.indexOfKey(axis); 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); - // if it's a locale with a region, also match an unmodified locale of the - // same language - if (axis == AXIS_LANGUAGE) { - if (value & 0xffff0000) { - sv.add(value & 0x0000ffff); + + // If it's a locale with a region, script or variant, we should also match an + // unmodified locale of the same language + if (axis == AXIS_LOCALE) { + 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; @@ -70,9 +75,9 @@ ResourceFilter::isEmpty() const } 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 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 return true; } - const SortedVector<uint32_t>& sv = mData.valueAt(index); + const SortedVector<AxisValue>& sv = mData.valueAt(index); return sv.indexOf(value) >= 0; } @@ -102,7 +107,7 @@ ResourceFilter::match(const ResTable_config& config) const 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); if (index < 0) { diff --git a/tools/aapt/ResourceFilter.h b/tools/aapt/ResourceFilter.h index 647b7bb..0d127ba 100644 --- a/tools/aapt/ResourceFilter.h +++ b/tools/aapt/ResourceFilter.h @@ -19,14 +19,15 @@ public: ResourceFilter() : mData(), mContainsPseudo(false) {} status_t parse(const char* arg); bool isEmpty() const; - bool match(int axis, uint32_t value) const; bool match(int axis, 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; } private: - KeyedVector<int,SortedVector<uint32_t> > mData; + bool match(int axis, const AxisValue& value) const; + + KeyedVector<int,SortedVector<AxisValue> > mData; bool mContainsPseudo; }; diff --git a/tools/aapt/ResourceIdCache.h b/tools/aapt/ResourceIdCache.h index 65f7781..e6bcda2 100644 --- a/tools/aapt/ResourceIdCache.h +++ b/tools/aapt/ResourceIdCache.h @@ -7,7 +7,6 @@ #define RESOURCE_ID_CACHE_H namespace android { -class android::String16; class ResourceIdCache { public: diff --git a/tools/aapt/ResourceTable.cpp b/tools/aapt/ResourceTable.cpp index 6ced8b3..0b1f985 100644 --- a/tools/aapt/ResourceTable.cpp +++ b/tools/aapt/ResourceTable.cpp @@ -1292,8 +1292,8 @@ status_t compileResourceFile(Bundle* bundle, curIsStyled = true; } else if (strcmp16(block.getElementName(&len), string16.string()) == 0) { // Note the existence and locale of every string we process - char rawLocale[16]; - curParams.getLocale(rawLocale); + char rawLocale[RESTABLE_MAX_LOCALE_LEN]; + curParams.getBcp47Locale(rawLocale); String8 locale(rawLocale); String16 name; String16 translatable; @@ -1317,9 +1317,9 @@ status_t compileResourceFile(Bundle* bundle, curIsFormatted = false; // Untranslatable strings must only exist in the default [empty] locale if (locale.size() > 0) { - fprintf(stderr, "aapt: warning: string '%s' in %s marked untranslatable but exists" - " in locale '%s'\n", String8(name).string(), - bundle->getResourceSourceDirs()[0], + SourcePos(in->getPrintableSource(), block.getLineNumber()).warning( + "string '%s' marked untranslatable but exists in locale '%s'\n", + String8(name).string(), locale.string()); // hasErrors = localHasErrors = true; } else { @@ -1330,7 +1330,10 @@ status_t compileResourceFile(Bundle* bundle, // having no default translation. } } else { - outTable->addLocalization(name, locale); + outTable->addLocalization( + name, + locale, + SourcePos(in->getPrintableSource(), block.getLineNumber())); } if (formatted == false16) { @@ -2570,9 +2573,9 @@ status_t ResourceTable::addSymbols(const sp<AaptSymbols>& outSymbols) { void -ResourceTable::addLocalization(const String16& name, const String8& locale) +ResourceTable::addLocalization(const String16& name, const String8& locale, const SourcePos& src) { - mLocalizations[name].insert(locale); + mLocalizations[name][locale] = src; } @@ -2592,21 +2595,22 @@ ResourceTable::validateLocalizations(void) const String8 defaultLocale; // For all strings... - for (map<String16, set<String8> >::iterator nameIter = mLocalizations.begin(); + for (map<String16, map<String8, SourcePos> >::iterator nameIter = mLocalizations.begin(); nameIter != mLocalizations.end(); nameIter++) { - const set<String8>& configSet = nameIter->second; // naming convenience + const map<String8, SourcePos>& configSrcMap = nameIter->second; // Look for strings with no default localization - if (configSet.count(defaultLocale) == 0) { - fprintf(stdout, "aapt: warning: string '%s' has no default translation in %s; found:", - String8(nameIter->first).string(), mBundle->getResourceSourceDirs()[0]); - for (set<String8>::const_iterator locales = configSet.begin(); - locales != configSet.end(); - locales++) { - fprintf(stdout, " %s", (*locales).string()); - } - fprintf(stdout, "\n"); + if (configSrcMap.count(defaultLocale) == 0) { + SourcePos().warning("string '%s' has no default translation.", + String8(nameIter->first).string()); + if (mBundle->getVerbose()) { + for (map<String8, SourcePos>::const_iterator locales = configSrcMap.begin(); + locales != configSrcMap.end(); + locales++) { + locales->second.printf("locale %s found", locales->first.string()); + } + } // !!! TODO: throw an error here in some circumstances } @@ -2616,6 +2620,8 @@ ResourceTable::validateLocalizations(void) const char* start = allConfigs; const char* comma; + set<String8> missingConfigs; + AaptLocaleValue locale; do { String8 config; comma = strchr(start, ','); @@ -2626,27 +2632,38 @@ ResourceTable::validateLocalizations(void) config.setTo(start); } + if (!locale.initFromFilterString(config)) { + continue; + } + // don't bother with the pseudolocale "zz_ZZ" if (config != "zz_ZZ") { - if (configSet.find(config) == configSet.end()) { + if (configSrcMap.find(config) == configSrcMap.end()) { // okay, no specific localization found. it's possible that we are // requiring a specific regional localization [e.g. de_DE] but there is an // available string in the generic language localization [e.g. de]; // consider that string to have fulfilled the localization requirement. String8 region(config.string(), 2); - if (configSet.find(region) == configSet.end()) { - if (configSet.count(defaultLocale) == 0) { - fprintf(stdout, "aapt: warning: " - "**** string '%s' has no default or required localization " - "for '%s' in %s\n", - String8(nameIter->first).string(), - config.string(), - mBundle->getResourceSourceDirs()[0]); - } + if (configSrcMap.find(region) == configSrcMap.end() && + configSrcMap.count(defaultLocale) == 0) { + missingConfigs.insert(config); } } } - } while (comma != NULL); + } while (comma != NULL); + + if (!missingConfigs.empty()) { + String8 configStr; + for (set<String8>::iterator iter = missingConfigs.begin(); + iter != missingConfigs.end(); + iter++) { + configStr.appendFormat(" %s", iter->string()); + } + SourcePos().warning("string '%s' is missing %u required localizations:%s", + String8(nameIter->first).string(), + (unsigned int)missingConfigs.size(), + configStr.string()); + } } } diff --git a/tools/aapt/ResourceTable.h b/tools/aapt/ResourceTable.h index a3e0666..75005cd 100644 --- a/tools/aapt/ResourceTable.h +++ b/tools/aapt/ResourceTable.h @@ -220,7 +220,7 @@ public: status_t assignResourceIds(); status_t addSymbols(const sp<AaptSymbols>& outSymbols = NULL); - void addLocalization(const String16& name, const String8& locale); + void addLocalization(const String16& name, const String8& locale, const SourcePos& src); status_t validateLocalizations(void); status_t flatten(Bundle*, const sp<AaptFile>& dest); @@ -551,7 +551,7 @@ private: Bundle* mBundle; // key = string resource name, value = set of locales in which that name is defined - map<String16, set<String8> > mLocalizations; + map<String16, map<String8, SourcePos> > mLocalizations; }; #endif diff --git a/tools/aapt/SourcePos.cpp b/tools/aapt/SourcePos.cpp index e2a921c..ae25047 100644 --- a/tools/aapt/SourcePos.cpp +++ b/tools/aapt/SourcePos.cpp @@ -10,17 +10,20 @@ using namespace std; // ============================================================================= struct ErrorPos { + enum Level { + NOTE, + WARNING, + ERROR + }; + String8 file; int line; String8 error; - bool fatal; + Level level; ErrorPos(); ErrorPos(const ErrorPos& that); - ErrorPos(const String8& file, int line, const String8& error, bool fatal); - ~ErrorPos(); - bool operator<(const ErrorPos& rhs) const; - bool operator==(const ErrorPos& rhs) const; + ErrorPos(const String8& file, int line, const String8& error, Level level); ErrorPos& operator=(const ErrorPos& rhs); void print(FILE* to) const; @@ -29,7 +32,7 @@ struct ErrorPos static vector<ErrorPos> g_errors; ErrorPos::ErrorPos() - :line(-1), fatal(false) + :line(-1), level(NOTE) { } @@ -37,41 +40,16 @@ ErrorPos::ErrorPos(const ErrorPos& that) :file(that.file), line(that.line), error(that.error), - fatal(that.fatal) + level(that.level) { } -ErrorPos::ErrorPos(const String8& f, int l, const String8& e, bool fat) +ErrorPos::ErrorPos(const String8& f, int l, const String8& e, Level lev) :file(f), line(l), error(e), - fatal(fat) -{ -} - -ErrorPos::~ErrorPos() -{ -} - -bool -ErrorPos::operator<(const ErrorPos& rhs) const -{ - if (this->file < rhs.file) return true; - if (this->file == rhs.file) { - if (this->line < rhs.line) return true; - if (this->line == rhs.line) { - if (this->error < rhs.error) return true; - } - } - return false; -} - -bool -ErrorPos::operator==(const ErrorPos& rhs) const + level(lev) { - return this->file == rhs.file - && this->line == rhs.line - && this->error == rhs.error; } ErrorPos& @@ -80,18 +58,34 @@ ErrorPos::operator=(const ErrorPos& rhs) this->file = rhs.file; this->line = rhs.line; this->error = rhs.error; + this->level = rhs.level; return *this; } void ErrorPos::print(FILE* to) const { - const char* type = fatal ? "error:" : "warning:"; + const char* type = ""; + switch (level) { + case NOTE: + type = "note: "; + break; + case WARNING: + type = "warning: "; + break; + case ERROR: + type = "error: "; + break; + } - if (this->line >= 0) { - fprintf(to, "%s:%d: %s %s\n", this->file.string(), this->line, type, this->error.string()); + if (!this->file.isEmpty()) { + if (this->line >= 0) { + fprintf(to, "%s:%d: %s%s\n", this->file.string(), this->line, type, this->error.string()); + } else { + fprintf(to, "%s: %s%s\n", this->file.string(), type, this->error.string()); + } } else { - fprintf(to, "%s: %s %s\n", this->file.string(), type, this->error.string()); + fprintf(to, "%s%s\n", type, this->error.string()); } } @@ -116,40 +110,34 @@ SourcePos::~SourcePos() { } -int +void SourcePos::error(const char* fmt, ...) const { - int retval=0; - char buf[1024]; va_list ap; va_start(ap, fmt); - retval = vsnprintf(buf, sizeof(buf), fmt, ap); + String8 msg = String8::formatV(fmt, ap); va_end(ap); - char* p = buf + retval - 1; - while (p > buf && *p == '\n') { - *p = '\0'; - p--; - } - g_errors.push_back(ErrorPos(this->file, this->line, String8(buf), true)); - return retval; + g_errors.push_back(ErrorPos(this->file, this->line, msg, ErrorPos::ERROR)); } -int +void SourcePos::warning(const char* fmt, ...) const { - int retval=0; - char buf[1024]; va_list ap; va_start(ap, fmt); - retval = vsnprintf(buf, sizeof(buf), fmt, ap); + String8 msg = String8::formatV(fmt, ap); va_end(ap); - char* p = buf + retval - 1; - while (p > buf && *p == '\n') { - *p = '\0'; - p--; - } - ErrorPos(this->file, this->line, String8(buf), false).print(stderr); - return retval; + ErrorPos(this->file, this->line, msg, ErrorPos::WARNING).print(stderr); +} + +void +SourcePos::printf(const char* fmt, ...) const +{ + va_list ap; + va_start(ap, fmt); + String8 msg = String8::formatV(fmt, ap); + va_end(ap); + ErrorPos(this->file, this->line, msg, ErrorPos::NOTE).print(stderr); } bool diff --git a/tools/aapt/SourcePos.h b/tools/aapt/SourcePos.h index 33f72a9..4ce817f 100644 --- a/tools/aapt/SourcePos.h +++ b/tools/aapt/SourcePos.h @@ -17,8 +17,9 @@ public: SourcePos(); ~SourcePos(); - int error(const char* fmt, ...) const; - int warning(const char* fmt, ...) const; + void error(const char* fmt, ...) const; + void warning(const char* fmt, ...) const; + void printf(const char* fmt, ...) const; static bool hasErrors(); static void printErrors(FILE* to); diff --git a/tools/aidl/Type.cpp b/tools/aidl/Type.cpp index d572af6..2267750 100644 --- a/tools/aidl/Type.cpp +++ b/tools/aidl/Type.cpp @@ -1,5 +1,7 @@ #include "Type.h" +#include <sys/types.h> + Namespace NAMES; Type* VOID_TYPE; diff --git a/tools/layoutlib/bridge/src/android/animation/PropertyValuesHolder_Delegate.java b/tools/layoutlib/bridge/src/android/animation/PropertyValuesHolder_Delegate.java index 7b444aa..224eac6 100644 --- a/tools/layoutlib/bridge/src/android/animation/PropertyValuesHolder_Delegate.java +++ b/tools/layoutlib/bridge/src/android/animation/PropertyValuesHolder_Delegate.java @@ -36,24 +36,24 @@ import com.android.tools.layoutlib.annotations.LayoutlibDelegate; /*package*/ class PropertyValuesHolder_Delegate { @LayoutlibDelegate - /*package*/ static int nGetIntMethod(Class<?> targetClass, String methodName) { + /*package*/ static long nGetIntMethod(Class<?> targetClass, String methodName) { // return 0 to force PropertyValuesHolder to use Java reflection. return 0; } @LayoutlibDelegate - /*package*/ static int nGetFloatMethod(Class<?> targetClass, String methodName) { + /*package*/ static long nGetFloatMethod(Class<?> targetClass, String methodName) { // return 0 to force PropertyValuesHolder to use Java reflection. return 0; } @LayoutlibDelegate - /*package*/ static void nCallIntMethod(Object target, int methodID, int arg) { + /*package*/ static void nCallIntMethod(Object target, long methodID, int arg) { // do nothing } @LayoutlibDelegate - /*package*/ static void nCallFloatMethod(Object target, int methodID, float arg) { + /*package*/ static void nCallFloatMethod(Object target, long methodID, float arg) { // do nothing } } diff --git a/tools/layoutlib/bridge/src/android/graphics/BitmapFactory_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/BitmapFactory_Delegate.java index d85c3d1..06673c1 100644 --- a/tools/layoutlib/bridge/src/android/graphics/BitmapFactory_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/BitmapFactory_Delegate.java @@ -102,7 +102,7 @@ import java.util.Set; } @LayoutlibDelegate - /*package*/ static Bitmap nativeDecodeAsset(int asset, Rect padding, Options opts) { + /*package*/ static Bitmap nativeDecodeAsset(long asset, Rect padding, Options opts) { opts.inBitmap = null; return null; } diff --git a/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java index 9d21866..73d274c 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java @@ -786,7 +786,7 @@ public final class Canvas_Delegate { } @LayoutlibDelegate - /*package*/ static void native_drawPath(long nativeCanvas, int path, long paint) { + /*package*/ static void native_drawPath(long nativeCanvas, long path, long paint) { final Path_Delegate pathDelegate = Path_Delegate.getDelegate(path); if (pathDelegate == null) { return; diff --git a/tools/layoutlib/bridge/src/android/graphics/Matrix_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Matrix_Delegate.java index 1d66586..ebfe9bc 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Matrix_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/Matrix_Delegate.java @@ -654,7 +654,7 @@ public final class Matrix_Delegate { } @LayoutlibDelegate - /*package*/ static boolean native_invert(long native_object, int inverse) { + /*package*/ static boolean native_invert(long native_object, long inverse) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { return false; diff --git a/tools/layoutlib/bridge/src/android/graphics/Path_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Path_Delegate.java index 4e9c129..6f6ef20 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Path_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/Path_Delegate.java @@ -401,17 +401,17 @@ public final class Path_Delegate { } @LayoutlibDelegate - /*package*/ static void native_addPath(long nPath, int src, float dx, float dy) { + /*package*/ static void native_addPath(long nPath, long src, float dx, float dy) { addPath(nPath, src, AffineTransform.getTranslateInstance(dx, dy)); } @LayoutlibDelegate - /*package*/ static void native_addPath(long nPath, int src) { + /*package*/ static void native_addPath(long nPath, long src) { addPath(nPath, src, null /*transform*/); } @LayoutlibDelegate - /*package*/ static void native_addPath(long nPath, int src, long matrix) { + /*package*/ static void native_addPath(long nPath, long src, long matrix) { Matrix_Delegate matrixDelegate = Matrix_Delegate.getDelegate(matrix); if (matrixDelegate == null) { return; @@ -474,7 +474,7 @@ public final class Path_Delegate { } @LayoutlibDelegate - /*package*/ static boolean native_op(long nPath1, long nPath2, int op, int result) { + /*package*/ static boolean native_op(long nPath1, long nPath2, int op, long result) { Bridge.getLog().error(LayoutLog.TAG_UNSUPPORTED, "Path.op() not supported", null); return false; } diff --git a/tools/layoutlib/bridge/src/android/os/SystemClock_Delegate.java b/tools/layoutlib/bridge/src/android/os/SystemClock_Delegate.java index fd594f7..5f0d98b 100644 --- a/tools/layoutlib/bridge/src/android/os/SystemClock_Delegate.java +++ b/tools/layoutlib/bridge/src/android/os/SystemClock_Delegate.java @@ -33,11 +33,6 @@ public class SystemClock_Delegate { private static long sBootTime = System.currentTimeMillis(); private static long sBootTimeNano = System.nanoTime(); - @LayoutlibDelegate - /*package*/ static boolean setCurrentTimeMillis(long millis) { - return true; - } - /** * Returns milliseconds since boot, not counting time spent in deep sleep. * <b>Note:</b> This value may get reset occasionally (before it would diff --git a/tools/layoutlib/bridge/src/libcore/icu/ICU_Delegate.java b/tools/layoutlib/bridge/src/libcore/icu/ICU_Delegate.java index ad4103b..998b08b 100644 --- a/tools/layoutlib/bridge/src/libcore/icu/ICU_Delegate.java +++ b/tools/layoutlib/bridge/src/libcore/icu/ICU_Delegate.java @@ -137,6 +137,11 @@ public class ICU_Delegate { } @LayoutlibDelegate + /*package*/ static String getDisplayScriptNative(String variantCode, String locale) { + return ""; + } + + @LayoutlibDelegate /*package*/ static String getISO3CountryNative(String locale) { return ""; } @@ -166,6 +171,17 @@ public class ICU_Delegate { return Locale.getISOCountries(); } + + @LayoutlibDelegate + /*package*/ static String localeForLanguageTag(String languageTag, boolean strict) { + return ""; + } + + @LayoutlibDelegate + /*package*/ static String languageTagForLocale(String locale) { + return ""; + } + @LayoutlibDelegate /*package*/ static boolean initLocaleDataNative(String locale, LocaleData result) { @@ -215,7 +231,7 @@ public class ICU_Delegate { result.percent = '%'; result.perMill = '\u2030'; result.monetarySeparator = ' '; - result.minusSign = '-'; + result.minusSign = "-"; result.exponentSeparator = "e"; result.infinity = "\u221E"; result.NaN = "NaN"; diff --git a/tools/preload/Android.mk b/tools/preload/Android.mk index f325870..14a4547 100644 --- a/tools/preload/Android.mk +++ b/tools/preload/Android.mk @@ -20,4 +20,4 @@ LOCAL_MODULE:= preload include $(BUILD_HOST_JAVA_LIBRARY) -include $(call all-subdir-makefiles) +include $(call all-makefiles-under,$(LOCAL_PATH)) |