Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "base/android/build_info.h" |
| 6 | |
| 7 | #include <string> |
| 8 | |
Mohannad Farrag | 6351069 | 2025-02-10 17:12:57 | [diff] [blame] | 9 | #include "base/android/android_info.h" |
| 10 | #include "base/android/apk_info.h" |
| 11 | #include "base/android/device_info.h" |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 12 | #include "base/android/jni_android.h" |
agrieve | 8e74adc | 2017-06-16 15:57:24 | [diff] [blame] | 13 | #include "base/android/jni_array.h" |
Rupert Ben Wiser | dfea6925 | 2024-07-26 15:50:10 | [diff] [blame] | 14 | #include "base/android/jni_string.h" |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 15 | #include "base/android/scoped_java_ref.h" |
Hans Wennborg | c3cffa6 | 2020-04-27 10:09:12 | [diff] [blame] | 16 | #include "base/check_op.h" |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 17 | #include "base/memory/singleton.h" |
Hans Wennborg | c3cffa6 | 2020-04-27 10:09:12 | [diff] [blame] | 18 | #include "base/notreached.h" |
agrieve | 8e74adc | 2017-06-16 15:57:24 | [diff] [blame] | 19 | #include "base/strings/string_number_conversions.h" |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 20 | |
Andrew Grieve | ecb885bb | 2024-05-29 18:14:19 | [diff] [blame] | 21 | // Must come after all headers that specialize FromJniType() / ToJniType(). |
Mohannad Farrag | 6351069 | 2025-02-10 17:12:57 | [diff] [blame] | 22 | #include "base/build_info_jni/BuildInfo_jni.h" |
Andrew Grieve | ecb885bb | 2024-05-29 18:14:19 | [diff] [blame] | 23 | |
agrieve | 91522d0 | 2017-04-24 15:44:29 | [diff] [blame] | 24 | namespace base { |
| 25 | namespace android { |
| 26 | |
[email protected] | 57bf183 | 2012-06-20 16:42:39 | [diff] [blame] | 27 | struct BuildInfoSingletonTraits { |
Mohannad Farrag | 6351069 | 2025-02-10 17:12:57 | [diff] [blame] | 28 | static BuildInfo* New() { return new BuildInfo(); } |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 29 | |
[email protected] | 57bf183 | 2012-06-20 16:42:39 | [diff] [blame] | 30 | static void Delete(BuildInfo* x) { |
| 31 | // We're leaking this type, see kRegisterAtExit. |
Peter Boström | de57333 | 2024-08-26 20:42:45 | [diff] [blame] | 32 | NOTREACHED(); |
[email protected] | 57bf183 | 2012-06-20 16:42:39 | [diff] [blame] | 33 | } |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 34 | |
[email protected] | 57bf183 | 2012-06-20 16:42:39 | [diff] [blame] | 35 | static const bool kRegisterAtExit = false; |
gab | 190f754 | 2016-08-01 20:03:41 | [diff] [blame] | 36 | #if DCHECK_IS_ON() |
[email protected] | 57bf183 | 2012-06-20 16:42:39 | [diff] [blame] | 37 | static const bool kAllowedToAccessOnNonjoinableThread = true; |
[email protected] | 5a8a806 | 2014-03-06 01:11:54 | [diff] [blame] | 38 | #endif |
[email protected] | 57bf183 | 2012-06-20 16:42:39 | [diff] [blame] | 39 | }; |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 40 | |
Mohannad Farrag | 6351069 | 2025-02-10 17:12:57 | [diff] [blame] | 41 | BuildInfo::BuildInfo() |
| 42 | : brand_(android_info::brand()), |
| 43 | device_(android_info::device()), |
| 44 | android_build_id_(android_info::android_build_id()), |
| 45 | manufacturer_(android_info::manufacturer()), |
| 46 | model_(android_info::model()), |
| 47 | sdk_int_(android_info::sdk_int()), |
| 48 | build_type_(android_info::build_type()), |
| 49 | board_(android_info::board()), |
| 50 | host_package_name_(apk_info::host_package_name()), |
| 51 | host_version_code_(apk_info::host_version_code()), |
| 52 | host_package_label_(apk_info::host_package_label()), |
| 53 | package_name_(apk_info::package_name()), |
| 54 | package_version_code_(apk_info::package_version_code()), |
| 55 | package_version_name_(apk_info::package_version_name()), |
| 56 | android_build_fp_(android_info::android_build_fp()), |
| 57 | installer_package_name_(apk_info::installer_package_name()), |
| 58 | abi_name_(android_info::abi_name()), |
Mohannad Farrag | 6351069 | 2025-02-10 17:12:57 | [diff] [blame] | 59 | resources_version_(apk_info::resources_version()), |
| 60 | target_sdk_version_(apk_info::target_sdk_version()), |
| 61 | is_debug_android_(android_info::is_debug_android()), |
| 62 | is_tv_(device_info::is_tv()), |
| 63 | version_incremental_(android_info::version_incremental()), |
| 64 | hardware_(android_info::hardware()), |
Mohannad Farrag | 6351069 | 2025-02-10 17:12:57 | [diff] [blame] | 65 | is_automotive_(device_info::is_automotive()), |
Mohannad Farrag | 6351069 | 2025-02-10 17:12:57 | [diff] [blame] | 66 | codename_(android_info::codename()), |
| 67 | vulkan_deqp_level_(device_info::vulkan_deqp_level()), |
| 68 | is_foldable_(device_info::is_foldable()), |
| 69 | soc_manufacturer_(android_info::soc_manufacturer()), |
| 70 | is_debug_app_(apk_info::is_debug_app()), |
| 71 | is_desktop_(device_info::is_desktop()) {} |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 72 | |
Rupert Ben Wiser | dfea6925 | 2024-07-26 15:50:10 | [diff] [blame] | 73 | BuildInfo::~BuildInfo() = default; |
| 74 | |
Sam Maier | 05ccd44f | 2025-05-13 18:51:38 | [diff] [blame] | 75 | const std::string& BuildInfo::gms_version_code() const { |
Mohannad Farrag | 6351069 | 2025-02-10 17:12:57 | [diff] [blame] | 76 | return device_info::gms_version_code(); |
| 77 | } |
| 78 | |
Victor Hugo Vianna Silva | 3daaf8e | 2024-07-31 22:34:31 | [diff] [blame] | 79 | void BuildInfo::set_gms_version_code_for_test( |
| 80 | const std::string& gms_version_code) { |
Mohannad Farrag | 6351069 | 2025-02-10 17:12:57 | [diff] [blame] | 81 | device_info::set_gms_version_code_for_test(gms_version_code); |
Victor Hugo Vianna Silva | 3daaf8e | 2024-07-31 22:34:31 | [diff] [blame] | 82 | } |
| 83 | |
Sam Maier | 05ccd44f | 2025-05-13 18:51:38 | [diff] [blame] | 84 | const std::string BuildInfo::host_signing_cert_sha256() { |
Rupert Ben Wiser | dfea6925 | 2024-07-26 15:50:10 | [diff] [blame] | 85 | JNIEnv* env = AttachCurrentThread(); |
Glenn Hartmann | df50216 | 2024-12-17 20:13:22 | [diff] [blame] | 86 | return Java_BuildInfo_lazyGetHostSigningCertSha256(env); |
Rupert Ben Wiser | dfea6925 | 2024-07-26 15:50:10 | [diff] [blame] | 87 | } |
| 88 | |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 89 | // static |
| 90 | BuildInfo* BuildInfo::GetInstance() { |
Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 91 | return Singleton<BuildInfo, BuildInfoSingletonTraits>::get(); |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 92 | } |
| 93 | |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 94 | } // namespace android |
| 95 | } // namespace base |