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 { 17 namespace android { 18 19 // This enumeration maps to the values returned by BuildInfo::sdk_int(), 20 // indicating the Android release associated with a given SDK version. 21 enum SdkVersion { 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, 34 SDK_VERSION_P = 28, 35 SDK_VERSION_Q = 29, 36 SDK_VERSION_R = 30, 37 SDK_VERSION_S = 31, 38 SDK_VERSION_Sv2 = 32, 39 SDK_VERSION_T = 33, 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 host_package_name()90 const char* host_package_name() const { return host_package_name_; } 91 host_version_code()92 const char* host_version_code() const { return host_version_code_; } 93 host_package_label()94 const char* host_package_label() const { return host_package_label_; } 95 package_version_code()96 const char* package_version_code() const { 97 return package_version_code_; 98 } 99 package_version_name()100 const char* package_version_name() const { 101 return package_version_name_; 102 } 103 package_name()104 const char* package_name() const { 105 return package_name_; 106 } 107 108 // Will be empty string if no app id is assigned. firebase_app_id()109 const char* firebase_app_id() const { return firebase_app_id_; } 110 custom_themes()111 const char* custom_themes() const { return custom_themes_; } 112 resources_version()113 const char* resources_version() const { return resources_version_; } 114 build_type()115 const char* build_type() const { 116 return build_type_; 117 } 118 board()119 const char* board() const { return board_; } 120 installer_package_name()121 const char* installer_package_name() const { return installer_package_name_; } 122 abi_name()123 const char* abi_name() const { return abi_name_; } 124 sdk_int()125 int sdk_int() const { 126 return sdk_int_; 127 } 128 129 // Returns the targetSdkVersion of the currently running app. If called from a 130 // library, this returns the embedding app's targetSdkVersion. 131 // 132 // This can only be compared to finalized SDK versions, never against 133 // pre-release Android versions. For pre-release Android versions, see the 134 // targetsAtLeast*() methods in BuildInfo.java. target_sdk_version()135 int target_sdk_version() const { return target_sdk_version_; } 136 is_debug_android()137 bool is_debug_android() const { return is_debug_android_; } 138 is_tv()139 bool is_tv() const { return is_tv_; } 140 version_incremental()141 const char* version_incremental() const { return version_incremental_; } 142 hardware()143 const char* hardware() const { return hardware_; } 144 is_at_least_t()145 bool is_at_least_t() const { return is_at_least_t_; } 146 is_automotive()147 bool is_automotive() const { return is_automotive_; } 148 is_at_least_u()149 bool is_at_least_u() const { return is_at_least_u_; } 150 targets_at_least_u()151 bool targets_at_least_u() const { return targets_at_least_u_; } 152 codename()153 const char* codename() const { return codename_; } 154 155 private: 156 friend struct BuildInfoSingletonTraits; 157 158 explicit BuildInfo(const std::vector<std::string>& params); 159 160 // Const char* is used instead of std::strings because these values must be 161 // available even if the process is in a crash state. Sadly 162 // std::string.c_str() doesn't guarantee that memory won't be allocated when 163 // it is called. 164 const char* const brand_; 165 const char* const device_; 166 const char* const android_build_id_; 167 const char* const manufacturer_; 168 const char* const model_; 169 const int sdk_int_; 170 const char* const build_type_; 171 const char* const board_; 172 const char* const host_package_name_; 173 const char* const host_version_code_; 174 const char* const host_package_label_; 175 const char* const package_name_; 176 const char* const package_version_code_; 177 const char* const package_version_name_; 178 const char* const android_build_fp_; 179 const char* const gms_version_code_; 180 const char* const installer_package_name_; 181 const char* const abi_name_; 182 const char* const firebase_app_id_; 183 const char* const custom_themes_; 184 const char* const resources_version_; 185 // Not needed by breakpad. 186 const int target_sdk_version_; 187 const bool is_debug_android_; 188 const bool is_tv_; 189 const char* const version_incremental_; 190 const char* const hardware_; 191 const bool is_at_least_t_; 192 const bool is_automotive_; 193 const bool is_at_least_u_; 194 const bool targets_at_least_u_; 195 const char* const codename_; 196 }; 197 198 } // namespace android 199 } // namespace base 200 201 #endif // BASE_ANDROID_BUILD_INFO_H_ 202