| 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/build_info_jni.h" | |
| 15 | |
| 16 namespace base { | |
| 17 namespace android { | |
| 18 | |
| 19 BuildInfo::BuildInfo() { | |
| 20 JNIEnv* env = AttachCurrentThread(); | |
| 21 | |
| 22 // The const char* pointers initialized below will be owned by the | |
| 23 // resultant BuildInfo. | |
| 24 std::string device_str = | |
| 25 ConvertJavaStringToUTF8(Java_BuildInfo_getDevice(env)); | |
| 26 device_ = strdup(device_str.c_str()); | |
| 27 | |
| 28 std::string model_str = | |
| 29 ConvertJavaStringToUTF8(Java_BuildInfo_getDeviceModel(env)); | |
| 30 model_ = strdup(model_str.c_str()); | |
| 31 | |
| 32 std::string brand_str = | |
| 33 ConvertJavaStringToUTF8(Java_BuildInfo_getBrand(env)); | |
| 34 brand_ = strdup(brand_str.c_str()); | |
| 35 | |
| 36 std::string android_build_id_str = | |
| 37 ConvertJavaStringToUTF8(Java_BuildInfo_getAndroidBuildId(env)); | |
| 38 android_build_id_ = strdup(android_build_id_str.c_str()); | |
| 39 | |
| 40 std::string android_build_fp_str = | |
| 41 ConvertJavaStringToUTF8(Java_BuildInfo_getAndroidBuildFingerprint(env)); | |
| 42 android_build_fp_ = strdup(android_build_fp_str.c_str()); | |
| 43 | |
| 44 jobject app_context = GetApplicationContext(); | |
| 45 std::string package_version_code_str = | |
| 46 ConvertJavaStringToUTF8(Java_BuildInfo_getPackageVersionCode( | |
| 47 env, app_context)); | |
| 48 package_version_code_ = strdup(package_version_code_str.c_str()); | |
| 49 | |
| 50 std::string package_version_name_str = | |
| 51 ConvertJavaStringToUTF8( | |
| 52 Java_BuildInfo_getPackageVersionName(env, app_context)); | |
| 53 package_version_name_ = strdup(package_version_name_str.c_str()); | |
| 54 } | |
| 55 | |
| 56 // static | |
| 57 BuildInfo* BuildInfo::GetInstance() { | |
| 58 return Singleton<BuildInfo, LeakySingletonTraits<BuildInfo> >::get(); | |
| 59 } | |
| 60 | |
| 61 bool RegisterBuildInfo(JNIEnv* env) { | |
| 62 return RegisterNativesImpl(env); | |
| 63 } | |
| 64 | |
| 65 } // namespace android | |
| 66 } // namespace base | |
| OLD | NEW |