blob: 3b7c2b89de7db036004fab30ec382f60da3530d4 [file] [log] [blame]
[email protected]6653c192012-04-10 22:52:441// 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"
agrieve8e74adc2017-06-16 15:57:2410#include "base/android/jni_array.h"
[email protected]6653c192012-04-10 22:52:4411#include "base/android/scoped_java_ref.h"
12#include "base/logging.h"
13#include "base/memory/singleton.h"
agrieve8e74adc2017-06-16 15:57:2414#include "base/strings/string_number_conversions.h"
[email protected]e46f66152012-07-19 20:02:5515#include "jni/BuildInfo_jni.h"
[email protected]6653c192012-04-10 22:52:4416
agrieve91522d02017-04-24 15:44:2917namespace base {
18namespace android {
19
agrieve8e74adc2017-06-16 15:57:2420namespace {
21
22// We are leaking these strings.
23const char* StrDupParam(const std::vector<std::string>& params, int index) {
24 return strdup(params[index].c_str());
25}
26
Shimi Zhangfa804f32018-04-19 23:16:1427int GetIntParam(const std::vector<std::string>& params, int index) {
agrieve8e74adc2017-06-16 15:57:2428 int ret = 0;
29 bool success = StringToInt(params[index], &ret);
30 DCHECK(success);
31 return ret;
32}
33
34} // namespace
35
[email protected]57bf1832012-06-20 16:42:3936struct BuildInfoSingletonTraits {
37 static BuildInfo* New() {
agrieve8e74adc2017-06-16 15:57:2438 JNIEnv* env = AttachCurrentThread();
39 ScopedJavaLocalRef<jobjectArray> params_objs = Java_BuildInfo_getAll(env);
40 std::vector<std::string> params;
Torne (Richard Coles)3c22e8302018-10-12 18:34:2241 AppendJavaStringArrayToStringVector(env, params_objs, &params);
agrieve8e74adc2017-06-16 15:57:2442 return new BuildInfo(params);
[email protected]57bf1832012-06-20 16:42:3943 }
[email protected]6653c192012-04-10 22:52:4444
[email protected]57bf1832012-06-20 16:42:3945 static void Delete(BuildInfo* x) {
46 // We're leaking this type, see kRegisterAtExit.
47 NOTREACHED();
48 }
[email protected]6653c192012-04-10 22:52:4449
[email protected]57bf1832012-06-20 16:42:3950 static const bool kRegisterAtExit = false;
gab190f7542016-08-01 20:03:4151#if DCHECK_IS_ON()
[email protected]57bf1832012-06-20 16:42:3952 static const bool kAllowedToAccessOnNonjoinableThread = true;
[email protected]5a8a8062014-03-06 01:11:5453#endif
[email protected]57bf1832012-06-20 16:42:3954};
[email protected]6653c192012-04-10 22:52:4455
agrieve8e74adc2017-06-16 15:57:2456BuildInfo::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 Zhangfa804f32018-04-19 23:16:1462 sdk_int_(GetIntParam(params, 5)),
agrieve8e74adc2017-06-16 15:57:2463 build_type_(StrDupParam(params, 6)),
Tobias Sargeant0d52ee12018-03-07 20:26:0564 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 Stevensonc5266e42018-04-04 19:30:5876 custom_themes_(StrDupParam(params, 19)),
77 resources_version_(StrDupParam(params, 20)),
Shimi Zhang7259fe142018-10-23 19:31:3378 extracted_file_suffix_(params[21]) {}
[email protected]6653c192012-04-10 22:52:4479
80// static
81BuildInfo* BuildInfo::GetInstance() {
[email protected]57bf1832012-06-20 16:42:3982 return Singleton<BuildInfo, BuildInfoSingletonTraits >::get();
[email protected]6653c192012-04-10 22:52:4483}
84
[email protected]6653c192012-04-10 22:52:4485} // namespace android
86} // namespace base