[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 | #include "base/android/build_info.h" |
| 6 | |
| 7 | #include <string> |
| 8 | |
| 9 | #include "base/android/jni_android.h" |
agrieve | 8e74adc | 2017-06-16 15:57:24 | [diff] [blame] | 10 | #include "base/android/jni_array.h" |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 11 | #include "base/android/scoped_java_ref.h" |
| 12 | #include "base/logging.h" |
| 13 | #include "base/memory/singleton.h" |
agrieve | 8e74adc | 2017-06-16 15:57:24 | [diff] [blame] | 14 | #include "base/strings/string_number_conversions.h" |
[email protected] | e46f6615 | 2012-07-19 20:02:55 | [diff] [blame] | 15 | #include "jni/BuildInfo_jni.h" |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 16 | |
agrieve | 91522d0 | 2017-04-24 15:44:29 | [diff] [blame] | 17 | namespace base { |
| 18 | namespace android { |
| 19 | |
agrieve | 8e74adc | 2017-06-16 15:57:24 | [diff] [blame] | 20 | namespace { |
| 21 | |
| 22 | // We are leaking these strings. |
| 23 | const char* StrDupParam(const std::vector<std::string>& params, int index) { |
| 24 | return strdup(params[index].c_str()); |
| 25 | } |
| 26 | |
Shimi Zhang | fa804f3 | 2018-04-19 23:16:14 | [diff] [blame] | 27 | int GetIntParam(const std::vector<std::string>& params, int index) { |
agrieve | 8e74adc | 2017-06-16 15:57:24 | [diff] [blame] | 28 | int ret = 0; |
| 29 | bool success = StringToInt(params[index], &ret); |
| 30 | DCHECK(success); |
| 31 | return ret; |
| 32 | } |
| 33 | |
| 34 | } // namespace |
| 35 | |
[email protected] | 57bf183 | 2012-06-20 16:42:39 | [diff] [blame] | 36 | struct BuildInfoSingletonTraits { |
| 37 | static BuildInfo* New() { |
agrieve | 8e74adc | 2017-06-16 15:57:24 | [diff] [blame] | 38 | JNIEnv* env = AttachCurrentThread(); |
| 39 | ScopedJavaLocalRef<jobjectArray> params_objs = Java_BuildInfo_getAll(env); |
| 40 | std::vector<std::string> params; |
Torne (Richard Coles) | 3c22e830 | 2018-10-12 18:34:22 | [diff] [blame] | 41 | AppendJavaStringArrayToStringVector(env, params_objs, ¶ms); |
agrieve | 8e74adc | 2017-06-16 15:57:24 | [diff] [blame] | 42 | return new BuildInfo(params); |
[email protected] | 57bf183 | 2012-06-20 16:42:39 | [diff] [blame] | 43 | } |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 44 | |
[email protected] | 57bf183 | 2012-06-20 16:42:39 | [diff] [blame] | 45 | static void Delete(BuildInfo* x) { |
| 46 | // We're leaking this type, see kRegisterAtExit. |
| 47 | NOTREACHED(); |
| 48 | } |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 49 | |
[email protected] | 57bf183 | 2012-06-20 16:42:39 | [diff] [blame] | 50 | static const bool kRegisterAtExit = false; |
gab | 190f754 | 2016-08-01 20:03:41 | [diff] [blame] | 51 | #if DCHECK_IS_ON() |
[email protected] | 57bf183 | 2012-06-20 16:42:39 | [diff] [blame] | 52 | static const bool kAllowedToAccessOnNonjoinableThread = true; |
[email protected] | 5a8a806 | 2014-03-06 01:11:54 | [diff] [blame] | 53 | #endif |
[email protected] | 57bf183 | 2012-06-20 16:42:39 | [diff] [blame] | 54 | }; |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 55 | |
agrieve | 8e74adc | 2017-06-16 15:57:24 | [diff] [blame] | 56 | BuildInfo::BuildInfo(const std::vector<std::string>& params) |
| 57 | : brand_(StrDupParam(params, 0)), |
| 58 | device_(StrDupParam(params, 1)), |
| 59 | android_build_id_(StrDupParam(params, 2)), |
| 60 | manufacturer_(StrDupParam(params, 3)), |
| 61 | model_(StrDupParam(params, 4)), |
Shimi Zhang | fa804f3 | 2018-04-19 23:16:14 | [diff] [blame] | 62 | sdk_int_(GetIntParam(params, 5)), |
agrieve | 8e74adc | 2017-06-16 15:57:24 | [diff] [blame] | 63 | build_type_(StrDupParam(params, 6)), |
Tobias Sargeant | 0d52ee1 | 2018-03-07 20:26:05 | [diff] [blame] | 64 | board_(StrDupParam(params, 7)), |
| 65 | host_package_name_(StrDupParam(params, 8)), |
| 66 | host_version_code_(StrDupParam(params, 9)), |
| 67 | host_package_label_(StrDupParam(params, 10)), |
| 68 | package_name_(StrDupParam(params, 11)), |
| 69 | package_version_code_(StrDupParam(params, 12)), |
| 70 | package_version_name_(StrDupParam(params, 13)), |
| 71 | android_build_fp_(StrDupParam(params, 14)), |
| 72 | gms_version_code_(StrDupParam(params, 15)), |
| 73 | installer_package_name_(StrDupParam(params, 16)), |
| 74 | abi_name_(StrDupParam(params, 17)), |
| 75 | firebase_app_id_(StrDupParam(params, 18)), |
Eric Stevenson | c5266e4 | 2018-04-04 19:30:58 | [diff] [blame] | 76 | custom_themes_(StrDupParam(params, 19)), |
| 77 | resources_version_(StrDupParam(params, 20)), |
Shimi Zhang | 7259fe14 | 2018-10-23 19:31:33 | [diff] [blame] | 78 | extracted_file_suffix_(params[21]) {} |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 79 | |
| 80 | // static |
| 81 | BuildInfo* BuildInfo::GetInstance() { |
[email protected] | 57bf183 | 2012-06-20 16:42:39 | [diff] [blame] | 82 | return Singleton<BuildInfo, BuildInfoSingletonTraits >::get(); |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 83 | } |
| 84 | |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 85 | } // namespace android |
| 86 | } // namespace base |