1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_ANDROID_BUILD_INFO_H_
6 #define BASE_ANDROID_BUILD_INFO_H_
13 #include "base/base_export.h"
14 #include "base/memory/singleton.h"
19 // This enumeration maps to the values returned by BuildInfo::sdk_int(),
20 // indicating the Android release associated with a given SDK version.
22 SDK_VERSION_JELLY_BEAN = 16,
23 SDK_VERSION_JELLY_BEAN_MR1 = 17,
24 SDK_VERSION_JELLY_BEAN_MR2 = 18,
25 SDK_VERSION_KITKAT = 19,
26 SDK_VERSION_KITKAT_WEAR = 20,
27 SDK_VERSION_LOLLIPOP = 21,
28 SDK_VERSION_LOLLIPOP_MR1 = 22,
29 SDK_VERSION_MARSHMALLOW = 23,
30 SDK_VERSION_NOUGAT = 24,
31 SDK_VERSION_NOUGAT_MR1 = 25,
32 SDK_VERSION_OREO = 26,
33 SDK_VERSION_O_MR1 = 27,
42 // BuildInfo is a singleton class that stores android build and device
43 // information. It will be called from Android specific code and gets used
44 // primarily in crash reporting.
45 class BASE_EXPORT BuildInfo {
47 BuildInfo(const BuildInfo&) = delete;
48 BuildInfo& operator=(const BuildInfo&) = delete;
52 // Static factory method for getting the singleton BuildInfo instance.
53 // Note that ownership is not conferred on the caller and the BuildInfo in
54 // question isn't actually freed until shutdown. This is ok because there
55 // should only be one instance of BuildInfo ever created.
56 static BuildInfo* GetInstance();
58 // Const char* is used instead of std::strings because these values must be
59 // available even if the process is in a crash state. Sadly
60 // std::string.c_str() doesn't guarantee that memory won't be allocated when
62 const char* device() const {
66 const char* manufacturer() const {
70 const char* model() const {
74 const char* brand() const {
78 const char* android_build_id() const {
79 return android_build_id_;
82 const char* android_build_fp() const {
83 return android_build_fp_;
86 const char* gms_version_code() const {
87 return gms_version_code_;
90 // The package name of the host app which has loaded WebView, retrieved from
91 // the application context. In the context of the SDK Runtime, the package
92 // name of the app that owns this particular instance of the SDK Runtime will
93 // also be included. e.g.
94 // com.google.android.sdksandbox:com:com.example.myappwithads
95 const char* host_package_name() const { return host_package_name_; }
97 // The application name (e.g. "Chrome"). For WebView, this is name of the
98 // embedding app. In the context of the SDK Runtime, this is the name of the
99 // app that owns this particular instance of the SDK Runtime.
100 const char* host_version_code() const { return host_version_code_; }
102 // By default: same as versionCode. For WebView: versionCode of the embedding
103 // app. In the context of the SDK Runtime, this is the versionCode of the app
104 // that owns this particular instance of the SDK Runtime.
105 const char* host_package_label() const { return host_package_label_; }
107 const char* package_version_code() const {
108 return package_version_code_;
111 const char* package_version_name() const {
112 return package_version_name_;
115 const char* package_name() const {
116 return package_name_;
119 const char* custom_themes() const { return custom_themes_; }
121 const char* resources_version() const { return resources_version_; }
123 const char* build_type() const {
127 const char* board() const { return board_; }
129 const char* installer_package_name() const { return installer_package_name_; }
131 const char* abi_name() const { return abi_name_; }
133 int sdk_int() const {
137 // Returns the targetSdkVersion of the currently running app. If called from a
138 // library, this returns the embedding app's targetSdkVersion.
140 // This can only be compared to finalized SDK versions, never against
141 // pre-release Android versions. For pre-release Android versions, see the
142 // targetsAtLeast*() methods in BuildInfo.java.
143 int target_sdk_version() const { return target_sdk_version_; }
145 bool is_debug_android() const { return is_debug_android_; }
147 bool is_tv() const { return is_tv_; }
149 const char* version_incremental() const { return version_incremental_; }
151 const char* hardware() const { return hardware_; }
153 bool is_at_least_t() const { return is_at_least_t_; }
155 bool is_automotive() const { return is_automotive_; }
157 bool is_at_least_u() const { return is_at_least_u_; }
159 bool targets_at_least_u() const { return targets_at_least_u_; }
161 const char* codename() const { return codename_; }
163 // Available only on Android T+.
164 int32_t vulkan_deqp_level() const { return vulkan_deqp_level_; }
167 friend struct BuildInfoSingletonTraits;
169 explicit BuildInfo(const std::vector<std::string>& params);
171 // Const char* is used instead of std::strings because these values must be
172 // available even if the process is in a crash state. Sadly
173 // std::string.c_str() doesn't guarantee that memory won't be allocated when
175 const char* const brand_;
176 const char* const device_;
177 const char* const android_build_id_;
178 const char* const manufacturer_;
179 const char* const model_;
181 const char* const build_type_;
182 const char* const board_;
183 const char* const host_package_name_;
184 const char* const host_version_code_;
185 const char* const host_package_label_;
186 const char* const package_name_;
187 const char* const package_version_code_;
188 const char* const package_version_name_;
189 const char* const android_build_fp_;
190 const char* const gms_version_code_;
191 const char* const installer_package_name_;
192 const char* const abi_name_;
193 const char* const custom_themes_;
194 const char* const resources_version_;
195 // Not needed by breakpad.
196 const int target_sdk_version_;
197 const bool is_debug_android_;
199 const char* const version_incremental_;
200 const char* const hardware_;
201 const bool is_at_least_t_;
202 const bool is_automotive_;
203 const bool is_at_least_u_;
204 const bool targets_at_least_u_;
205 const char* const codename_;
206 const int32_t vulkan_deqp_level_;
209 } // namespace android
212 #endif // BASE_ANDROID_BUILD_INFO_H_