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. 4 5 #ifndef BASE_ANDROID_BUILD_INFO_H_ 6 #define BASE_ANDROID_BUILD_INFO_H_ 7 8 #include <jni.h> 9 10 #include <string> 11 #include <vector> 12 13 #include "base/base_export.h" 14 #include "base/memory/singleton.h" 15 16 namespace base::android { 17 18 // This enumeration maps to the values returned by BuildInfo::sdk_int(), 19 // indicating the Android release associated with a given SDK version. 20 enum SdkVersion { 21 SDK_VERSION_JELLY_BEAN = 16, 22 SDK_VERSION_JELLY_BEAN_MR1 = 17, 23 SDK_VERSION_JELLY_BEAN_MR2 = 18, 24 SDK_VERSION_KITKAT = 19, 25 SDK_VERSION_KITKAT_WEAR = 20, 26 SDK_VERSION_LOLLIPOP = 21, 27 SDK_VERSION_LOLLIPOP_MR1 = 22, 28 SDK_VERSION_MARSHMALLOW = 23, 29 SDK_VERSION_NOUGAT = 24, 30 SDK_VERSION_NOUGAT_MR1 = 25, 31 SDK_VERSION_OREO = 26, 32 SDK_VERSION_O_MR1 = 27, 33 SDK_VERSION_P = 28, 34 SDK_VERSION_Q = 29, 35 SDK_VERSION_R = 30, 36 SDK_VERSION_S = 31, 37 SDK_VERSION_Sv2 = 32, 38 SDK_VERSION_T = 33, 39 SDK_VERSION_U = 34, 40 }; 41 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 { 46 public: 47 BuildInfo(const BuildInfo&) = delete; 48 BuildInfo& operator=(const BuildInfo&) = delete; 49 ~BuildInfo()50 ~BuildInfo() {} 51 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(); 57 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 61 // it is called. device()62 const char* device() const { 63 return device_; 64 } 65 manufacturer()66 const char* manufacturer() const { 67 return manufacturer_; 68 } 69 model()70 const char* model() const { 71 return model_; 72 } 73 brand()74 const char* brand() const { 75 return brand_; 76 } 77 android_build_id()78 const char* android_build_id() const { 79 return android_build_id_; 80 } 81 android_build_fp()82 const char* android_build_fp() const { 83 return android_build_fp_; 84 } 85 gms_version_code()86 const char* gms_version_code() const { 87 return gms_version_code_; 88 } 89 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 host_package_name()95 const char* host_package_name() const { return host_package_name_; } 96 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. host_version_code()100 const char* host_version_code() const { return host_version_code_; } 101 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. host_package_label()105 const char* host_package_label() const { return host_package_label_; } 106 package_version_code()107 const char* package_version_code() const { 108 return package_version_code_; 109 } 110 package_version_name()111 const char* package_version_name() const { 112 return package_version_name_; 113 } 114 package_name()115 const char* package_name() const { 116 return package_name_; 117 } 118 custom_themes()119 const char* custom_themes() const { return custom_themes_; } 120 resources_version()121 const char* resources_version() const { return resources_version_; } 122 build_type()123 const char* build_type() const { 124 return build_type_; 125 } 126 board()127 const char* board() const { return board_; } 128 installer_package_name()129 const char* installer_package_name() const { return installer_package_name_; } 130 abi_name()131 const char* abi_name() const { return abi_name_; } 132 sdk_int()133 int sdk_int() const { 134 return sdk_int_; 135 } 136 137 // Returns the targetSdkVersion of the currently running app. If called from a 138 // library, this returns the embedding app's targetSdkVersion. 139 // 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. target_sdk_version()143 int target_sdk_version() const { return target_sdk_version_; } 144 is_debug_android()145 bool is_debug_android() const { return is_debug_android_; } 146 is_tv()147 bool is_tv() const { return is_tv_; } 148 version_incremental()149 const char* version_incremental() const { return version_incremental_; } 150 hardware()151 const char* hardware() const { return hardware_; } 152 is_at_least_t()153 bool is_at_least_t() const { return is_at_least_t_; } 154 is_automotive()155 bool is_automotive() const { return is_automotive_; } 156 is_at_least_u()157 bool is_at_least_u() const { return is_at_least_u_; } 158 targets_at_least_u()159 bool targets_at_least_u() const { return targets_at_least_u_; } 160 codename()161 const char* codename() const { return codename_; } 162 is_foldable()163 bool is_foldable() const { return is_foldable_; } 164 165 // Available only on Android T+. vulkan_deqp_level()166 int32_t vulkan_deqp_level() const { return vulkan_deqp_level_; } 167 168 private: 169 friend struct BuildInfoSingletonTraits; 170 171 explicit BuildInfo(const std::vector<std::string>& params); 172 173 // Const char* is used instead of std::strings because these values must be 174 // available even if the process is in a crash state. Sadly 175 // std::string.c_str() doesn't guarantee that memory won't be allocated when 176 // it is called. 177 const char* const brand_; 178 const char* const device_; 179 const char* const android_build_id_; 180 const char* const manufacturer_; 181 const char* const model_; 182 const int sdk_int_; 183 const char* const build_type_; 184 const char* const board_; 185 const char* const host_package_name_; 186 const char* const host_version_code_; 187 const char* const host_package_label_; 188 const char* const package_name_; 189 const char* const package_version_code_; 190 const char* const package_version_name_; 191 const char* const android_build_fp_; 192 const char* const gms_version_code_; 193 const char* const installer_package_name_; 194 const char* const abi_name_; 195 const char* const custom_themes_; 196 const char* const resources_version_; 197 // Not needed by breakpad. 198 const int target_sdk_version_; 199 const bool is_debug_android_; 200 const bool is_tv_; 201 const char* const version_incremental_; 202 const char* const hardware_; 203 const bool is_at_least_t_; 204 const bool is_automotive_; 205 const bool is_at_least_u_; 206 const bool targets_at_least_u_; 207 const char* const codename_; 208 const int32_t vulkan_deqp_level_; 209 const bool is_foldable_; 210 }; 211 212 } // namespace base::android 213 214 #endif // BASE_ANDROID_BUILD_INFO_H_ 215