Index: base/sys_info_android.cc |
diff --git a/base/sys_info_android.cc b/base/sys_info_android.cc |
index b84b557ec323ad5781fff8443c32f31d18d49046..afb7a8a5d5596126016342928ace84e1ee9e51e3 100644 |
--- a/base/sys_info_android.cc |
+++ b/base/sys_info_android.cc |
@@ -9,9 +9,51 @@ |
#include "base/logging.h" |
#include "base/string_number_conversions.h" |
#include "base/string_piece.h" |
+#include "base/stringprintf.h" |
namespace { |
+// Default to ICS when the version number string doesn't make sense. |
+// TODO(yfriedman): Keep this reasonably up to date. |
+static const int kPublicAndroidMajorVersion = 4; |
+static const int kPublicAndroidMinorVersion = 0; |
+static const int kPublicAndroidBugfixVersion = 3; |
+ |
+// If we have no clue what version of Android we're on, use 1.0.0. |
+static const int kUnknownMajorVersion = 1; |
+static const int kUnknownMinorVersion = 0; |
+static const int kUnknownBugfixVersion = 0; |
+ |
+// Parse out the OS version numbers from the system properties. |
+void GetOSVersionNumbers(const char* os_version_str, |
+ int *major_version, |
+ int *minor_version, |
+ int *bugfix_version) { |
+ if (strlen(os_version_str) > 0) { |
+ // Try to parse out the version numbers. |
+ int num_read = sscanf(os_version_str, "%d.%d.%d", major_version, |
+ minor_version, bugfix_version); |
+ |
+ if (num_read == 0) { |
+ // Either the user is using a build that doesn't have a proper version |
+ // number, or the release doesn't have a version number yet (e.g. |
+ // "Jellybean"). In this case, use the latest public Android version. |
+ *major_version = kPublicAndroidMajorVersion; |
+ *minor_version = kPublicAndroidMinorVersion; |
+ *bugfix_version = kPublicAndroidBugfixVersion; |
+ } else { |
+ // If we don't have a full set of version numbers, make the extras 0. |
+ if (num_read < 2) *minor_version = 0; |
+ if (num_read < 3) *bugfix_version = 0; |
+ } |
+ } else { |
+ // We don't have a string at all. |
+ *major_version = kUnknownMajorVersion; |
+ *minor_version = kUnknownMinorVersion; |
+ *bugfix_version = kUnknownBugfixVersion; |
+ } |
+} |
+ |
int ParseHeapSize(const base::StringPiece& str) { |
const int64 KB = 1024; |
const int64 MB = 1024 * KB; |
@@ -51,6 +93,59 @@ int GetDalvikHeapSizeMB() { |
namespace base { |
+void SysInfo::OperatingSystemVersionNumbers(int32* major_version, |
+ int32* minor_version, |
+ int32* bugfix_version) { |
+ // Read the version number string out from the properties. |
+ char os_version_str[PROP_VALUE_MAX]; |
+ __system_property_get("ro.build.version.release", os_version_str); |
+ |
+ // Parse out the numbers. |
+ int internal_major_version, internal_minor_version, internal_bugfix_version; |
+ GetOSVersionNumbers(os_version_str, &internal_major_version, |
+ &internal_minor_version, &internal_bugfix_version); |
+ *major_version = internal_major_version; |
+ *minor_version = internal_minor_version; |
+ *bugfix_version = internal_bugfix_version; |
+} |
+ |
+std::string SysInfo::OperatingSystemInformation() { |
+ std::string android_info_str; |
+ |
+ // Append information about the OS version. |
+ int32 version_major, version_minor, version_bugfix; |
+ OperatingSystemVersionNumbers(&version_major, &version_minor, |
+ &version_bugfix); |
+ if (version_bugfix == 0) { |
+ base::StringAppendF(&android_info_str, "%d.%d", version_major, |
+ version_minor); |
+ } else { |
+ base::StringAppendF(&android_info_str, "%d.%d.%d", version_major, |
+ version_minor, version_bugfix); |
+ } |
+ android_info_str += ";"; |
+ |
+ // Append information about the device. |
+ char os_version_codename_str[PROP_VALUE_MAX]; |
+ __system_property_get("ro.build.version.codename", os_version_codename_str); |
+ if (strcmp("REL", os_version_codename_str) == 0) { |
+ char device_model_str[PROP_VALUE_MAX]; |
+ __system_property_get("ro.product.model", device_model_str); |
+ if (strlen(device_model_str) > 0) { |
+ android_info_str += " " + std::string(device_model_str); |
+ } |
+ } |
+ |
+ // Append the build ID. |
+ char os_build_id_str[PROP_VALUE_MAX]; |
+ __system_property_get("ro.build.id", os_build_id_str); |
+ if (strlen(os_build_id_str) > 0) { |
willchan no longer on Chromium
2012/08/14 17:51:09
You don't need strlen, just see if (os_build_id_st
gone
2012/08/14 17:58:37
Done.
|
+ android_info_str += " Build/" + std::string(os_build_id_str); |
+ } |
+ |
+ return android_info_str; |
+} |
+ |
int SysInfo::DalvikHeapSizeMB() { |
static int heap_size = GetDalvikHeapSizeMB(); |
return heap_size; |