Merge changes Ibdb7dd0b,Iafd3e846

am: 72e6e55e34

Change-Id: I2cf9f6e8c489b6c48056687d0405ba3585df5b9a
This commit is contained in:
Tianjie Xu
2019-04-23 11:04:48 -07:00
committed by android-build-merger
5 changed files with 33 additions and 12 deletions
+14 -4
View File
@@ -347,6 +347,10 @@ bool matches_locale(const std::string& prefix, const std::string& locale) {
// match the locale string without the {script} section. // match the locale string without the {script} section.
// For instance, prefix == "en" matches locale == "en-US", prefix == "sr-Latn" matches locale // For instance, prefix == "en" matches locale == "en-US", prefix == "sr-Latn" matches locale
// == "sr-Latn-BA", and prefix == "zh-CN" matches locale == "zh-Hans-CN". // == "sr-Latn-BA", and prefix == "zh-CN" matches locale == "zh-Hans-CN".
if (prefix.empty()) {
return false;
}
if (android::base::StartsWith(locale, prefix)) { if (android::base::StartsWith(locale, prefix)) {
return true; return true;
} }
@@ -414,12 +418,18 @@ int res_create_localized_alpha_surface(const char* name,
__unused int len = row[4]; __unused int len = row[4];
char* loc = reinterpret_cast<char*>(&row[5]); char* loc = reinterpret_cast<char*>(&row[5]);
if (y + 1 + h >= height || matches_locale(loc, locale)) { // We need to include one additional line for the metadata of the localized image.
if (y + 1 + h > height) {
printf("Read exceeds the image boundary, y %u, h %d, height %u\n", y, h, height);
return -8;
}
if (matches_locale(loc, locale)) {
printf(" %20s: %s (%d x %d @ %d)\n", name, loc, w, h, y); printf(" %20s: %s (%d x %d @ %d)\n", name, loc, w, h, y);
auto surface = GRSurface::Create(w, h, w, 1); auto surface = GRSurface::Create(w, h, w, 1);
if (!surface) { if (!surface) {
return -8; return -9;
} }
for (int i = 0; i < h; ++i, ++y) { for (int i = 0; i < h; ++i, ++y) {
@@ -428,7 +438,7 @@ int res_create_localized_alpha_surface(const char* name,
} }
*pSurface = surface.release(); *pSurface = surface.release();
break; return 0;
} }
for (int i = 0; i < h; ++i, ++y) { for (int i = 0; i < h; ++i, ++y) {
@@ -436,7 +446,7 @@ int res_create_localized_alpha_surface(const char* name,
} }
} }
return 0; return -10;
} }
void res_free_surface(GRSurface* surface) { void res_free_surface(GRSurface* surface) {
-1
View File
@@ -373,7 +373,6 @@ int main(int argc, char** argv) {
} }
if (locale.empty()) { if (locale.empty()) {
static constexpr const char* DEFAULT_LOCALE = "en-US";
locale = DEFAULT_LOCALE; locale = DEFAULT_LOCALE;
} }
} }
+2
View File
@@ -27,6 +27,8 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
static constexpr const char* DEFAULT_LOCALE = "en-US";
// Abstract class for controlling the user interface during recovery. // Abstract class for controlling the user interface during recovery.
class RecoveryUI { class RecoveryUI {
public: public:
+15 -5
View File
@@ -817,12 +817,22 @@ std::unique_ptr<GRSurface> ScreenRecoveryUI::LoadBitmap(const std::string& filen
std::unique_ptr<GRSurface> ScreenRecoveryUI::LoadLocalizedBitmap(const std::string& filename) { std::unique_ptr<GRSurface> ScreenRecoveryUI::LoadLocalizedBitmap(const std::string& filename) {
GRSurface* surface; GRSurface* surface;
if (auto result = res_create_localized_alpha_surface(filename.c_str(), locale_.c_str(), &surface); auto result = res_create_localized_alpha_surface(filename.c_str(), locale_.c_str(), &surface);
result < 0) { if (result == 0) {
LOG(ERROR) << "Failed to load bitmap " << filename << " (error " << result << ")"; return std::unique_ptr<GRSurface>(surface);
return nullptr;
} }
return std::unique_ptr<GRSurface>(surface); // TODO(xunchang) create a error code enum to refine the retry condition.
LOG(WARNING) << "Failed to load bitmap " << filename << " for locale " << locale_ << " (error "
<< result << "). Falling back to use default locale.";
result = res_create_localized_alpha_surface(filename.c_str(), DEFAULT_LOCALE, &surface);
if (result == 0) {
return std::unique_ptr<GRSurface>(surface);
}
LOG(ERROR) << "Failed to load bitmap " << filename << " for locale " << DEFAULT_LOCALE
<< " (error " << result << ")";
return nullptr;
} }
static char** Alloc2d(size_t rows, size_t cols) { static char** Alloc2d(size_t rows, size_t cols) {
+2 -2
View File
@@ -27,7 +27,7 @@ TEST(LocaleTest, Misc) {
EXPECT_FALSE(matches_locale("en-GB", "en")); EXPECT_FALSE(matches_locale("en-GB", "en"));
EXPECT_FALSE(matches_locale("en-GB", "en-US")); EXPECT_FALSE(matches_locale("en-GB", "en-US"));
EXPECT_FALSE(matches_locale("en-US", "")); EXPECT_FALSE(matches_locale("en-US", ""));
// Empty locale prefix in the PNG file will match the input locale. // Empty locale prefix in the PNG file should not match the input locale.
EXPECT_TRUE(matches_locale("", "en-US")); EXPECT_FALSE(matches_locale("", "en-US"));
EXPECT_TRUE(matches_locale("sr-Latn", "sr-Latn-BA")); EXPECT_TRUE(matches_locale("sr-Latn", "sr-Latn-BA"));
} }