Update V8 to version 4.5.86.
[chromium-blink-merge.git] / base / android / build_info.cc
blob075b8938a8f52d2aff8089e3f1af05ba3a28eb5f
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/android/build_info.h"
7 #include <string>
9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h"
11 #include "base/android/scoped_java_ref.h"
12 #include "base/logging.h"
13 #include "base/memory/singleton.h"
14 #include "jni/BuildInfo_jni.h"
16 namespace {
18 // The caller takes ownership of the returned const char*.
19 const char* StrDupJString(const base::android::JavaRef<jstring>& java_string) {
20 std::string str = ConvertJavaStringToUTF8(java_string);
21 return strdup(str.c_str());
24 } // namespace
26 namespace base {
27 namespace android {
29 struct BuildInfoSingletonTraits {
30 static BuildInfo* New() {
31 return new BuildInfo(AttachCurrentThread());
34 static void Delete(BuildInfo* x) {
35 // We're leaking this type, see kRegisterAtExit.
36 NOTREACHED();
39 static const bool kRegisterAtExit = false;
40 #ifndef NDEBUG
41 static const bool kAllowedToAccessOnNonjoinableThread = true;
42 #endif
45 BuildInfo::BuildInfo(JNIEnv* env)
46 : device_(StrDupJString(Java_BuildInfo_getDevice(env))),
47 manufacturer_(StrDupJString(Java_BuildInfo_getDeviceManufacturer(env))),
48 model_(StrDupJString(Java_BuildInfo_getDeviceModel(env))),
49 brand_(StrDupJString(Java_BuildInfo_getBrand(env))),
50 android_build_id_(StrDupJString(Java_BuildInfo_getAndroidBuildId(env))),
51 android_build_fp_(StrDupJString(
52 Java_BuildInfo_getAndroidBuildFingerprint(env))),
53 package_version_code_(StrDupJString(Java_BuildInfo_getPackageVersionCode(
54 env, GetApplicationContext()))),
55 package_version_name_(StrDupJString(Java_BuildInfo_getPackageVersionName(
56 env, GetApplicationContext()))),
57 package_label_(StrDupJString(Java_BuildInfo_getPackageLabel(
58 env, GetApplicationContext()))),
59 package_name_(StrDupJString(Java_BuildInfo_getPackageName(
60 env, GetApplicationContext()))),
61 build_type_(StrDupJString(Java_BuildInfo_getBuildType(env))),
62 sdk_int_(Java_BuildInfo_getSdkInt(env)),
63 has_apk_splits_(Java_BuildInfo_hasApkSplits(
64 env, GetApplicationContext())),
65 java_exception_info_(NULL) {
68 // static
69 BuildInfo* BuildInfo::GetInstance() {
70 return Singleton<BuildInfo, BuildInfoSingletonTraits >::get();
73 void BuildInfo::SetJavaExceptionInfo(const std::string& info) {
74 DCHECK(!java_exception_info_) << "info should be set only once.";
75 java_exception_info_ = strndup(info.c_str(), 4096);
78 void BuildInfo::ClearJavaExceptionInfo() {
79 delete java_exception_info_;
80 java_exception_info_ = nullptr;
83 // static
84 bool BuildInfo::RegisterBindings(JNIEnv* env) {
85 return RegisterNativesImpl(env);
88 } // namespace android
89 } // namespace base