1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/android/android_info.h"
#include <cstring>
#include <mutex>
#include <string>
#include <variant>
#include "base/android/jni_android.h"
#include "base/android/jni_array.h"
#include "base/android/jni_string.h"
#include "base/android/scoped_java_ref.h"
#include "base/check.h"
#include "base/compiler_specific.h"
#include "base/no_destructor.h"
#include "base/strings/string_number_conversions.h"
// Must come after all headers that specialize FromJniType() / ToJniType().
#include "base/android_info_jni/AndroidInfo_jni.h"
#if __ANDROID_API__ >= 29
// .aidl based NDK generation is only available when our min SDK level is 29 or
// higher.
#include "aidl/org/chromium/base/IAndroidInfo.h"
using aidl::org::chromium::base::IAndroidInfo;
#endif
namespace base::android::android_info {
namespace {
#if __ANDROID_API__ < 29
struct IAndroidInfo {
const std::string abiName;
const std::string androidBuildFp;
const std::string androidBuildId;
const std::string board;
const std::string brand;
const std::string buildType;
const std::string codename;
const std::string device;
const std::string hardware;
bool isDebugAndroid;
const std::string manufacturer;
const std::string model;
int sdkInt;
const std::string securityPatch;
// Available only on android S+. For S-, this method returns empty string.
const std::string socManufacturer;
const std::string versionIncremental;
};
#endif
static std::optional<IAndroidInfo>& get_holder() {
static base::NoDestructor<std::optional<IAndroidInfo>> holder;
return *holder;
}
const IAndroidInfo& get_android_info() {
const std::optional<IAndroidInfo>& holder = get_holder();
if (!holder.has_value()) {
Java_AndroidInfo_nativeReadyForFields(AttachCurrentThread());
}
return *holder;
}
} // namespace
static void JNI_AndroidInfo_FillFields(JNIEnv* env,
std::string& brand,
std::string& device,
std::string& buildId,
std::string& manufacturer,
std::string& model,
std::string& type,
std::string& board,
std::string& androidBuildFingerprint,
std::string& versionIncremental,
std::string& hardware,
std::string& codename,
std::string& socManufacturer,
std::string& supportedAbis,
jint sdkInt,
jboolean isDebugAndroid,
std::string& securityPatch) {
std::optional<IAndroidInfo>& holder = get_holder();
DCHECK(!holder.has_value());
holder.emplace(
IAndroidInfo{.abiName = supportedAbis,
.androidBuildFp = androidBuildFingerprint,
.androidBuildId = buildId,
.board = board,
.brand = brand,
.buildType = type,
.codename = codename,
.device = device,
.hardware = hardware,
.isDebugAndroid = static_cast<bool>(isDebugAndroid),
.manufacturer = manufacturer,
.model = model,
.sdkInt = sdkInt,
.securityPatch = securityPatch,
.socManufacturer = socManufacturer,
.versionIncremental = versionIncremental});
}
const std::string& device() {
return get_android_info().device;
}
const std::string& manufacturer() {
return get_android_info().manufacturer;
}
const std::string& model() {
return get_android_info().model;
}
const std::string& brand() {
return get_android_info().brand;
}
const std::string& android_build_id() {
return get_android_info().androidBuildId;
}
const std::string& build_type() {
return get_android_info().buildType;
}
const std::string& board() {
return get_android_info().board;
}
const std::string& android_build_fp() {
return get_android_info().androidBuildFp;
}
int sdk_int() {
return get_android_info().sdkInt;
}
bool is_debug_android() {
return get_android_info().isDebugAndroid;
}
const std::string& version_incremental() {
return get_android_info().versionIncremental;
}
const std::string& hardware() {
return get_android_info().hardware;
}
const std::string& codename() {
return get_android_info().codename;
}
// Available only on android S+. For S-, this method returns empty string.
const std::string& soc_manufacturer() {
return get_android_info().socManufacturer;
}
const std::string& abi_name() {
return get_android_info().abiName;
}
const std::string& security_patch() {
return get_android_info().securityPatch;
}
} // namespace base::android::android_info
|