| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "base/android/build_info.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 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" | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 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()); | |
| 22 } | |
| 23 | |
| 24 } // namespace | |
| 25 | |
| 26 namespace base { | |
| 27 namespace android { | |
| 28 | |
| 29 struct BuildInfoSingletonTraits { | |
| 30 static BuildInfo* New() { | |
| 31 return new BuildInfo(AttachCurrentThread()); | |
| 32 } | |
| 33 | |
| 34 static void Delete(BuildInfo* x) { | |
| 35 // We're leaking this type, see kRegisterAtExit. | |
| 36 NOTREACHED(); | |
| 37 } | |
| 38 | |
| 39 static const bool kRegisterAtExit = false; | |
| 40 #ifndef NDEBUG | |
| 41 static const bool kAllowedToAccessOnNonjoinableThread = true; | |
| 42 #endif | |
| 43 }; | |
| 44 | |
| 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_( | |
| 52 StrDupJString(Java_BuildInfo_getAndroidBuildFingerprint(env))), | |
| 53 package_version_code_(StrDupJString( | |
| 54 Java_BuildInfo_getPackageVersionCode(env, GetApplicationContext()))), | |
| 55 package_version_name_(StrDupJString( | |
| 56 Java_BuildInfo_getPackageVersionName(env, GetApplicationContext()))), | |
| 57 package_label_(StrDupJString( | |
| 58 Java_BuildInfo_getPackageLabel(env, GetApplicationContext()))), | |
| 59 package_name_(StrDupJString( | |
| 60 Java_BuildInfo_getPackageName(env, GetApplicationContext()))), | |
| 61 build_type_(StrDupJString(Java_BuildInfo_getBuildType(env))), | |
| 62 sdk_int_(Java_BuildInfo_getSdkInt(env)), | |
| 63 has_language_apk_splits_( | |
| 64 Java_BuildInfo_hasLanguageApkSplits(env, GetApplicationContext())), | |
| 65 java_exception_info_(NULL) {} | |
| 66 | |
| 67 // static | |
| 68 BuildInfo* BuildInfo::GetInstance() { | |
| 69 return Singleton<BuildInfo, BuildInfoSingletonTraits >::get(); | |
| 70 } | |
| 71 | |
| 72 void BuildInfo::SetJavaExceptionInfo(const std::string& info) { | |
| 73 DCHECK(!java_exception_info_) << "info should be set only once."; | |
| 74 java_exception_info_ = strndup(info.c_str(), 4096); | |
| 75 } | |
| 76 | |
| 77 void BuildInfo::ClearJavaExceptionInfo() { | |
| 78 delete java_exception_info_; | |
| 79 java_exception_info_ = nullptr; | |
| 80 } | |
| 81 | |
| 82 // static | |
| 83 bool BuildInfo::RegisterBindings(JNIEnv* env) { | |
| 84 return RegisterNativesImpl(env); | |
| 85 } | |
| 86 | |
| 87 } // namespace android | |
| 88 } // namespace base | |
| OLD | NEW |