Android: remove device_data.h from browser/device_orientation/
[chromium-blink-merge.git] / base / android / build_info.cc
blobcdde6a90052f732f596f2ef142bdbd503bbf8ec5
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 static const bool kAllowedToAccessOnNonjoinableThread = true;
43 BuildInfo::BuildInfo(JNIEnv* env)
44 : device_(StrDupJString(Java_BuildInfo_getDevice(env))),
45 model_(StrDupJString(Java_BuildInfo_getDeviceModel(env))),
46 brand_(StrDupJString(Java_BuildInfo_getBrand(env))),
47 android_build_id_(StrDupJString(Java_BuildInfo_getAndroidBuildId(env))),
48 android_build_fp_(StrDupJString(
49 Java_BuildInfo_getAndroidBuildFingerprint(env))),
50 package_version_code_(StrDupJString(Java_BuildInfo_getPackageVersionCode(
51 env, GetApplicationContext()))),
52 package_version_name_(StrDupJString(Java_BuildInfo_getPackageVersionName(
53 env, GetApplicationContext()))),
54 package_label_(StrDupJString(Java_BuildInfo_getPackageLabel(
55 env, GetApplicationContext()))),
56 package_name_(StrDupJString(Java_BuildInfo_getPackageName(
57 env, GetApplicationContext()))),
58 sdk_int_(Java_BuildInfo_getSdkInt(env)),
59 java_exception_info_(NULL) {
62 // static
63 BuildInfo* BuildInfo::GetInstance() {
64 return Singleton<BuildInfo, BuildInfoSingletonTraits >::get();
67 void BuildInfo::set_java_exception_info(const std::string& info) {
68 DCHECK(!java_exception_info_) << "info should be set only once.";
69 java_exception_info_ = strndup(info.c_str(), 1024);
72 // static
73 bool BuildInfo::RegisterBindings(JNIEnv* env) {
74 return RegisterNativesImpl(env);
77 } // namespace android
78 } // namespace base