build_info.h 4.8 KB

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