summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/sys_info.h9
-rw-r--r--base/sys_info_android.cc62
-rw-r--r--content/app/android/app_jni_registrar.cc2
-rw-r--r--content/app/android/content_main.cc3
-rw-r--r--content/app/android/user_agent.cc30
-rw-r--r--content/app/android/user_agent.h21
-rw-r--r--content/content_app.gypi2
-rw-r--r--content/content_jni.gypi1
-rw-r--r--content/public/android/java/src/org/chromium/content/app/UserAgent.java50
-rw-r--r--webkit/glue/user_agent.cc47
-rw-r--r--webkit/glue/user_agent.h7
11 files changed, 101 insertions, 133 deletions
diff --git a/base/sys_info.h b/base/sys_info.h
index c95415e..af9f017 100644
--- a/base/sys_info.h
+++ b/base/sys_info.h
@@ -81,6 +81,15 @@ class BASE_EXPORT SysInfo {
#endif // defined(OS_CHROMEOS)
#if defined(OS_ANDROID)
+ // Returns the Android build's codename.
+ static std::string GetAndroidBuildCodename();
+
+ // Returns the Android build ID.
+ static std::string GetAndroidBuildID();
+
+ // Returns the device's name.
+ static std::string GetDeviceName();
+
static int DalvikHeapSizeMB();
#endif // defined(OS_ANDROID)
};
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;
diff --git a/content/app/android/app_jni_registrar.cc b/content/app/android/app_jni_registrar.cc
index 699b618..ee0863a 100644
--- a/content/app/android/app_jni_registrar.cc
+++ b/content/app/android/app_jni_registrar.cc
@@ -8,14 +8,12 @@
#include "base/android/jni_registrar.h"
#include "content/app/android/content_main.h"
#include "content/app/android/sandboxed_process_service.h"
-#include "content/app/android/user_agent.h"
namespace {
base::android::RegistrationMethod kContentRegisteredMethods[] = {
{ "ContentMain", content::RegisterContentMain },
{ "SandboxedProcessService", content::RegisterSandboxedProcessService },
- { "UserAgent", content::RegisterUserAgent },
};
} // namespace
diff --git a/content/app/android/content_main.cc b/content/app/android/content_main.cc
index f373186..1371617 100644
--- a/content/app/android/content_main.cc
+++ b/content/app/android/content_main.cc
@@ -8,7 +8,6 @@
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/lazy_instance.h"
-#include "content/app/android/user_agent.h"
#include "content/public/app/content_main_delegate.h"
#include "content/public/app/content_main_runner.h"
#include "content/public/common/content_switches.h"
@@ -47,8 +46,6 @@ static jint Start(JNIEnv* env, jclass clazz) {
base::debug::WaitForDebugger(24*60*60, false);
}
- webkit_glue::SetUserAgentOSInfo(content::GetUserAgentOSInfo());
-
DCHECK(!g_content_runner.Get().get());
g_content_runner.Get().reset(ContentMainRunner::Create());
g_content_runner.Get()->Initialize(0, NULL,
diff --git a/content/app/android/user_agent.cc b/content/app/android/user_agent.cc
deleted file mode 100644
index 7a1c49b..0000000
--- a/content/app/android/user_agent.cc
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "content/app/android/user_agent.h"
-
-#include "base/android/jni_android.h"
-#include "base/android/jni_string.h"
-#include "base/android/scoped_java_ref.h"
-#include "jni/UserAgent_jni.h"
-
-using base::android::AttachCurrentThread;
-using base::android::ScopedJavaLocalRef;
-using base::android::ConvertJavaStringToUTF8;
-using base::android::GetApplicationContext;
-
-namespace content {
-
-std::string GetUserAgentOSInfo() {
- JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jstring> os_info =
- Java_UserAgent_getUserAgentOSInfo(env);
- return ConvertJavaStringToUTF8(os_info);
-}
-
-bool RegisterUserAgent(JNIEnv* env) {
- return RegisterNativesImpl(env);
-}
-
-} // namespace content
diff --git a/content/app/android/user_agent.h b/content/app/android/user_agent.h
deleted file mode 100644
index 374c5fb..0000000
--- a/content/app/android/user_agent.h
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CONTENT_APP_ANDROID_USER_AGENT_H_
-#define CONTENT_APP_ANDROID_USER_AGENT_H_
-
-#include <jni.h>
-#include <string>
-
-namespace content {
-
-// Returns the OS information component required by user agent composition.
-std::string GetUserAgentOSInfo();
-
-// Register JNI method.
-bool RegisterUserAgent(JNIEnv* env);
-
-} // namespace content
-
-#endif // CONTENT_APP_ANDROID_USER_AGENT_H_
diff --git a/content/content_app.gypi b/content/content_app.gypi
index 023bd00..adc924c 100644
--- a/content/content_app.gypi
+++ b/content/content_app.gypi
@@ -20,8 +20,6 @@
'app/android/library_loader_hooks.cc',
'app/android/sandboxed_process_service.cc',
'app/android/sandboxed_process_service.h',
- 'app/android/user_agent.cc',
- 'app/android/user_agent.h',
'app/content_main.cc',
'app/content_main_runner.cc',
'app/startup_helper_win.cc',
diff --git a/content/content_jni.gypi b/content/content_jni.gypi
index 30ac54d..929fb83 100644
--- a/content/content_jni.gypi
+++ b/content/content_jni.gypi
@@ -11,7 +11,6 @@
'public/android/java/src/org/chromium/content/app/ContentMain.java',
'public/android/java/src/org/chromium/content/app/LibraryLoader.java',
'public/android/java/src/org/chromium/content/app/SandboxedProcessService.java',
- 'public/android/java/src/org/chromium/content/app/UserAgent.java',
'public/android/java/src/org/chromium/content/browser/AndroidBrowserProcess.java',
'public/android/java/src/org/chromium/content/browser/ContentSettings.java',
'public/android/java/src/org/chromium/content/browser/ContentVideoView.java',
diff --git a/content/public/android/java/src/org/chromium/content/app/UserAgent.java b/content/public/android/java/src/org/chromium/content/app/UserAgent.java
deleted file mode 100644
index 36d328d..0000000
--- a/content/public/android/java/src/org/chromium/content/app/UserAgent.java
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package org.chromium.content.app;
-
-import android.os.Build;
-
-import org.chromium.base.CalledByNative;
-
-/**
- * Provides necessary information for building the user agent string.
- */
-class UserAgent {
- // TODO(yfriedman): Keep this reasonably up to date.
- private static final String PREVIOUS_VERSION = "4.0.3";
-
- @CalledByNative
- static String getUserAgentOSInfo() {
- String osInfo = "";
- final String version = Build.VERSION.RELEASE;
- if (version.length() > 0) {
- if (Character.isDigit(version.charAt(0))) {
- // Release is a version, eg "3.1"
- osInfo += version;
- } else {
- // Release doesn't have a version number yet, eg "Honeycomb"
- // In this case, use the previous release's version
- osInfo += PREVIOUS_VERSION;
- }
- } else {
- // default to "1.0"
- osInfo += "1.0";
- }
- osInfo += ";";
-
- if ("REL".equals(Build.VERSION.CODENAME)) {
- final String model = Build.MODEL;
- if (model.length() > 0) {
- osInfo += " " + model;
- }
- }
- final String id = Build.ID;
- if (id.length() > 0) {
- osInfo += " Build/" + id;
- }
-
- return osInfo;
- }
-}
diff --git a/webkit/glue/user_agent.cc b/webkit/glue/user_agent.cc
index 5165040..bfd1ff4 100644
--- a/webkit/glue/user_agent.cc
+++ b/webkit/glue/user_agent.cc
@@ -20,14 +20,6 @@
// Generated
#include "webkit_version.h" // NOLINT
-#if defined(OS_ANDROID)
-namespace {
-
-base::LazyInstance<std::string>::Leaky g_os_info = LAZY_INSTANCE_INITIALIZER;
-
-} // namespace
-#endif
-
namespace webkit_glue {
std::string GetWebKitVersion() {
@@ -44,7 +36,8 @@ std::string GetWebKitRevision() {
std::string BuildOSCpuInfo() {
std::string os_cpu;
-#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
+#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) ||\
+ defined(OS_ANDROID)
int32 os_major_version = 0;
int32 os_minor_version = 0;
int32 os_bugfix_version = 0;
@@ -52,6 +45,7 @@ std::string BuildOSCpuInfo() {
&os_minor_version,
&os_bugfix_version);
#endif
+
#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
// Should work on any Posix system.
struct utsname unixinfo;
@@ -82,6 +76,28 @@ std::string BuildOSCpuInfo() {
}
#endif
+#if defined(OS_ANDROID)
+ std::string android_info_str;
+
+ // Send information about the device.
+ bool semicolon_inserted = false;
+ std::string android_build_codename = base::SysInfo::GetAndroidBuildCodename();
+ std::string android_device_name = base::SysInfo::GetDeviceName();
+ if ("REL" == android_build_codename && android_device_name.size() > 0) {
+ android_info_str += "; " + android_device_name;
+ semicolon_inserted = true;
+ }
+
+ // Append the build ID.
+ std::string android_build_id = base::SysInfo::GetAndroidBuildID();
+ if (android_build_id.size() > 0) {
+ if (!semicolon_inserted) {
+ android_info_str += ";";
+ }
+ android_info_str += " Build/" + android_build_id;
+ }
+#endif
+
base::StringAppendF(
&os_cpu,
#if defined(OS_WIN)
@@ -102,8 +118,11 @@ std::string BuildOSCpuInfo() {
os_minor_version,
os_bugfix_version
#elif defined(OS_ANDROID)
- "Android %s",
- g_os_info.Get().c_str()
+ "Android %d.%d.%d%s",
+ os_major_version,
+ os_minor_version,
+ os_bugfix_version,
+ android_info_str.c_str()
#else
"%s %s",
unixinfo.sysname, // e.g. Linux
@@ -156,10 +175,4 @@ std::string BuildUserAgentFromProduct(const std::string& product) {
return user_agent;
}
-#if defined(OS_ANDROID)
-void SetUserAgentOSInfo(const std::string& os_info) {
- g_os_info.Get() = os_info;
-}
-#endif
-
} // namespace webkit_glue
diff --git a/webkit/glue/user_agent.h b/webkit/glue/user_agent.h
index 60f6e53..5d2594a 100644
--- a/webkit/glue/user_agent.h
+++ b/webkit/glue/user_agent.h
@@ -21,13 +21,6 @@ std::string GetWebKitVersion();
int GetWebKitMajorVersion();
int GetWebKitMinorVersion();
-#if defined(OS_ANDROID)
-// Sets the OS component of the user agent (e.g. "4.0.4; Galaxy Nexus
-// BUILD/IMM76K")
-// TODO(yfriedman): Remove this ASAP (http://crbug.com/131312)
-void SetUserAgentOSInfo(const std::string& os_info);
-#endif
-
// Helper function to generate a full user agent string from a short
// product name.
std::string BuildUserAgentFromProduct(const std::string& product);