Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(540)

Side by Side Diff: base/android/build_info.cc

Issue 2835113004: Revert of Android: Refactor BuildInfo to use less jni and remove StrictMode exception (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/android/build_info.h ('k') | base/android/java/src/org/chromium/base/BuildInfo.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/android/build_info.h" 5 #include "base/android/build_info.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_array.h" 10 #include "base/android/jni_string.h"
11 #include "base/android/scoped_java_ref.h" 11 #include "base/android/scoped_java_ref.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/singleton.h" 13 #include "base/memory/singleton.h"
14 #include "base/strings/string_number_conversions.h"
15 #include "jni/BuildInfo_jni.h" 14 #include "jni/BuildInfo_jni.h"
16 15
16 namespace {
17
18 // We are leaking these strings.
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
17 namespace base { 26 namespace base {
18 namespace android { 27 namespace android {
19 28
20 namespace {
21
22 // We are leaking these strings.
23 const char* StrDupParam(const std::vector<std::string>& params, int index) {
24 return strdup(params[index].c_str());
25 }
26
27 int SdkIntParam(const std::vector<std::string>& params, int index) {
28 int ret = 0;
29 DCHECK(StringToInt(params[index], &ret));
30 return ret;
31 }
32
33 } // namespace
34
35 struct BuildInfoSingletonTraits { 29 struct BuildInfoSingletonTraits {
36 static BuildInfo* New() { 30 static BuildInfo* New() {
37 JNIEnv* env = AttachCurrentThread(); 31 return new BuildInfo(AttachCurrentThread());
38 ScopedJavaLocalRef<jobjectArray> params_objs = Java_BuildInfo_getAll(env);
39 std::vector<std::string> params;
40 AppendJavaStringArrayToStringVector(env, params_objs.obj(), &params);
41 return new BuildInfo(params);
42 } 32 }
43 33
44 static void Delete(BuildInfo* x) { 34 static void Delete(BuildInfo* x) {
45 // We're leaking this type, see kRegisterAtExit. 35 // We're leaking this type, see kRegisterAtExit.
46 NOTREACHED(); 36 NOTREACHED();
47 } 37 }
48 38
49 static const bool kRegisterAtExit = false; 39 static const bool kRegisterAtExit = false;
50 #if DCHECK_IS_ON() 40 #if DCHECK_IS_ON()
51 static const bool kAllowedToAccessOnNonjoinableThread = true; 41 static const bool kAllowedToAccessOnNonjoinableThread = true;
52 #endif 42 #endif
53 }; 43 };
54 44
55 BuildInfo::BuildInfo(const std::vector<std::string>& params) 45 BuildInfo::BuildInfo(JNIEnv* env)
56 : brand_(StrDupParam(params, 0)), 46 : device_(StrDupJString(Java_BuildInfo_getDevice(env))),
57 device_(StrDupParam(params, 1)), 47 manufacturer_(StrDupJString(Java_BuildInfo_getDeviceManufacturer(env))),
58 android_build_id_(StrDupParam(params, 2)), 48 model_(StrDupJString(Java_BuildInfo_getDeviceModel(env))),
59 manufacturer_(StrDupParam(params, 3)), 49 brand_(StrDupJString(Java_BuildInfo_getBrand(env))),
60 model_(StrDupParam(params, 4)), 50 android_build_id_(StrDupJString(Java_BuildInfo_getAndroidBuildId(env))),
61 sdk_int_(SdkIntParam(params, 5)), 51 android_build_fp_(
62 build_type_(StrDupParam(params, 6)), 52 StrDupJString(Java_BuildInfo_getAndroidBuildFingerprint(env))),
63 package_label_(StrDupParam(params, 7)), 53 gms_version_code_(StrDupJString(Java_BuildInfo_getGMSVersionCode(env))),
64 package_name_(StrDupParam(params, 8)), 54 package_version_code_(
65 package_version_code_(StrDupParam(params, 9)), 55 StrDupJString(Java_BuildInfo_getPackageVersionCode(env))),
66 package_version_name_(StrDupParam(params, 10)), 56 package_version_name_(
67 android_build_fp_(StrDupParam(params, 11)), 57 StrDupJString(Java_BuildInfo_getPackageVersionName(env))),
68 gms_version_code_(StrDupParam(params, 12)), 58 package_label_(StrDupJString(Java_BuildInfo_getPackageLabel(env))),
69 extracted_file_suffix_(params[13]), 59 package_name_(StrDupJString(Java_BuildInfo_getPackageName(env))),
60 build_type_(StrDupJString(Java_BuildInfo_getBuildType(env))),
61 extracted_file_suffix_(
62 ConvertJavaStringToUTF8(Java_BuildInfo_getExtractedFileSuffix(env))),
63 sdk_int_(Java_BuildInfo_getSdkInt(env)),
70 java_exception_info_(NULL) {} 64 java_exception_info_(NULL) {}
71 65
72 // static 66 // static
73 BuildInfo* BuildInfo::GetInstance() { 67 BuildInfo* BuildInfo::GetInstance() {
74 return Singleton<BuildInfo, BuildInfoSingletonTraits >::get(); 68 return Singleton<BuildInfo, BuildInfoSingletonTraits >::get();
75 } 69 }
76 70
77 void BuildInfo::SetJavaExceptionInfo(const std::string& info) { 71 void BuildInfo::SetJavaExceptionInfo(const std::string& info) {
78 DCHECK(!java_exception_info_) << "info should be set only once."; 72 DCHECK(!java_exception_info_) << "info should be set only once.";
79 java_exception_info_ = strndup(info.c_str(), 4096); 73 java_exception_info_ = strndup(info.c_str(), 4096);
80 } 74 }
81 75
82 void BuildInfo::ClearJavaExceptionInfo() { 76 void BuildInfo::ClearJavaExceptionInfo() {
83 delete java_exception_info_; 77 delete java_exception_info_;
84 java_exception_info_ = nullptr; 78 java_exception_info_ = nullptr;
85 } 79 }
86 80
87 } // namespace android 81 } // namespace android
88 } // namespace base 82 } // namespace base
OLDNEW
« no previous file with comments | « base/android/build_info.h ('k') | base/android/java/src/org/chromium/base/BuildInfo.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698