1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
base / android / build_info.cc [blame]
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/android/build_info.h"
#include <string>
#include "base/android/jni_android.h"
#include "base/android/jni_array.h"
#include "base/android/jni_string.h"
#include "base/android/scoped_java_ref.h"
#include "base/check_op.h"
#include "base/memory/singleton.h"
#include "base/notreached.h"
#include "base/strings/string_number_conversions.h"
// Must come after all headers that specialize FromJniType() / ToJniType().
#include "base/base_jni/BuildInfo_jni.h"
namespace base {
namespace android {
namespace {
// We are leaking these strings.
const char* StrDupParam(const std::vector<std::string>& params, size_t index) {
return strdup(params[index].c_str());
}
int GetIntParam(const std::vector<std::string>& params, size_t index) {
int ret = 0;
bool success = StringToInt(params[index], &ret);
DCHECK(success);
return ret;
}
} // namespace
struct BuildInfoSingletonTraits {
static BuildInfo* New() {
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobjectArray> params_objs = Java_BuildInfo_getAll(env);
std::vector<std::string> params;
AppendJavaStringArrayToStringVector(env, params_objs, ¶ms);
return new BuildInfo(params);
}
static void Delete(BuildInfo* x) {
// We're leaking this type, see kRegisterAtExit.
NOTREACHED();
}
static const bool kRegisterAtExit = false;
#if DCHECK_IS_ON()
static const bool kAllowedToAccessOnNonjoinableThread = true;
#endif
};
BuildInfo::BuildInfo(const std::vector<std::string>& params)
: brand_(StrDupParam(params, 0)),
device_(StrDupParam(params, 1)),
android_build_id_(StrDupParam(params, 2)),
manufacturer_(StrDupParam(params, 3)),
model_(StrDupParam(params, 4)),
sdk_int_(GetIntParam(params, 5)),
build_type_(StrDupParam(params, 6)),
board_(StrDupParam(params, 7)),
host_package_name_(StrDupParam(params, 8)),
host_version_code_(StrDupParam(params, 9)),
host_package_label_(StrDupParam(params, 10)),
package_name_(StrDupParam(params, 11)),
package_version_code_(StrDupParam(params, 12)),
package_version_name_(StrDupParam(params, 13)),
android_build_fp_(StrDupParam(params, 14)),
gms_version_code_(StrDupParam(params, 15)),
installer_package_name_(StrDupParam(params, 16)),
abi_name_(StrDupParam(params, 17)),
custom_themes_(StrDupParam(params, 18)),
resources_version_(StrDupParam(params, 19)),
target_sdk_version_(GetIntParam(params, 20)),
is_debug_android_(GetIntParam(params, 21)),
is_tv_(GetIntParam(params, 22)),
version_incremental_(StrDupParam(params, 23)),
hardware_(StrDupParam(params, 24)),
is_at_least_t_(GetIntParam(params, 25)),
is_automotive_(GetIntParam(params, 26)),
is_at_least_u_(GetIntParam(params, 27)),
targets_at_least_u_(GetIntParam(params, 28)),
codename_(StrDupParam(params, 29)),
vulkan_deqp_level_(GetIntParam(params, 30)),
is_foldable_(GetIntParam(params, 31)),
soc_manufacturer_(StrDupParam(params, 32)),
is_debug_app_(GetIntParam(params, 33)),
is_desktop_(GetIntParam(params, 34)) {}
BuildInfo::~BuildInfo() = default;
void BuildInfo::set_gms_version_code_for_test(
const std::string& gms_version_code) {
// This leaks the string, just like production code.
gms_version_code_ = strdup(gms_version_code.c_str());
Java_BuildInfo_setGmsVersionCodeForTest(AttachCurrentThread(),
gms_version_code);
}
std::string BuildInfo::host_signing_cert_sha256() {
JNIEnv* env = AttachCurrentThread();
return Java_BuildInfo_lazyGetHostSigningCertSha256(env);
}
// static
BuildInfo* BuildInfo::GetInstance() {
return Singleton<BuildInfo, BuildInfoSingletonTraits >::get();
}
} // namespace android
} // namespace base