Bug 1095298 - Ignore 'C' locale when initializing nsLocaleService on Android. r=emk, a=lmandel
authorRichard Newman <rnewman@mozilla.com>
Wed, 12 Nov 2014 08:52:19 -0800
changeset 233840 db92e37c83a22b47121e980bc8d2f1d3e8512270
parent 233839 4f17bbb8fcd3d34cb727eb6abfddfa8587d8afbe
child 233841 fba588b0173c74142cc956380a93cf983162c8f4
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemk, lmandel
bugs1095298
milestone35.0a2
Bug 1095298 - Ignore 'C' locale when initializing nsLocaleService on Android. r=emk, a=lmandel On Android Lollipop, our setlocale call returns "C", rather than the null it returns on earlier Android versions. This impacts locale detection, causing devices to always appear to be in en-US. This patch conditionally ignores "C" if MOZ_WIDGET_ANDROID is set.
intl/locale/nsLocaleService.cpp
--- a/intl/locale/nsLocaleService.cpp
+++ b/intl/locale/nsLocaleService.cpp
@@ -135,17 +135,25 @@ nsLocaleService::nsLocaleService(void)
 
     for( i = 0; i < LocaleListLength; i++ ) {
         nsresult result;
         // setlocale( , "") evaluates LC_* and LANG
         char* lc_temp = setlocale(posix_locale_category[i], "");
         CopyASCIItoUTF16(LocaleList[i], category);
         category_platform = category;
         category_platform.AppendLiteral("##PLATFORM");
-        if (lc_temp != nullptr) {
+
+        bool lc_temp_valid = lc_temp != nullptr;
+
+#if defined(MOZ_WIDGET_ANDROID)
+        // Treat the "C" env as nothing useful. See Bug 1095298.
+        lc_temp_valid = lc_temp_valid && strcmp(lc_temp, "C") != 0;
+#endif
+
+        if (lc_temp_valid) {
             result = nsPosixLocale::GetXPLocale(lc_temp, xpLocale);
             CopyASCIItoUTF16(lc_temp, platformLocale);
         } else {
             if ( lang == nullptr ) {
                 platformLocale.AssignLiteral("en_US");
                 result = nsPosixLocale::GetXPLocale("en-US", xpLocale);
             } else {
                 CopyASCIItoUTF16(lang, platformLocale);