| 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/macros.h" |
| 15 | #include "base/memory/singleton.h" |
| 16 |
| 17 | namespace base { |
| 18 | namespace android { |
| 19 |
| 20 | // This enumeration maps to the values returned by BuildInfo::sdk_int(), |
| 21 | // indicating the Android release associated with a given SDK version. |
| 22 | enum SdkVersion { |
| 23 | SDK_VERSION_JELLY_BEAN = 16, |
| 24 | SDK_VERSION_JELLY_BEAN_MR1 = 17, |
| 25 | SDK_VERSION_JELLY_BEAN_MR2 = 18, |
| 26 | SDK_VERSION_KITKAT = 19, |
| 27 | SDK_VERSION_KITKAT_WEAR = 20, |
| 28 | SDK_VERSION_LOLLIPOP = 21, |
| 29 | SDK_VERSION_LOLLIPOP_MR1 = 22, |
| 30 | SDK_VERSION_MARSHMALLOW = 23, |
| 31 | SDK_VERSION_NOUGAT = 24, |
| 32 | SDK_VERSION_NOUGAT_MR1 = 25, |
| 33 | SDK_VERSION_OREO = 26, |
| 34 | SDK_VERSION_O_MR1 = 27, |
| 35 | SDK_VERSION_P = 28, |
| 36 | }; |
| 37 |
| 38 | // BuildInfo is a singleton class that stores android build and device |
| 39 | // information. It will be called from Android specific code and gets used |
| 40 | // primarily in crash reporting. |
| 41 | class BASE_EXPORT BuildInfo { |
| 42 | public: |
| 43 |
| 44 | ~BuildInfo() {} |
| 45 |
| 46 | // Static factory method for getting the singleton BuildInfo instance. |
| 47 | // Note that ownership is not conferred on the caller and the BuildInfo in |
| 48 | // question isn't actually freed until shutdown. This is ok because there |
| 49 | // should only be one instance of BuildInfo ever created. |
| 50 | static BuildInfo* GetInstance(); |
| 51 |
| 52 | // Const char* is used instead of std::strings because these values must be |
| 53 | // available even if the process is in a crash state. Sadly |
| 54 | // std::string.c_str() doesn't guarantee that memory won't be allocated when |
| 55 | // it is called. |
| 56 | const char* device() const { |
| 57 | return device_; |
| 58 | } |
| 59 |
| 60 | const char* manufacturer() const { |
| 61 | return manufacturer_; |
| 62 | } |
| 63 |
| 64 | const char* model() const { |
| 65 | return model_; |
| 66 | } |
| 67 |
| 68 | const char* brand() const { |
| 69 | return brand_; |
| 70 | } |
| 71 |
| 72 | const char* android_build_id() const { |
| 73 | return android_build_id_; |
| 74 | } |
| 75 |
| 76 | const char* android_build_fp() const { |
| 77 | return android_build_fp_; |
| 78 | } |
| 79 |
| 80 | const char* gms_version_code() const { |
| 81 | return gms_version_code_; |
| 82 | } |
| 83 |
| 84 | const char* host_package_name() const { return host_package_name_; } |
| 85 |
| 86 | const char* host_version_code() const { return host_version_code_; } |
| 87 |
| 88 | const char* host_package_label() const { return host_package_label_; } |
| 89 |
| 90 | const char* package_version_code() const { |
| 91 | return package_version_code_; |
| 92 | } |
| 93 |
| 94 | const char* package_version_name() const { |
| 95 | return package_version_name_; |
| 96 | } |
| 97 |
| 98 | const char* package_name() const { |
| 99 | return package_name_; |
| 100 | } |
| 101 |
| 102 | // Will be empty string if no app id is assigned. |
| 103 | const char* firebase_app_id() const { return firebase_app_id_; } |
| 104 |
| 105 | const char* custom_themes() const { return custom_themes_; } |
| 106 |
| 107 | const char* resources_version() const { return resources_version_; } |
| 108 |
| 109 | const char* build_type() const { |
| 110 | return build_type_; |
| 111 | } |
| 112 |
| 113 | const char* board() const { return board_; } |
| 114 |
| 115 | const char* installer_package_name() const { return installer_package_name_; } |
| 116 |
| 117 | const char* abi_name() const { return abi_name_; } |
| 118 |
| 119 | std::string extracted_file_suffix() const { return extracted_file_suffix_; } |
| 120 |
| 121 | int sdk_int() const { |
| 122 | return sdk_int_; |
| 123 | } |
| 124 |
| 125 | bool is_at_least_q() const { return is_at_least_q_; } |
| 126 |
| 127 | bool targets_at_least_r() const { return targets_at_least_r_; } |
| 128 |
| 129 | bool is_debug_android() const { return is_debug_android_; } |
| 130 |
| 131 | private: |
| 132 | friend struct BuildInfoSingletonTraits; |
| 133 |
| 134 | explicit BuildInfo(const std::vector<std::string>& params); |
| 135 |
| 136 | // Const char* is used instead of std::strings because these values must be |
| 137 | // available even if the process is in a crash state. Sadly |
| 138 | // std::string.c_str() doesn't guarantee that memory won't be allocated when |
| 139 | // it is called. |
| 140 | const char* const brand_; |
| 141 | const char* const device_; |
| 142 | const char* const android_build_id_; |
| 143 | const char* const manufacturer_; |
| 144 | const char* const model_; |
| 145 | const int sdk_int_; |
| 146 | const char* const build_type_; |
| 147 | const char* const board_; |
| 148 | const char* const host_package_name_; |
| 149 | const char* const host_version_code_; |
| 150 | const char* const host_package_label_; |
| 151 | const char* const package_name_; |
| 152 | const char* const package_version_code_; |
| 153 | const char* const package_version_name_; |
| 154 | const char* const android_build_fp_; |
| 155 | const char* const gms_version_code_; |
| 156 | const char* const installer_package_name_; |
| 157 | const char* const abi_name_; |
| 158 | const char* const firebase_app_id_; |
| 159 | const char* const custom_themes_; |
| 160 | const char* const resources_version_; |
| 161 | // Not needed by breakpad. |
| 162 | const std::string extracted_file_suffix_; |
| 163 | const bool is_at_least_q_; |
| 164 | const bool targets_at_least_r_; |
| 165 | const bool is_debug_android_; |
| 166 |
| 167 | DISALLOW_COPY_AND_ASSIGN(BuildInfo); |
| 168 | }; |
| 169 |
| 170 | } // namespace android |
| 171 | } // namespace base |
| 172 |
| 173 | #endif // BASE_ANDROID_BUILD_INFO_H_ |
| 174 |