build_info.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. #ifndef BASE_ANDROID_BUILD_INFO_H_
  5. #define BASE_ANDROID_BUILD_INFO_H_
  6. #include <jni.h>
  7. #include <string>
  8. #include <vector>
  9. #include "base/base_export.h"
  10. #include "base/memory/singleton.h"
  11. namespace base {
  12. namespace android {
  13. // This enumeration maps to the values returned by BuildInfo::sdk_int(),
  14. // indicating the Android release associated with a given SDK version.
  15. enum SdkVersion {
  16. SDK_VERSION_JELLY_BEAN = 16,
  17. SDK_VERSION_JELLY_BEAN_MR1 = 17,
  18. SDK_VERSION_JELLY_BEAN_MR2 = 18,
  19. SDK_VERSION_KITKAT = 19,
  20. SDK_VERSION_KITKAT_WEAR = 20,
  21. SDK_VERSION_LOLLIPOP = 21,
  22. SDK_VERSION_LOLLIPOP_MR1 = 22,
  23. SDK_VERSION_MARSHMALLOW = 23,
  24. SDK_VERSION_NOUGAT = 24,
  25. SDK_VERSION_NOUGAT_MR1 = 25,
  26. SDK_VERSION_OREO = 26,
  27. SDK_VERSION_O_MR1 = 27,
  28. SDK_VERSION_P = 28,
  29. SDK_VERSION_Q = 29,
  30. SDK_VERSION_R = 30,
  31. SDK_VERSION_S = 31,
  32. };
  33. // BuildInfo is a singleton class that stores android build and device
  34. // information. It will be called from Android specific code and gets used
  35. // primarily in crash reporting.
  36. class BASE_EXPORT BuildInfo {
  37. public:
  38. BuildInfo(const BuildInfo&) = delete;
  39. BuildInfo& operator=(const BuildInfo&) = delete;
  40. ~BuildInfo() {}
  41. // Static factory method for getting the singleton BuildInfo instance.
  42. // Note that ownership is not conferred on the caller and the BuildInfo in
  43. // question isn't actually freed until shutdown. This is ok because there
  44. // should only be one instance of BuildInfo ever created.
  45. static BuildInfo* GetInstance();
  46. // Const char* is used instead of std::strings because these values must be
  47. // available even if the process is in a crash state. Sadly
  48. // std::string.c_str() doesn't guarantee that memory won't be allocated when
  49. // it is called.
  50. const char* device() const {
  51. return device_;
  52. }
  53. const char* manufacturer() const {
  54. return manufacturer_;
  55. }
  56. const char* model() const {
  57. return model_;
  58. }
  59. const char* brand() const {
  60. return brand_;
  61. }
  62. const char* android_build_id() const {
  63. return android_build_id_;
  64. }
  65. const char* android_build_fp() const {
  66. return android_build_fp_;
  67. }
  68. const char* gms_version_code() const {
  69. return gms_version_code_;
  70. }
  71. const char* host_package_name() const { return host_package_name_; }
  72. const char* host_version_code() const { return host_version_code_; }
  73. const char* host_package_label() const { return host_package_label_; }
  74. const char* package_version_code() const {
  75. return package_version_code_;
  76. }
  77. const char* package_version_name() const {
  78. return package_version_name_;
  79. }
  80. const char* package_name() const {
  81. return package_name_;
  82. }
  83. // Will be empty string if no app id is assigned.
  84. const char* firebase_app_id() const { return firebase_app_id_; }
  85. const char* custom_themes() const { return custom_themes_; }
  86. const char* resources_version() const { return resources_version_; }
  87. const char* build_type() const {
  88. return build_type_;
  89. }
  90. const char* board() const { return board_; }
  91. const char* installer_package_name() const { return installer_package_name_; }
  92. const char* abi_name() const { return abi_name_; }
  93. int sdk_int() const {
  94. return sdk_int_;
  95. }
  96. // Returns the targetSdkVersion of the currently running app. If called from a
  97. // library, this returns the embedding app's targetSdkVersion.
  98. //
  99. // This can only be compared to finalized SDK versions, never against
  100. // pre-release Android versions. For pre-release Android versions, see the
  101. // targetsAtLeast*() methods in BuildInfo.java.
  102. int target_sdk_version() const { return target_sdk_version_; }
  103. bool is_debug_android() const { return is_debug_android_; }
  104. bool is_tv() const { return is_tv_; }
  105. const char* version_incremental() const { return version_incremental_; }
  106. const char* hardware() const { return hardware_; }
  107. bool is_at_least_t() const { return is_at_least_t_; }
  108. bool is_automotive() const { return is_automotive_; }
  109. private:
  110. friend struct BuildInfoSingletonTraits;
  111. explicit BuildInfo(const std::vector<std::string>& params);
  112. // Const char* is used instead of std::strings because these values must be
  113. // available even if the process is in a crash state. Sadly
  114. // std::string.c_str() doesn't guarantee that memory won't be allocated when
  115. // it is called.
  116. const char* const brand_;
  117. const char* const device_;
  118. const char* const android_build_id_;
  119. const char* const manufacturer_;
  120. const char* const model_;
  121. const int sdk_int_;
  122. const char* const build_type_;
  123. const char* const board_;
  124. const char* const host_package_name_;
  125. const char* const host_version_code_;
  126. const char* const host_package_label_;
  127. const char* const package_name_;
  128. const char* const package_version_code_;
  129. const char* const package_version_name_;
  130. const char* const android_build_fp_;
  131. const char* const gms_version_code_;
  132. const char* const installer_package_name_;
  133. const char* const abi_name_;
  134. const char* const firebase_app_id_;
  135. const char* const custom_themes_;
  136. const char* const resources_version_;
  137. // Not needed by breakpad.
  138. const int target_sdk_version_;
  139. const bool is_debug_android_;
  140. const bool is_tv_;
  141. const char* const version_incremental_;
  142. const char* const hardware_;
  143. const bool is_at_least_t_;
  144. const bool is_automotive_;
  145. };
  146. } // namespace android
  147. } // namespace base
  148. #endif // BASE_ANDROID_BUILD_INFO_H_