Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2895)

Unified Diff: base/sys_info_android.cc

Issue 10832235: Move Android user agent generation to native code (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Nit fix Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/sys_info.h ('k') | content/app/android/app_jni_registrar.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/sys_info_android.cc
diff --git a/base/sys_info_android.cc b/base/sys_info_android.cc
index b84b557ec323ad5781fff8443c32f31d18d49046..d2bfbcbbdb93227144480b3240c1620f6b128de8 100644
--- a/base/sys_info_android.cc
+++ b/base/sys_info_android.cc
@@ -12,6 +12,38 @@
namespace {
+// Default version of Android to fall back to when actual version numbers
+// cannot be acquired.
+// TODO(dfalcantara): Keep this reasonably up to date with the latest publicly
+// available version of Android.
+static const int kDefaultAndroidMajorVersion = 4;
+static const int kDefaultAndroidMinorVersion = 0;
+static const int kDefaultAndroidBugfixVersion = 3;
+
+// Parse out the OS version numbers from the system properties.
+void ParseOSVersionNumbers(const char* os_version_str,
+ int32 *major_version,
+ int32 *minor_version,
+ int32 *bugfix_version) {
+ if (os_version_str[0]) {
+ // Try to parse out the version numbers from the string.
+ int num_read = sscanf(os_version_str, "%d.%d.%d", major_version,
+ minor_version, bugfix_version);
+
+ if (num_read > 0) {
+ // 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;
+ return;
+ }
+ }
+
+ // For some reason, we couldn't parse the version number string.
+ *major_version = kDefaultAndroidMajorVersion;
+ *minor_version = kDefaultAndroidMinorVersion;
+ *bugfix_version = kDefaultAndroidBugfixVersion;
+}
+
int ParseHeapSize(const base::StringPiece& str) {
const int64 KB = 1024;
const int64 MB = 1024 * KB;
@@ -51,6 +83,36 @@ int GetDalvikHeapSizeMB() {
namespace base {
+std::string SysInfo::GetAndroidBuildCodename() {
+ char os_version_codename_str[PROP_VALUE_MAX];
+ __system_property_get("ro.build.version.codename", os_version_codename_str);
+ return std::string(os_version_codename_str);
+}
+
+std::string SysInfo::GetAndroidBuildID() {
+ char os_build_id_str[PROP_VALUE_MAX];
+ __system_property_get("ro.build.id", os_build_id_str);
+ return std::string(os_build_id_str);
+}
+
+std::string SysInfo::GetDeviceName() {
+ char device_model_str[PROP_VALUE_MAX];
+ __system_property_get("ro.product.model", device_model_str);
+ return std::string(device_model_str);
+}
+
+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.
+ ParseOSVersionNumbers(os_version_str, major_version, minor_version,
+ bugfix_version);
+}
+
int SysInfo::DalvikHeapSizeMB() {
static int heap_size = GetDalvikHeapSizeMB();
return heap_size;
« no previous file with comments | « base/sys_info.h ('k') | content/app/android/app_jni_registrar.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698