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 SDK_VERSION_V = 35, 41 }; 42 43 // BuildInfo is a singleton class that stores android build and device 44 // information. It will be called from Android specific code and gets used 45 // primarily in crash reporting. 46 class BASE_EXPORT BuildInfo { 47 public: 48 BuildInfo(const BuildInfo&) = delete; 49 BuildInfo& operator=(const BuildInfo&) = delete; 50 51 ~BuildInfo(); 52 53 // Static factory method for getting the singleton BuildInfo instance. 54 // Note that ownership is not conferred on the caller and the BuildInfo in 55 // question isn't actually freed until shutdown. This is ok because there 56 // should only be one instance of BuildInfo ever created. 57 static BuildInfo* GetInstance(); 58 59 // Const char* is used instead of std::strings because these values must be 60 // available even if the process is in a crash state. Sadly 61 // std::string.c_str() doesn't guarantee that memory won't be allocated when 62 // it is called. device()63 const char* device() const { 64 return device_; 65 } 66 manufacturer()67 const char* manufacturer() const { 68 return manufacturer_; 69 } 70 model()71 const char* model() const { 72 return model_; 73 } 74 brand()75 const char* brand() const { 76 return brand_; 77 } 78 android_build_id()79 const char* android_build_id() const { 80 return android_build_id_; 81 } 82 android_build_fp()83 const char* android_build_fp() const { 84 return android_build_fp_; 85 } 86 gms_version_code()87 const char* gms_version_code() const { 88 return gms_version_code_; 89 } 90 91 void set_gms_version_code_for_test(const std::string& gms_version_code); 92 93 // The package name of the host app which has loaded WebView, retrieved from 94 // the application context. In the context of the SDK Runtime, the package 95 // name of the app that owns this particular instance of the SDK Runtime will 96 // also be included. e.g. 97 // com.google.android.sdksandbox:com:com.example.myappwithads host_package_name()98 const char* host_package_name() const { return host_package_name_; } 99 100 // The application name (e.g. "Chrome"). For WebView, this is name of the 101 // embedding app. In the context of the SDK Runtime, this is the name of the 102 // app that owns this particular instance of the SDK Runtime. host_version_code()103 const char* host_version_code() const { return host_version_code_; } 104 105 // By default: same as versionCode. For WebView: versionCode of the embedding 106 // app. In the context of the SDK Runtime, this is the versionCode of the app 107 // that owns this particular instance of the SDK Runtime. host_package_label()108 const char* host_package_label() const { return host_package_label_; } 109 110 // The SHA256 of the public certificate used to sign the host application. 111 // This will default to an empty string if we were unable to retrieve it. 112 std::string host_signing_cert_sha256(); 113 package_version_code()114 const char* package_version_code() const { 115 return package_version_code_; 116 } 117 package_version_name()118 const char* package_version_name() const { 119 return package_version_name_; 120 } 121 package_name()122 const char* package_name() const { 123 return package_name_; 124 } 125 custom_themes()126 const char* custom_themes() const { return custom_themes_; } 127 resources_version()128 const char* resources_version() const { return resources_version_; } 129 build_type()130 const char* build_type() const { 131 return build_type_; 132 } 133 board()134 const char* board() const { return board_; } 135 installer_package_name()136 const char* installer_package_name() const { return installer_package_name_; } 137 abi_name()138 const char* abi_name() const { return abi_name_; } 139 sdk_int()140 int sdk_int() const { 141 return sdk_int_; 142 } 143 144 // Returns the targetSdkVersion of the currently running app. If called from a 145 // library, this returns the embedding app's targetSdkVersion. 146 // 147 // This can only be compared to finalized SDK versions, never against 148 // pre-release Android versions. For pre-release Android versions, see the 149 // targetsAtLeast*() methods in BuildInfo.java. target_sdk_version()150 int target_sdk_version() const { return target_sdk_version_; } 151 is_debug_android()152 bool is_debug_android() const { return is_debug_android_; } 153 is_tv()154 bool is_tv() const { return is_tv_; } 155 version_incremental()156 const char* version_incremental() const { return version_incremental_; } 157 hardware()158 const char* hardware() const { return hardware_; } 159 is_at_least_t()160 bool is_at_least_t() const { return is_at_least_t_; } 161 is_automotive()162 bool is_automotive() const { return is_automotive_; } 163 is_at_least_u()164 bool is_at_least_u() const { return is_at_least_u_; } 165 targets_at_least_u()166 bool targets_at_least_u() const { return targets_at_least_u_; } 167 codename()168 const char* codename() const { return codename_; } 169 is_foldable()170 bool is_foldable() const { return is_foldable_; } 171 is_desktop()172 bool is_desktop() const { return is_desktop_; } 173 174 // Available only on Android T+. vulkan_deqp_level()175 int32_t vulkan_deqp_level() const { return vulkan_deqp_level_; } 176 177 // Available only on android S+. For S-, this method returns empty string. soc_manufacturer()178 const char* soc_manufacturer() const { return soc_manufacturer_; } 179 is_debug_app()180 bool is_debug_app() const { return is_debug_app_; } 181 182 private: 183 friend struct BuildInfoSingletonTraits; 184 185 explicit BuildInfo(const std::vector<std::string>& params); 186 187 // Const char* is used instead of std::strings because these values must be 188 // available even if the process is in a crash state. Sadly 189 // std::string.c_str() doesn't guarantee that memory won't be allocated when 190 // it is called. 191 const char* const brand_; 192 const char* const device_; 193 const char* const android_build_id_; 194 const char* const manufacturer_; 195 const char* const model_; 196 const int sdk_int_; 197 const char* const build_type_; 198 const char* const board_; 199 const char* const host_package_name_; 200 const char* const host_version_code_; 201 const char* const host_package_label_; 202 const char* const package_name_; 203 const char* const package_version_code_; 204 const char* const package_version_name_; 205 const char* const android_build_fp_; 206 // Can be overridden in tests. 207 const char* gms_version_code_ = nullptr; 208 const char* const installer_package_name_; 209 const char* const abi_name_; 210 const char* const custom_themes_; 211 const char* const resources_version_; 212 // Not needed by breakpad. 213 const int target_sdk_version_; 214 const bool is_debug_android_; 215 const bool is_tv_; 216 const char* const version_incremental_; 217 const char* const hardware_; 218 const bool is_at_least_t_; 219 const bool is_automotive_; 220 const bool is_at_least_u_; 221 const bool targets_at_least_u_; 222 const char* const codename_; 223 const int32_t vulkan_deqp_level_; 224 const bool is_foldable_; 225 const char* const soc_manufacturer_; 226 const bool is_debug_app_; 227 const bool is_desktop_; 228 }; 229 230 } // namespace base::android 231 232 #endif // BASE_ANDROID_BUILD_INFO_H_ 233