Bug 1284921- Hardcode Android version for non-numeric releases. r=nfroyd
authorMichael Kaply <mozilla@kaply.com>
Wed, 13 Jul 2016 10:31:26 -0500
changeset 304907 9efa66f1c6a15449be7a3c37ade8e104ce2afef8
parent 304906 0b6a509a03d1fdec9a92e41c45730b8a6975caac
child 304908 395c5a486954a3f747ceb07dfc8f1ebd3d00cf60
push id30446
push usercbook@mozilla.com
push dateThu, 14 Jul 2016 09:44:34 +0000
treeherdermozilla-central@cd9da00ffcc3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnfroyd
bugs1284921
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1284921- Hardcode Android version for non-numeric releases. r=nfroyd
xpcom/base/nsSystemInfo.cpp
--- a/xpcom/base/nsSystemInfo.cpp
+++ b/xpcom/base/nsSystemInfo.cpp
@@ -811,16 +811,25 @@ nsSystemInfo::Init()
                       sandInfo.CanSandboxMedia());
   }
 #endif // XP_LINUX && MOZ_SANDBOX
 
   return NS_OK;
 }
 
 #ifdef MOZ_WIDGET_ANDROID
+// Prerelease versions of Android use a letter instead of version numbers.
+// Unfortunately this breaks websites due to the user agent.
+// Chrome works around this by hardcoding an Android version when a
+// numeric version can't be obtained. We're doing the same.
+// This version will need to be updated whenever there is a new official
+// Android release.
+// See: https://cs.chromium.org/chromium/src/base/sys_info_android.cc?l=61
+#define DEFAULT_ANDROID_VERSION "6.0.99"
+
 /* static */
 void
 nsSystemInfo::GetAndroidSystemInfo(AndroidSystemInfo* aInfo)
 {
   MOZ_ASSERT(XRE_IsParentProcess());
 
   if (!mozilla::AndroidBridge::Bridge()) {
     aInfo->sdk_version() = 0;
@@ -833,17 +842,25 @@ nsSystemInfo::GetAndroidSystemInfo(Andro
     aInfo->device() = str;
   }
   if (mozilla::AndroidBridge::Bridge()->GetStaticStringField(
       "android/os/Build", "MANUFACTURER", str)) {
     aInfo->manufacturer() = str;
   }
   if (mozilla::AndroidBridge::Bridge()->GetStaticStringField(
       "android/os/Build$VERSION", "RELEASE", str)) {
-    aInfo->release_version() = str;
+    int major_version;
+    int minor_version;
+    int bugfix_version;
+    int num_read = sscanf(NS_ConvertUTF16toUTF8(str).get(), "%d.%d.%d", &major_version, &minor_version, &bugfix_version);
+    if (num_read == 0) {
+      aInfo->release_version() = NS_LITERAL_STRING(DEFAULT_ANDROID_VERSION);
+    } else {
+      aInfo->release_version() = str;
+    }
   }
   if (mozilla::AndroidBridge::Bridge()->GetStaticStringField(
       "android/os/Build", "HARDWARE", str)) {
     aInfo->hardware() = str;
   }
   int32_t sdk_version;
   if (!mozilla::AndroidBridge::Bridge()->GetStaticIntField(
       "android/os/Build$VERSION", "SDK_INT", &sdk_version)) {