11 KiB
11 KiB
BuildInfo 新增功能使用示例
概述
BuildInfo类已新增了大量系统信息获取功能,包括Treble支持、无缝更新、Root检测、Google Play服务、系统工具、SSL版本、语言时区、USB调试、内核信息和设备标识符等。
新增功能列表
1. Treble 和系统更新
- ✅ Treble支持检测 -
isTrebleEnabled - ✅ Treble版本 -
trebleVersion - ✅ 无缝更新(A/B)支持 -
isSeamlessUpdateSupported - ✅ 当前活动插槽 -
currentSlot - ✅ 虚拟A/B支持 -
isVirtualABEnabled
2. Root 权限和安全
- ✅ Root状态检测 -
isRooted - ✅ SELinux状态 -
seLinuxStatus - ✅ dm-verity状态 -
isDmVerityEnabled
3. Google Play 服务
- ✅ Play服务版本名称 -
googlePlayServicesVersion - ✅ Play服务版本代码 -
googlePlayServicesVersionCode - ✅ Play商店版本 -
googlePlayStoreVersion - ✅ Google Services Framework版本 -
googleServicesFrameworkVersion
4. 系统工具版本
- ✅ Toybox版本 -
toyboxVersion - ✅ Toolbox版本 -
toolboxVersion - ✅ BusyBox版本 -
busyboxVersion
5. SSL/TLS 信息
- ✅ OpenSSL版本 -
openSslVersion - ✅ BoringSSL版本 -
boringSslVersion - ✅ TLS支持版本 -
tlsVersion
6. 语言和时区
- ✅ 系统语言 -
systemLanguage - ✅ 语言代码 -
languageCode - ✅ 国家/地区 -
country - ✅ 国家/地区代码 -
countryCode - ✅ 系统时区 -
timeZone - ✅ 时区显示名称 -
timeZoneDisplayName - ✅ UTC偏移 -
timeZoneOffset
7. 开发者选项和调试
- ✅ USB调试状态 -
isUsbDebuggingEnabled - ✅ 开发者选项状态 -
isDevelopmentSettingsEnabled - ✅ 未知来源安装 -
isUnknownSourcesEnabled
8. 内核信息
- ✅ 内核版本号 -
kernelVersion - ✅ 内核架构 -
kernelArchitecture - ✅ 内核名称 -
kernelName - ✅ 内核命令行参数 -
kernelCommandLine - ✅ CPU信息(/proc/cpuinfo) -
procCpuInfo - ✅ 内存信息(/proc/meminfo) -
procMemInfo
9. 设备标识符
- ✅ Android ID -
androidId - ✅ 序列号 -
serialNumber - ✅ 设备唯一ID -
deviceUniqueId
使用示例
初始化
import com.xyzshell.andinfo.AndInfo
// 在Application或Activity中初始化
AndInfo.init(applicationContext)
// 获取BuildInfo实例
val buildInfo = AndInfo.instance.build
1. Treble 和系统更新信息
// 检查Treble支持
val isTrebleSupported = buildInfo.isTrebleEnabled
println("Treble支持: ${if (isTrebleSupported) "是" else "否"}")
// Treble版本
buildInfo.trebleVersion?.let { version ->
println("Treble版本: $version")
}
// 检查无缝更新(A/B)支持
val isABUpdateSupported = buildInfo.isSeamlessUpdateSupported
println("无缝更新(A/B): ${if (isABUpdateSupported) "支持" else "不支持"}")
// 当前活动插槽
buildInfo.currentSlot?.let { slot ->
println("当前活动插槽: $slot")
}
// 虚拟A/B支持
val isVirtualAB = buildInfo.isVirtualABEnabled
println("虚拟A/B: ${if (isVirtualAB) "支持" else "不支持"}")
2. Root 权限和安全检测
// Root状态检测
val isRooted = buildInfo.isRooted
println("Root状态: ${if (isRooted) "已Root" else "未Root"}")
// SELinux状态
val seLinuxStatus = buildInfo.seLinuxStatus
println("SELinux状态: $seLinuxStatus")
// dm-verity状态
val isDmVerity = buildInfo.isDmVerityEnabled
println("dm-verity: ${if (isDmVerity) "启用" else "禁用"}")
3. Google Play 服务信息
// Google Play 服务版本
buildInfo.googlePlayServicesVersion?.let { version ->
println("Play服务版本: $version")
}
// Google Play 服务版本代码
buildInfo.googlePlayServicesVersionCode?.let { versionCode ->
println("Play服务版本代码: $versionCode")
}
// Google Play 商店版本
buildInfo.googlePlayStoreVersion?.let { version ->
println("Play商店版本: $version")
}
// Google Services Framework 版本
buildInfo.googleServicesFrameworkVersion?.let { version ->
println("GSF版本: $version")
}
4. 系统工具版本
// Toybox版本
buildInfo.toyboxVersion?.let { version ->
println("Toybox: $version")
}
// Toolbox版本
buildInfo.toolboxVersion?.let { version ->
println("Toolbox: $version")
}
// BusyBox版本(如果安装)
buildInfo.busyboxVersion?.let { version ->
println("BusyBox: $version")
}
5. SSL/TLS 信息
// OpenSSL版本
buildInfo.openSslVersion?.let { version ->
println("OpenSSL: $version")
}
// BoringSSL版本
buildInfo.boringSslVersion?.let { version ->
println("BoringSSL: $version")
}
// TLS支持版本
buildInfo.tlsVersion?.let { version ->
println("TLS支持: $version")
// 输出示例: "TLSv1, TLSv1.1, TLSv1.2, TLSv1.3"
}
6. 语言和时区信息
// 系统语言
val language = buildInfo.systemLanguage
val languageCode = buildInfo.languageCode
println("系统语言: $language ($languageCode)")
// 国家/地区
val country = buildInfo.country
val countryCode = buildInfo.countryCode
println("国家/地区: $country ($countryCode)")
// 时区信息
val timeZone = buildInfo.timeZone
val timeZoneDisplay = buildInfo.timeZoneDisplayName
val utcOffset = buildInfo.timeZoneOffset / 3600000 // 转换为小时
println("时区: $timeZone")
println("时区显示: $timeZoneDisplay")
println("UTC偏移: ${if (utcOffset >= 0) "+" else ""}${utcOffset}小时")
7. 开发者选项和调试
// USB调试状态
val isUsbDebugEnabled = buildInfo.isUsbDebuggingEnabled
println("USB调试: ${if (isUsbDebugEnabled) "启用" else "禁用"}")
// 开发者选项状态
val isDeveloperEnabled = buildInfo.isDevelopmentSettingsEnabled
println("开发者选项: ${if (isDeveloperEnabled) "启用" else "禁用"}")
// 未知来源安装
val isUnknownSourcesEnabled = buildInfo.isUnknownSourcesEnabled
println("未知来源: ${if (isUnknownSourcesEnabled) "允许" else "禁止"}")
8. 内核信息
// 内核基本信息
buildInfo.kernelName?.let { println("内核名称: $it") }
buildInfo.kernelVersion?.let { println("内核版本: $it") }
buildInfo.kernelArchitecture?.let { println("内核架构: $it") }
buildInfo.kernelCompleteVersion?.let { println("完整版本: $it") }
// 内核命令行参数
buildInfo.kernelCommandLine?.let { cmdline ->
println("内核命令行:")
println(cmdline)
}
// CPU信息(/proc/cpuinfo)
buildInfo.procCpuInfo?.let { cpuInfo ->
println("CPU信息:")
println(cpuInfo)
}
// 内存信息(/proc/meminfo)
buildInfo.procMemInfo?.let { memInfo ->
println("内存信息:")
println(memInfo)
}
9. 设备标识符
// Android ID
val androidId = buildInfo.androidId
println("Android ID: $androidId")
// 序列号
val serialNumber = buildInfo.serialNumber
println("序列号: $serialNumber")
// 设备唯一ID(基于多个参数生成)
val deviceUniqueId = buildInfo.deviceUniqueId
println("设备唯一ID: $deviceUniqueId")
10. 完整信息输出
// 使用text()方法获取格式化的完整信息
val fullInfo = buildInfo.text()
println(fullInfo)
示例输出
=== Treble 和系统更新 ===
Treble支持: 是
Treble版本: 1
无缝更新(A/B): 是
当前活动插槽: a
虚拟A/B: 否
=== Root 和安全 ===
Root状态: 未Root
SELinux状态: Enforcing
dm-verity: 启用
=== Google 服务 ===
Play服务版本: 23.45.12 (190400-582679489)
Play服务版本代码: 234512023
Play商店版本: 38.6.21-29 [0] [PR] 593153572
GSF版本: 13-9684448
=== 系统工具 ===
Toybox: 0.8.9-android13
Toolbox: 未找到
BusyBox: 未安装
=== SSL/TLS ===
OpenSSL: OpenSSL 1.1.1t 7 Feb 2023
BoringSSL: BoringCrypto
TLS支持: TLSv1, TLSv1.1, TLSv1.2, TLSv1.3
=== 语言和时区 ===
系统语言: 中文(简体) (zh)
国家/地区: 中国 (CN)
时区: Asia/Shanghai
时区显示: 中国标准时间
UTC偏移: +8小时
=== 开发者选项 ===
USB调试: 启用
开发者选项: 启用
未知来源: 允许
=== 内核信息 ===
内核名称: Linux
内核版本: 5.10.157
内核架构: aarch64
完整版本: 5.10.157-android13-4-00001-gf0123456789a-ab9876543
=== 设备标识符 ===
Android ID: 1234567890abcdef
序列号: ABC123456789
设备唯一ID: 123456789
注意事项
-
权限要求:
- 序列号 (
serialNumber) 在 Android 8.0+ 需要READ_PHONE_STATE权限 - 大部分其他功能不需要特殊权限
- 序列号 (
-
设备差异:
- 不同设备支持的功能可能不同
- 某些属性可能返回
null
-
安全和隐私:
- Android ID 和序列号属于设备标识符,使用时需要注意隐私保护
- Root检测方法可能无法检测到所有Root工具
-
系统版本:
- 某些功能仅在特定 Android 版本上可用
- Treble 功能需要 Android 8.0+
- 虚拟A/B 需要 Android 11+
-
Root检测:
isRooted检测常见的Root工具和文件- 高级隐藏Root的设备可能检测不到
-
Google服务:
- 如果设备未安装Google服务,相关属性将返回
null - 国内Android设备通常没有Google服务
- 如果设备未安装Google服务,相关属性将返回
典型应用场景
系统信息页面
class SystemInfoActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val buildInfo = AndInfo.instance.build
// 显示完整系统信息
val textView = findViewById<TextView>(R.id.systemInfo)
textView.text = buildInfo.text()
}
}
安全检查
fun checkDeviceSecurity(): SecurityReport {
val buildInfo = AndInfo.instance.build
return SecurityReport(
isRooted = buildInfo.isRooted,
seLinuxEnabled = buildInfo.seLinuxStatus == "Enforcing",
dmVerityEnabled = buildInfo.isDmVerityEnabled,
usbDebuggingEnabled = buildInfo.isUsbDebuggingEnabled
)
}
兼容性检查
fun checkSystemCompatibility(): Boolean {
val buildInfo = AndInfo.instance.build
// 检查是否支持必要的功能
val hasTreble = buildInfo.isTrebleEnabled
val hasABUpdate = buildInfo.isSeamlessUpdateSupported
val hasGoogleServices = buildInfo.googlePlayServicesVersion != null
return hasTreble && hasABUpdate && hasGoogleServices
}
完成度
✅ 100% - 所有请求的功能都已实现并添加详细注释
- Treble支持检测 ✅
- 无缝更新检测 ✅
- 活动插槽信息 ✅
- Root权限检测 ✅
- Google Play服务版本 ✅
- Toybox信息 ✅
- SSL版本信息 ✅
- 语言和时区 ✅
- USB调试状态 ✅
- 内核信息 ✅
- 设备标识符 ✅
- 详细中文注释 ✅