Loading tools/aapt2/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -139,6 +139,7 @@ cc_library_host_static { "xml/XmlDom.cpp", "xml/XmlPullParser.cpp", "xml/XmlUtil.cpp", "Configuration.proto", "Resources.proto", "ResourcesInternal.proto", ], Loading tools/aapt2/ConfigDescription.cpp +6 −0 Original line number Diff line number Diff line Loading @@ -876,6 +876,12 @@ ConfigDescription ConfigDescription::CopyWithoutSdkVersion() const { return copy; } std::string ConfigDescription::GetBcp47LanguageTag(bool canonicalize) const { char locale[RESTABLE_MAX_LOCALE_LEN]; getBcp47Locale(locale, canonicalize); return std::string(locale); } bool ConfigDescription::Dominates(const ConfigDescription& o) const { if (*this == o) { return true; Loading tools/aapt2/ConfigDescription.h +3 −0 Original line number Diff line number Diff line Loading @@ -61,6 +61,9 @@ struct ConfigDescription : public android::ResTable_config { ConfigDescription CopyWithoutSdkVersion() const; // Returns the BCP-47 language tag of this configuration's locale. std::string GetBcp47LanguageTag(bool canonicalize = false) const; /** * A configuration X dominates another configuration Y, if X has at least the * precedence of Y and X is strictly more general than Y: for any type defined Loading tools/aapt2/Configuration.proto 0 → 100644 +207 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ syntax = "proto3"; package aapt.pb; option java_package = "com.android.aapt"; option optimize_for = LITE_RUNTIME; // A description of the requirements a device must have in order for a // resource to be matched and selected. message Configuration { enum LayoutDirection { LAYOUT_DIRECTION_UNSET = 0; LAYOUT_DIRECTION_LTR = 1; LAYOUT_DIRECTION_RTL = 2; } enum ScreenLayoutSize { SCREEN_LAYOUT_SIZE_UNSET = 0; SCREEN_LAYOUT_SIZE_SMALL = 1; SCREEN_LAYOUT_SIZE_NORMAL = 2; SCREEN_LAYOUT_SIZE_LARGE = 3; SCREEN_LAYOUT_SIZE_XLARGE = 4; } enum ScreenLayoutLong { SCREEN_LAYOUT_LONG_UNSET = 0; SCREEN_LAYOUT_LONG_LONG = 1; SCREEN_LAYOUT_LONG_NOTLONG = 2; } enum ScreenRound { SCREEN_ROUND_UNSET = 0; SCREEN_ROUND_ROUND = 1; SCREEN_ROUND_NOTROUND = 2; } enum WideColorGamut { WIDE_COLOR_GAMUT_UNSET = 0; WIDE_COLOR_GAMUT_WIDECG = 1; WIDE_COLOR_GAMUT_NOWIDECG = 2; } enum Hdr { HDR_UNSET = 0; HDR_HIGHDR = 1; HDR_LOWDR = 2; } enum Orientation { ORIENTATION_UNSET = 0; ORIENTATION_PORT = 1; ORIENTATION_LAND = 2; ORIENTATION_SQUARE = 3; } enum UiModeType { UI_MODE_TYPE_UNSET = 0; UI_MODE_TYPE_NORMAL = 1; UI_MODE_TYPE_DESK = 2; UI_MODE_TYPE_CAR = 3; UI_MODE_TYPE_TELEVISION = 4; UI_MODE_TYPE_APPLIANCE = 5; UI_MODE_TYPE_WATCH = 6; UI_MODE_TYPE_VRHEADSET = 7; } enum UiModeNight { UI_MODE_NIGHT_UNSET = 0; UI_MODE_NIGHT_NIGHT = 1; UI_MODE_NIGHT_NOTNIGHT = 2; } enum Touchscreen { TOUCHSCREEN_UNSET = 0; TOUCHSCREEN_NOTOUCH = 1; TOUCHSCREEN_STYLUS = 2; TOUCHSCREEN_FINGER = 3; } enum KeysHidden { KEYS_HIDDEN_UNSET = 0; KEYS_HIDDEN_KEYSEXPOSED = 1; KEYS_HIDDEN_KEYSHIDDEN = 2; KEYS_HIDDEN_KEYSSOFT = 3; } enum Keyboard { KEYBOARD_UNSET = 0; KEYBOARD_NOKEYS = 1; KEYBOARD_QWERTY = 2; KEYBOARD_TWELVEKEY = 3; } enum NavHidden { NAV_HIDDEN_UNSET = 0; NAV_HIDDEN_NAVEXPOSED = 1; NAV_HIDDEN_NAVHIDDEN = 2; } enum Navigation { NAVIGATION_UNSET = 0; NAVIGATION_NONAV = 1; NAVIGATION_DPAD = 2; NAVIGATION_TRACKBALL = 3; NAVIGATION_WHEEL = 4; } // // Axis/dimensions that are understood by the runtime. // // Mobile country code. uint32 mcc = 1; // Mobile network code. uint32 mnc = 2; // BCP-47 locale tag. string locale = 3; // Left-to-right, right-to-left... LayoutDirection layout_direction = 4; // Screen width in pixels. Prefer screen_width_dp. uint32 screen_width = 5; // Screen height in pixels. Prefer screen_height_dp. uint32 screen_height = 6; // Screen width in density independent pixels (dp). uint32 screen_width_dp = 7; // Screen height in density independent pixels (dp). uint32 screen_height_dp = 8; // The smallest screen dimension, regardless of orientation, in dp. uint32 smallest_screen_width_dp = 9; // Whether the device screen is classified as small, normal, large, xlarge. ScreenLayoutSize screen_layout_size = 10; // Whether the device screen is long. ScreenLayoutLong screen_layout_long = 11; // Whether the screen is round (Android Wear). ScreenRound screen_round = 12; // Whether the screen supports wide color gamut. WideColorGamut wide_color_gamut = 13; // Whether the screen has high dynamic range. Hdr hdr = 14; // Which orientation the device is in (portrait, landscape). Orientation orientation = 15; // Which type of UI mode the device is in (television, car, etc.). UiModeType ui_mode_type = 16; // Whether the device is in night mode. UiModeNight ui_mode_night = 17; // The device's screen density in dots-per-inch (dpi). uint32 density = 18; // Whether a touchscreen exists, supports a stylus, or finger. Touchscreen touchscreen = 19; // Whether the keyboard hardware keys are currently hidden, exposed, or // if the keyboard is a software keyboard. KeysHidden keys_hidden = 20; // The type of keyboard present (none, QWERTY, 12-key). Keyboard keyboard = 21; // Whether the navigation is exposed or hidden. NavHidden nav_hidden = 22; // The type of navigation present on the device // (trackball, wheel, dpad, etc.). Navigation navigation = 23; // The minimum SDK version of the device. uint32 sdk_version = 24; // // Build-time only dimensions. // string product = 25; } tools/aapt2/Locale.cpp +72 −65 Original line number Diff line number Diff line Loading @@ -24,9 +24,10 @@ #include "util/Util.h" namespace aapt { using ::android::ResTable_config; using ::android::StringPiece; using android::ResTable_config; namespace aapt { void LocaleValue::set_language(const char* language_chars) { size_t i = 0; Loading Loading @@ -72,7 +73,7 @@ static inline bool is_number(const std::string& str) { return std::all_of(std::begin(str), std::end(str), ::isdigit); } bool LocaleValue::InitFromFilterString(const android::StringPiece& str) { bool LocaleValue::InitFromFilterString(const StringPiece& str) { // A locale (as specified in the filter) is an underscore separated name such // as "en_US", "en_Latn_US", or "en_US_POSIX". std::vector<std::string> parts = util::SplitAndLowercase(str, '_'); Loading Loading @@ -138,16 +139,12 @@ bool LocaleValue::InitFromFilterString(const android::StringPiece& str) { return true; } ssize_t LocaleValue::InitFromParts(std::vector<std::string>::iterator iter, std::vector<std::string>::iterator end) { const std::vector<std::string>::iterator start_iter = iter; bool LocaleValue::InitFromBcp47Tag(const StringPiece& bcp47tag) { return InitFromBcp47TagImpl(bcp47tag, '-'); } std::string& part = *iter; 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 "-". std::vector<std::string> subtags = util::SplitAndLowercase(part, '+'); subtags.erase(subtags.begin()); bool LocaleValue::InitFromBcp47TagImpl(const StringPiece& bcp47tag, const char separator) { std::vector<std::string> subtags = util::SplitAndLowercase(bcp47tag, separator); if (subtags.size() == 1) { set_language(subtags[0].c_str()); } else if (subtags.size() == 2) { Loading @@ -173,7 +170,7 @@ ssize_t LocaleValue::InitFromParts(std::vector<std::string>::iterator iter, set_variant(subtags[1].c_str()); break; default: return -1; return false; } } else if (subtags.size() == 3) { // The language is always the first subtag. Loading @@ -186,7 +183,7 @@ ssize_t LocaleValue::InitFromParts(std::vector<std::string>::iterator iter, } else if (subtags[1].size() == 2 || subtags[1].size() == 3) { set_region(subtags[1].c_str()); } else { return -1; return false; } // The third tag can either be a region code (if the second tag was Loading @@ -202,14 +199,25 @@ ssize_t LocaleValue::InitFromParts(std::vector<std::string>::iterator iter, set_region(subtags[2].c_str()); set_variant(subtags[3].c_str()); } else { return -1; return false; } return true; } ++iter; ssize_t LocaleValue::InitFromParts(std::vector<std::string>::iterator iter, std::vector<std::string>::iterator end) { const std::vector<std::string>::iterator start_iter = iter; std::string& part = *iter; 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 "-". Skip the prefix 'b+'. if (!InitFromBcp47TagImpl(StringPiece(part).substr(2), '+')) { return -1; } ++iter; } else { if ((part.length() == 2 || part.length() == 3) && is_alpha(part) && part != "car") { if ((part.length() == 2 || part.length() == 3) && is_alpha(part) && part != "car") { set_language(part.c_str()); ++iter; Loading @@ -222,7 +230,6 @@ ssize_t LocaleValue::InitFromParts(std::vector<std::string>::iterator iter, } } } return static_cast<ssize_t>(iter - start_iter); } Loading Loading
tools/aapt2/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -139,6 +139,7 @@ cc_library_host_static { "xml/XmlDom.cpp", "xml/XmlPullParser.cpp", "xml/XmlUtil.cpp", "Configuration.proto", "Resources.proto", "ResourcesInternal.proto", ], Loading
tools/aapt2/ConfigDescription.cpp +6 −0 Original line number Diff line number Diff line Loading @@ -876,6 +876,12 @@ ConfigDescription ConfigDescription::CopyWithoutSdkVersion() const { return copy; } std::string ConfigDescription::GetBcp47LanguageTag(bool canonicalize) const { char locale[RESTABLE_MAX_LOCALE_LEN]; getBcp47Locale(locale, canonicalize); return std::string(locale); } bool ConfigDescription::Dominates(const ConfigDescription& o) const { if (*this == o) { return true; Loading
tools/aapt2/ConfigDescription.h +3 −0 Original line number Diff line number Diff line Loading @@ -61,6 +61,9 @@ struct ConfigDescription : public android::ResTable_config { ConfigDescription CopyWithoutSdkVersion() const; // Returns the BCP-47 language tag of this configuration's locale. std::string GetBcp47LanguageTag(bool canonicalize = false) const; /** * A configuration X dominates another configuration Y, if X has at least the * precedence of Y and X is strictly more general than Y: for any type defined Loading
tools/aapt2/Configuration.proto 0 → 100644 +207 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ syntax = "proto3"; package aapt.pb; option java_package = "com.android.aapt"; option optimize_for = LITE_RUNTIME; // A description of the requirements a device must have in order for a // resource to be matched and selected. message Configuration { enum LayoutDirection { LAYOUT_DIRECTION_UNSET = 0; LAYOUT_DIRECTION_LTR = 1; LAYOUT_DIRECTION_RTL = 2; } enum ScreenLayoutSize { SCREEN_LAYOUT_SIZE_UNSET = 0; SCREEN_LAYOUT_SIZE_SMALL = 1; SCREEN_LAYOUT_SIZE_NORMAL = 2; SCREEN_LAYOUT_SIZE_LARGE = 3; SCREEN_LAYOUT_SIZE_XLARGE = 4; } enum ScreenLayoutLong { SCREEN_LAYOUT_LONG_UNSET = 0; SCREEN_LAYOUT_LONG_LONG = 1; SCREEN_LAYOUT_LONG_NOTLONG = 2; } enum ScreenRound { SCREEN_ROUND_UNSET = 0; SCREEN_ROUND_ROUND = 1; SCREEN_ROUND_NOTROUND = 2; } enum WideColorGamut { WIDE_COLOR_GAMUT_UNSET = 0; WIDE_COLOR_GAMUT_WIDECG = 1; WIDE_COLOR_GAMUT_NOWIDECG = 2; } enum Hdr { HDR_UNSET = 0; HDR_HIGHDR = 1; HDR_LOWDR = 2; } enum Orientation { ORIENTATION_UNSET = 0; ORIENTATION_PORT = 1; ORIENTATION_LAND = 2; ORIENTATION_SQUARE = 3; } enum UiModeType { UI_MODE_TYPE_UNSET = 0; UI_MODE_TYPE_NORMAL = 1; UI_MODE_TYPE_DESK = 2; UI_MODE_TYPE_CAR = 3; UI_MODE_TYPE_TELEVISION = 4; UI_MODE_TYPE_APPLIANCE = 5; UI_MODE_TYPE_WATCH = 6; UI_MODE_TYPE_VRHEADSET = 7; } enum UiModeNight { UI_MODE_NIGHT_UNSET = 0; UI_MODE_NIGHT_NIGHT = 1; UI_MODE_NIGHT_NOTNIGHT = 2; } enum Touchscreen { TOUCHSCREEN_UNSET = 0; TOUCHSCREEN_NOTOUCH = 1; TOUCHSCREEN_STYLUS = 2; TOUCHSCREEN_FINGER = 3; } enum KeysHidden { KEYS_HIDDEN_UNSET = 0; KEYS_HIDDEN_KEYSEXPOSED = 1; KEYS_HIDDEN_KEYSHIDDEN = 2; KEYS_HIDDEN_KEYSSOFT = 3; } enum Keyboard { KEYBOARD_UNSET = 0; KEYBOARD_NOKEYS = 1; KEYBOARD_QWERTY = 2; KEYBOARD_TWELVEKEY = 3; } enum NavHidden { NAV_HIDDEN_UNSET = 0; NAV_HIDDEN_NAVEXPOSED = 1; NAV_HIDDEN_NAVHIDDEN = 2; } enum Navigation { NAVIGATION_UNSET = 0; NAVIGATION_NONAV = 1; NAVIGATION_DPAD = 2; NAVIGATION_TRACKBALL = 3; NAVIGATION_WHEEL = 4; } // // Axis/dimensions that are understood by the runtime. // // Mobile country code. uint32 mcc = 1; // Mobile network code. uint32 mnc = 2; // BCP-47 locale tag. string locale = 3; // Left-to-right, right-to-left... LayoutDirection layout_direction = 4; // Screen width in pixels. Prefer screen_width_dp. uint32 screen_width = 5; // Screen height in pixels. Prefer screen_height_dp. uint32 screen_height = 6; // Screen width in density independent pixels (dp). uint32 screen_width_dp = 7; // Screen height in density independent pixels (dp). uint32 screen_height_dp = 8; // The smallest screen dimension, regardless of orientation, in dp. uint32 smallest_screen_width_dp = 9; // Whether the device screen is classified as small, normal, large, xlarge. ScreenLayoutSize screen_layout_size = 10; // Whether the device screen is long. ScreenLayoutLong screen_layout_long = 11; // Whether the screen is round (Android Wear). ScreenRound screen_round = 12; // Whether the screen supports wide color gamut. WideColorGamut wide_color_gamut = 13; // Whether the screen has high dynamic range. Hdr hdr = 14; // Which orientation the device is in (portrait, landscape). Orientation orientation = 15; // Which type of UI mode the device is in (television, car, etc.). UiModeType ui_mode_type = 16; // Whether the device is in night mode. UiModeNight ui_mode_night = 17; // The device's screen density in dots-per-inch (dpi). uint32 density = 18; // Whether a touchscreen exists, supports a stylus, or finger. Touchscreen touchscreen = 19; // Whether the keyboard hardware keys are currently hidden, exposed, or // if the keyboard is a software keyboard. KeysHidden keys_hidden = 20; // The type of keyboard present (none, QWERTY, 12-key). Keyboard keyboard = 21; // Whether the navigation is exposed or hidden. NavHidden nav_hidden = 22; // The type of navigation present on the device // (trackball, wheel, dpad, etc.). Navigation navigation = 23; // The minimum SDK version of the device. uint32 sdk_version = 24; // // Build-time only dimensions. // string product = 25; }
tools/aapt2/Locale.cpp +72 −65 Original line number Diff line number Diff line Loading @@ -24,9 +24,10 @@ #include "util/Util.h" namespace aapt { using ::android::ResTable_config; using ::android::StringPiece; using android::ResTable_config; namespace aapt { void LocaleValue::set_language(const char* language_chars) { size_t i = 0; Loading Loading @@ -72,7 +73,7 @@ static inline bool is_number(const std::string& str) { return std::all_of(std::begin(str), std::end(str), ::isdigit); } bool LocaleValue::InitFromFilterString(const android::StringPiece& str) { bool LocaleValue::InitFromFilterString(const StringPiece& str) { // A locale (as specified in the filter) is an underscore separated name such // as "en_US", "en_Latn_US", or "en_US_POSIX". std::vector<std::string> parts = util::SplitAndLowercase(str, '_'); Loading Loading @@ -138,16 +139,12 @@ bool LocaleValue::InitFromFilterString(const android::StringPiece& str) { return true; } ssize_t LocaleValue::InitFromParts(std::vector<std::string>::iterator iter, std::vector<std::string>::iterator end) { const std::vector<std::string>::iterator start_iter = iter; bool LocaleValue::InitFromBcp47Tag(const StringPiece& bcp47tag) { return InitFromBcp47TagImpl(bcp47tag, '-'); } std::string& part = *iter; 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 "-". std::vector<std::string> subtags = util::SplitAndLowercase(part, '+'); subtags.erase(subtags.begin()); bool LocaleValue::InitFromBcp47TagImpl(const StringPiece& bcp47tag, const char separator) { std::vector<std::string> subtags = util::SplitAndLowercase(bcp47tag, separator); if (subtags.size() == 1) { set_language(subtags[0].c_str()); } else if (subtags.size() == 2) { Loading @@ -173,7 +170,7 @@ ssize_t LocaleValue::InitFromParts(std::vector<std::string>::iterator iter, set_variant(subtags[1].c_str()); break; default: return -1; return false; } } else if (subtags.size() == 3) { // The language is always the first subtag. Loading @@ -186,7 +183,7 @@ ssize_t LocaleValue::InitFromParts(std::vector<std::string>::iterator iter, } else if (subtags[1].size() == 2 || subtags[1].size() == 3) { set_region(subtags[1].c_str()); } else { return -1; return false; } // The third tag can either be a region code (if the second tag was Loading @@ -202,14 +199,25 @@ ssize_t LocaleValue::InitFromParts(std::vector<std::string>::iterator iter, set_region(subtags[2].c_str()); set_variant(subtags[3].c_str()); } else { return -1; return false; } return true; } ++iter; ssize_t LocaleValue::InitFromParts(std::vector<std::string>::iterator iter, std::vector<std::string>::iterator end) { const std::vector<std::string>::iterator start_iter = iter; std::string& part = *iter; 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 "-". Skip the prefix 'b+'. if (!InitFromBcp47TagImpl(StringPiece(part).substr(2), '+')) { return -1; } ++iter; } else { if ((part.length() == 2 || part.length() == 3) && is_alpha(part) && part != "car") { if ((part.length() == 2 || part.length() == 3) && is_alpha(part) && part != "car") { set_language(part.c_str()); ++iter; Loading @@ -222,7 +230,6 @@ ssize_t LocaleValue::InitFromParts(std::vector<std::string>::iterator iter, } } } return static_cast<ssize_t>(iter - start_iter); } Loading