summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorcarlosvaldivia@google.com <carlosvaldivia@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-10 22:52:44 +0000
committercarlosvaldivia@google.com <carlosvaldivia@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-10 22:52:44 +0000
commit6653c19c044e724ad9a93248611abd2135d16a1a (patch)
tree1e036d686937704495302c125d7f3f200a521470 /base
parentb168ddfb28b4d83213dcfd5974ba64d2dc964030 (diff)
downloadchromium_src-6653c19c044e724ad9a93248611abd2135d16a1a.zip
chromium_src-6653c19c044e724ad9a93248611abd2135d16a1a.tar.gz
chromium_src-6653c19c044e724ad9a93248611abd2135d16a1a.tar.bz2
Upstream crash changes for android.
Third time is a charm. Original Reviews: https://chromiumcodereview.appspot.com/9838033/ http://codereview.chromium.org/9967017 Revert "Revert 131593" This reverts commit e306ea7f630d4264075913ea3a1a728d98ca9605. BUG= TEST= Review URL: http://codereview.chromium.org/9960072 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131662 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/android/build_info.cc66
-rw-r--r--base/android/build_info.h88
-rw-r--r--base/android/java/org/chromium/base/BuildInfo.java88
-rw-r--r--base/base.gyp2
-rw-r--r--base/base.gypi2
5 files changed, 246 insertions, 0 deletions
diff --git a/base/android/build_info.cc b/base/android/build_info.cc
new file mode 100644
index 0000000..157ce42
--- /dev/null
+++ b/base/android/build_info.cc
@@ -0,0 +1,66 @@
+// 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 "base/android/build_info.h"
+
+#include <string>
+
+#include "base/android/jni_android.h"
+#include "base/android/jni_string.h"
+#include "base/android/scoped_java_ref.h"
+#include "base/logging.h"
+#include "base/memory/singleton.h"
+#include "jni/build_info_jni.h"
+
+namespace base {
+namespace android {
+
+BuildInfo::BuildInfo() {
+ JNIEnv* env = AttachCurrentThread();
+
+ // The const char* pointers initialized below will be owned by the
+ // resultant BuildInfo.
+ std::string device_str =
+ ConvertJavaStringToUTF8(Java_BuildInfo_getDevice(env));
+ device_ = strdup(device_str.c_str());
+
+ std::string model_str =
+ ConvertJavaStringToUTF8(Java_BuildInfo_getDeviceModel(env));
+ model_ = strdup(model_str.c_str());
+
+ std::string brand_str =
+ ConvertJavaStringToUTF8(Java_BuildInfo_getBrand(env));
+ brand_ = strdup(brand_str.c_str());
+
+ std::string android_build_id_str =
+ ConvertJavaStringToUTF8(Java_BuildInfo_getAndroidBuildId(env));
+ android_build_id_ = strdup(android_build_id_str.c_str());
+
+ std::string android_build_fp_str =
+ ConvertJavaStringToUTF8(Java_BuildInfo_getAndroidBuildFingerprint(env));
+ android_build_fp_ = strdup(android_build_fp_str.c_str());
+
+ jobject app_context = GetApplicationContext();
+ std::string package_version_code_str =
+ ConvertJavaStringToUTF8(Java_BuildInfo_getPackageVersionCode(
+ env, app_context));
+ package_version_code_ = strdup(package_version_code_str.c_str());
+
+ std::string package_version_name_str =
+ ConvertJavaStringToUTF8(
+ Java_BuildInfo_getPackageVersionName(env, app_context));
+ package_version_name_ = strdup(package_version_name_str.c_str());
+}
+
+// static
+BuildInfo* BuildInfo::GetInstance() {
+ return Singleton<BuildInfo, LeakySingletonTraits<BuildInfo> >::get();
+}
+
+bool RegisterBuildInfo(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+} // namespace android
+} // namespace base
diff --git a/base/android/build_info.h b/base/android/build_info.h
new file mode 100644
index 0000000..95a0cf5
--- /dev/null
+++ b/base/android/build_info.h
@@ -0,0 +1,88 @@
+// 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 BASE_ANDROID_BUILD_INFO_H_
+#define BASE_ANDROID_BUILD_INFO_H_
+
+#include <jni.h>
+
+#include <string>
+
+#include "base/memory/singleton.h"
+
+namespace base {
+namespace android {
+
+// BuildInfo is a singleton class that stores android build and device
+// information. It will be called from Android specific java code and gets used
+// primarily in crash reporting.
+class BuildInfo {
+ public:
+
+ ~BuildInfo() {}
+
+ // Static factory method for getting the singleton BuildInfo instance.
+ // Note that ownership is not conferred on the caller and the BuildInfo in
+ // question isn't actually freed until shutdown. This is ok because there
+ // should only be one instance of BuildInfo ever created.
+ static BuildInfo* GetInstance();
+
+ // Const char* is used instead of std::strings because these values must be
+ // available even if the process is in a crash state. Sadly
+ // std::string.c_str() doesn't guarantee that memory won't be allocated when
+ // it is called.
+ const char* device() const {
+ return device_;
+ }
+
+ const char* model() const {
+ return model_;
+ }
+
+ const char* brand() const {
+ return brand_;
+ }
+
+ const char* android_build_id() const {
+ return android_build_id_;
+ }
+
+ const char* android_build_fp() const {
+ return android_build_fp_;
+ }
+
+ const char* package_version_code() const {
+ return package_version_code_;
+ }
+
+ const char* package_version_name() const {
+ return package_version_name_;
+ }
+
+ private:
+ BuildInfo();
+
+ friend struct DefaultSingletonTraits<BuildInfo>;
+
+ // Const char* is used instead of std::strings because these values must be
+ // available even if the process is in a crash state. Sadly
+ // std::string.c_str() doesn't guarantee that memory won't be allocated when
+ // it is called.
+ char* device_;
+ char* model_;
+ char* brand_;
+ char* android_build_id_;
+ char* android_build_fp_;
+ char* package_version_code_;
+ char* package_version_name_;
+
+ DISALLOW_COPY_AND_ASSIGN(BuildInfo);
+};
+
+bool RegisterBuildInfo(JNIEnv* env);
+
+} // namespace android
+} // namespace base
+
+#endif // BASE_ANDROID_BUILD_INFO_H_
diff --git a/base/android/java/org/chromium/base/BuildInfo.java b/base/android/java/org/chromium/base/BuildInfo.java
new file mode 100644
index 0000000..75748ac
--- /dev/null
+++ b/base/android/java/org/chromium/base/BuildInfo.java
@@ -0,0 +1,88 @@
+// 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.base;
+
+import android.content.Context;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.os.Build;
+import android.util.Log;
+
+/**
+ * BuildInfo is a utility class providing easy access to {@link PackageInfo}
+ * information. This is primarly of use for accessesing package information
+ * from native code.
+ */
+public class BuildInfo {
+ private static final String TAG = "BuildInfo";
+ private static final int MAX_FINGERPRINT_LENGTH = 128;
+
+ /**
+ * BuildInfo is a static utility class and therefore should'nt be
+ * instantiated.
+ */
+ private BuildInfo() {
+ }
+
+ @CalledByNative
+ public static String getDevice() {
+ return Build.DEVICE;
+ }
+
+ @CalledByNative
+ public static String getBrand() {
+ return Build.BRAND;
+ }
+
+ @CalledByNative
+ public static String getAndroidBuildId() {
+ return Build.ID;
+ }
+
+ /**
+ * @return The build fingerprint for the current Android install. The value is truncated to a
+ * 128 characters as this is used for crash and UMA reporting, which should avoid huge
+ * strings.
+ */
+ @CalledByNative
+ public static String getAndroidBuildFingerprint() {
+ return Build.FINGERPRINT.substring(
+ 0, Math.min(Build.FINGERPRINT.length(), MAX_FINGERPRINT_LENGTH));
+ }
+
+ @CalledByNative
+ public static String getDeviceModel() {
+ return Build.MODEL;
+ }
+
+ @CalledByNative
+ public static String getPackageVersionCode(Context context) {
+ String msg = "versionCode not available.";
+ try {
+ PackageManager pm = context.getPackageManager();
+ PackageInfo pi = pm.getPackageInfo("com.android.chrome", 0);
+ msg = "" + pi.versionCode;
+ } catch (NameNotFoundException e) {
+ Log.d(TAG, msg);
+ }
+ return msg;
+
+ }
+
+ @CalledByNative
+ public static String getPackageVersionName(Context context) {
+ String msg = "versionName not available";
+ try {
+ PackageManager pm = context.getPackageManager();
+ PackageInfo pi = pm.getPackageInfo("com.android.chrome", 0);
+ msg = pi.versionName;
+ } catch (NameNotFoundException e) {
+ Log.d(TAG, msg);
+ }
+ return msg;
+ }
+
+}
diff --git a/base/base.gyp b/base/base.gyp
index 4225f7e..c6058873 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -122,10 +122,12 @@
'action_name': 'generate_jni_headers',
'inputs': [
'android/jni_generator/jni_generator.py',
+ 'android/java/org/chromium/base/BuildInfo.java',
'android/java/org/chromium/base/PathUtils.java',
'android/java/org/chromium/base/SystemMessageHandler.java',
],
'outputs': [
+ '<(SHARED_INTERMEDIATE_DIR)/base/jni/build_info_jni.h',
'<(SHARED_INTERMEDIATE_DIR)/base/jni/path_utils_jni.h',
'<(SHARED_INTERMEDIATE_DIR)/base/jni/system_message_handler_jni.h',
],
diff --git a/base/base.gypi b/base/base.gypi
index facb472..48812a0 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -21,6 +21,8 @@
'third_party/nspr/prtime.h',
'third_party/nspr/prcpucfg_linux.h',
'third_party/xdg_mime/xdgmime.h',
+ 'android/build_info.cc',
+ 'android/build_info.h',
'android/scoped_java_ref.cc',
'android/scoped_java_ref.h',
'android/jni_android.cc',