summaryrefslogtreecommitdiffstats
path: root/base/sys_info_android.cc
diff options
context:
space:
mode:
authordfalcantara@chromium.org <dfalcantara@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-21 23:55:52 +0000
committerdfalcantara@chromium.org <dfalcantara@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-21 23:55:52 +0000
commitabef4b33bc3d484621e28a70c141e6ca8ce7aa1e (patch)
treed495c173007c3ecb45efe288f072bd23d26537a1 /base/sys_info_android.cc
parentb7c8d6c560adc7cddfcf23ad73e3c4378ef65ea4 (diff)
downloadchromium_src-abef4b33bc3d484621e28a70c141e6ca8ce7aa1e.zip
chromium_src-abef4b33bc3d484621e28a70c141e6ca8ce7aa1e.tar.gz
chromium_src-abef4b33bc3d484621e28a70c141e6ca8ce7aa1e.tar.bz2
Move Android user agent generation to native code
Gets rid of a pathway that forced us to set the user agent from the Java side, replacing it with one that's entirely native. Functions have been added to base to allow accessing information about the device and Android build, while the user agent generation code was moved to the webkit_glue namespace. BUG=131312 Review URL: https://chromiumcodereview.appspot.com/10832235 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152675 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/sys_info_android.cc')
-rw-r--r--base/sys_info_android.cc62
1 files changed, 62 insertions, 0 deletions
diff --git a/base/sys_info_android.cc b/base/sys_info_android.cc
index b84b557..d2bfbcb 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;