[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 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> |
agrieve | 8e74adc | 2017-06-16 15:57:24 | [diff] [blame] | 11 | #include <vector> |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 12 | |
[email protected] | 4f2b94f | 2013-02-22 21:06:37 | [diff] [blame] | 13 | #include "base/base_export.h" |
avi | b30f240 | 2015-12-24 03:43:28 | [diff] [blame] | 14 | #include "base/macros.h" |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 15 | #include "base/memory/singleton.h" |
| 16 | |
| 17 | namespace base { |
| 18 | namespace android { |
| 19 | |
peter | d948e02 | 2015-02-17 17:49:46 | [diff] [blame] | 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 { |
peter | d948e02 | 2015-02-17 17:49:46 | [diff] [blame] | 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, |
jdduke | 05bb97f | 2015-06-10 00:27:56 | [diff] [blame] | 28 | SDK_VERSION_LOLLIPOP = 21, |
andrewhayden | 752b1fb | 2015-08-27 21:05:57 | [diff] [blame] | 29 | SDK_VERSION_LOLLIPOP_MR1 = 22, |
tobiasjs | 2c944c9 | 2016-11-08 21:10:09 | [diff] [blame] | 30 | SDK_VERSION_MARSHMALLOW = 23, |
Simeon Anfinrud | d9644fc | 2017-06-02 17:26:55 | [diff] [blame] | 31 | SDK_VERSION_NOUGAT = 24, |
Klaus Weidner | 3824a888 | 2017-11-03 06:24:57 | [diff] [blame] | 32 | SDK_VERSION_NOUGAT_MR1 = 25, |
| 33 | SDK_VERSION_OREO = 26, |
peter | d948e02 | 2015-02-17 17:49:46 | [diff] [blame] | 34 | }; |
| 35 | |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 36 | // BuildInfo is a singleton class that stores android build and device |
[email protected] | 9be878f | 2012-09-18 01:51:27 | [diff] [blame] | 37 | // information. It will be called from Android specific code and gets used |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 38 | // primarily in crash reporting. |
[email protected] | 1b46a53 | 2012-05-23 05:59:49 | [diff] [blame] | 39 | |
| 40 | // It is also used to store the last java exception seen during JNI. |
| 41 | // TODO(nileshagrawal): Find a better place to store this info. |
[email protected] | 4f2b94f | 2013-02-22 21:06:37 | [diff] [blame] | 42 | class BASE_EXPORT BuildInfo { |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 43 | public: |
| 44 | |
| 45 | ~BuildInfo() {} |
| 46 | |
| 47 | // Static factory method for getting the singleton BuildInfo instance. |
| 48 | // Note that ownership is not conferred on the caller and the BuildInfo in |
| 49 | // question isn't actually freed until shutdown. This is ok because there |
| 50 | // should only be one instance of BuildInfo ever created. |
| 51 | static BuildInfo* GetInstance(); |
| 52 | |
| 53 | // Const char* is used instead of std::strings because these values must be |
| 54 | // available even if the process is in a crash state. Sadly |
| 55 | // std::string.c_str() doesn't guarantee that memory won't be allocated when |
| 56 | // it is called. |
| 57 | const char* device() const { |
| 58 | return device_; |
| 59 | } |
| 60 | |
gunsch | e2dcec5 | 2014-09-23 21:39:19 | [diff] [blame] | 61 | const char* manufacturer() const { |
| 62 | return manufacturer_; |
| 63 | } |
| 64 | |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 65 | const char* model() const { |
| 66 | return model_; |
| 67 | } |
| 68 | |
| 69 | const char* brand() const { |
| 70 | return brand_; |
| 71 | } |
| 72 | |
| 73 | const char* android_build_id() const { |
| 74 | return android_build_id_; |
| 75 | } |
| 76 | |
| 77 | const char* android_build_fp() const { |
| 78 | return android_build_fp_; |
| 79 | } |
| 80 | |
hzl | e36a130 | 2016-06-10 17:50:17 | [diff] [blame] | 81 | const char* gms_version_code() const { |
| 82 | return gms_version_code_; |
| 83 | } |
| 84 | |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 85 | const char* package_version_code() const { |
| 86 | return package_version_code_; |
| 87 | } |
| 88 | |
| 89 | const char* package_version_name() const { |
| 90 | return package_version_name_; |
| 91 | } |
| 92 | |
[email protected] | 9be878f | 2012-09-18 01:51:27 | [diff] [blame] | 93 | const char* package_label() const { |
| 94 | return package_label_; |
| 95 | } |
| 96 | |
[email protected] | 281288d | 2012-11-09 03:03:23 | [diff] [blame] | 97 | const char* package_name() const { |
| 98 | return package_name_; |
| 99 | } |
| 100 | |
[email protected] | a588c09 | 2014-02-13 23:26:54 | [diff] [blame] | 101 | const char* build_type() const { |
| 102 | return build_type_; |
| 103 | } |
| 104 | |
ranj | f2c67e4 | 2017-06-29 19:43:30 | [diff] [blame] | 105 | const char* installer_package_name() const { return installer_package_name_; } |
| 106 | |
| 107 | const char* abi_name() const { return abi_name_; } |
| 108 | |
agrieve | a9cdba4 | 2017-04-20 18:03:29 | [diff] [blame] | 109 | std::string extracted_file_suffix() const { return extracted_file_suffix_; } |
| 110 | |
[email protected] | 19728484 | 2012-11-20 03:39:01 | [diff] [blame] | 111 | int sdk_int() const { |
| 112 | return sdk_int_; |
| 113 | } |
| 114 | |
[email protected] | 1b46a53 | 2012-05-23 05:59:49 | [diff] [blame] | 115 | const char* java_exception_info() const { |
| 116 | return java_exception_info_; |
| 117 | } |
| 118 | |
cjhopman | 060e007 | 2015-05-06 21:37:48 | [diff] [blame] | 119 | void SetJavaExceptionInfo(const std::string& info); |
| 120 | |
| 121 | void ClearJavaExceptionInfo(); |
[email protected] | 1b46a53 | 2012-05-23 05:59:49 | [diff] [blame] | 122 | |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 123 | private: |
[email protected] | 57bf183 | 2012-06-20 16:42:39 | [diff] [blame] | 124 | friend struct BuildInfoSingletonTraits; |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 125 | |
agrieve | 8e74adc | 2017-06-16 15:57:24 | [diff] [blame] | 126 | explicit BuildInfo(const std::vector<std::string>& params); |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 127 | |
| 128 | // Const char* is used instead of std::strings because these values must be |
| 129 | // available even if the process is in a crash state. Sadly |
| 130 | // std::string.c_str() doesn't guarantee that memory won't be allocated when |
| 131 | // it is called. |
agrieve | 8e74adc | 2017-06-16 15:57:24 | [diff] [blame] | 132 | const char* const brand_; |
[email protected] | 57bf183 | 2012-06-20 16:42:39 | [diff] [blame] | 133 | const char* const device_; |
agrieve | 8e74adc | 2017-06-16 15:57:24 | [diff] [blame] | 134 | const char* const android_build_id_; |
gunsch | e2dcec5 | 2014-09-23 21:39:19 | [diff] [blame] | 135 | const char* const manufacturer_; |
[email protected] | 57bf183 | 2012-06-20 16:42:39 | [diff] [blame] | 136 | const char* const model_; |
agrieve | 8e74adc | 2017-06-16 15:57:24 | [diff] [blame] | 137 | const int sdk_int_; |
| 138 | const char* const build_type_; |
agrieve | 91522d0 | 2017-04-24 15:44:29 | [diff] [blame] | 139 | const char* const package_label_; |
| 140 | const char* const package_name_; |
agrieve | 8e74adc | 2017-06-16 15:57:24 | [diff] [blame] | 141 | const char* const package_version_code_; |
| 142 | const char* const package_version_name_; |
| 143 | const char* const android_build_fp_; |
| 144 | const char* const gms_version_code_; |
ranj | f2c67e4 | 2017-06-29 19:43:30 | [diff] [blame] | 145 | const char* const installer_package_name_; |
| 146 | const char* const abi_name_; |
agrieve | a9cdba4 | 2017-04-20 18:03:29 | [diff] [blame] | 147 | // Not needed by breakpad. |
| 148 | const std::string extracted_file_suffix_; |
[email protected] | 57bf183 | 2012-06-20 16:42:39 | [diff] [blame] | 149 | // This is set via set_java_exception_info, not at constructor time. |
| 150 | const char* java_exception_info_; |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 151 | |
| 152 | DISALLOW_COPY_AND_ASSIGN(BuildInfo); |
| 153 | }; |
| 154 | |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 155 | } // namespace android |
| 156 | } // namespace base |
| 157 | |
| 158 | #endif // BASE_ANDROID_BUILD_INFO_H_ |