Bug 991923 - Set Android SDK version in DNS resolver. r=sworkman, a=sledru
authorEugen Sawin <esawin@mozilla.com>
Wed, 17 Dec 2014 16:03:04 +0100
changeset 242554 0e7c88cc3a61b0456b7823f87f925efe95026b1f
parent 242553 f81ef02f704e6f62da7411e252286318f869ba83
child 242555 4c6a7ec58300ebeaa4cfce7c4d5ef0479690b093
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssworkman, sledru
bugs991923
milestone36.0a2
Bug 991923 - Set Android SDK version in DNS resolver. r=sworkman, a=sledru
other-licenses/android/getaddrinfo.c
--- a/other-licenses/android/getaddrinfo.c
+++ b/other-licenses/android/getaddrinfo.c
@@ -417,29 +417,48 @@ extern int
 extern const char *
 __real_gai_strerror(int ecode);
 extern void
 __real_freeaddrinfo(struct addrinfo *ai);
 extern int
 __real_getaddrinfo(const char *hostname, const char *servname,
     const struct addrinfo *hints, struct addrinfo **res);
 
-int android_sdk_version;
-
 #pragma GCC visibility pop
 
-int android_sdk_version = -1;
+static int get_android_sdk_version()
+{
+  char version_str[PROP_VALUE_MAX];
+  memset(version_str, 0, PROP_VALUE_MAX);
+  int len = __system_property_get("ro.build.version.sdk", version_str);
+  if (len < 1) {
+#ifdef MOZ_GETADDRINFO_LOG_VERBOSE
+    __android_log_print(ANDROID_LOG_INFO, "getaddrinfo",
+      "Failed to get Android SDK version\n");
+#endif
+
+    return len;
+  }
+
+  return (int)strtol(version_str, NULL, 10);
+}
 
 static int honeycomb_or_later()
 {
+  static int android_sdk_version = 0;
+  if (android_sdk_version == 0) {
+    android_sdk_version = get_android_sdk_version();
+  }
+
 #ifdef MOZ_GETADDRINFO_LOG_VERBOSE
 	__android_log_print(ANDROID_LOG_INFO, "getaddrinfo",
 		"I am%s Honeycomb\n",
 		(android_sdk_version >= 11) ? "" : " not");
 #endif
+
 	return android_sdk_version >= 11;
 }
 
 const char *
 __wrap_gai_strerror(int ecode)
 {
 	if (honeycomb_or_later())
 		return __real_gai_strerror(ecode);