DevCheck-lib/DRMInfo使用示例.md
2025-12-23 18:32:08 +08:00

236 lines
7.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# DRMInfo 使用示例
## 概述
DRMInfo类提供了获取设备支持的DRM数字版权管理方案的详细信息包括Widevine、PlayReady等。
## 主要功能
1. 获取所有支持的DRM方案列表
2. 获取指定DRM方案的详细信息类型、供应商、版本、算法、设备ID、安全级别、最高HDCP级别等
3. 获取所有DRM方案的详细信息
## 使用方法
### 1. 初始化AndInfo
```kotlin
import com.xyzshell.andinfo.AndInfo
// 在Application或Activity中初始化
AndInfo.init(applicationContext)
```
### 2. 获取DRMInfo实例
```kotlin
val drmInfo = AndInfo.instance.drm
```
### 3. 获取所有支持的DRM方案
```kotlin
// 获取所有支持的DRM UUID列表
val supportedDrmSchemes = drmInfo.getSupportedDrmSchemes()
supportedDrmSchemes.forEach { uuid ->
println("支持的DRM方案: $uuid")
}
```
### 4. 获取指定DRM方案的详细信息
```kotlin
import com.xyzshell.andinfo.libs.DRMInfo
// 获取Widevine DRM详细信息
val widevineDrmDetail = drmInfo.getDrmDetail(DRMInfo.WIDEVINE_UUID)
widevineDrmDetail?.let { detail ->
println("DRM名称: ${detail.name}")
println("UUID: ${detail.uuid}")
println("供应商: ${detail.vendor}")
println("版本: ${detail.version}")
println("描述: ${detail.description}")
println("支持的算法: ${detail.algorithms?.joinToString(", ")}")
println("设备唯一ID: ${detail.deviceUniqueId}")
println("安全级别: ${detail.securityLevel}") // L1, L3等
println("系统ID: ${detail.systemId}")
println("当前打开的会话数: ${detail.openSessionCount}")
println("最大会话数: ${detail.maxSessionCount}")
println("当前连接的HDCP级别: ${detail.connectedHdcpLevel}")
println("最高支持的HDCP级别: ${detail.maxHdcpLevel}")
// 获取HDCP级别描述
detail.maxHdcpLevel?.let { level ->
val hdcpDescription = drmInfo.getHdcpLevelDescription(level)
println("最高HDCP级别描述: $hdcpDescription")
}
}
```
### 5. 获取所有DRM方案的详细信息
```kotlin
val allDrmDetails = drmInfo.getAllDrmDetails()
allDrmDetails.forEach { detail ->
println("=== ${detail.name} ===")
println("UUID: ${detail.uuid}")
println("供应商: ${detail.vendor}")
println("版本: ${detail.version}")
println("安全级别: ${detail.securityLevel}")
println("最高HDCP级别: ${detail.maxHdcpLevel?.let { drmInfo.getHdcpLevelDescription(it) }}")
println()
}
```
### 6. 在Android UI中显示DRM信息
```kotlin
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.xyzshell.andinfo.AndInfo
import com.xyzshell.andinfo.libs.DRMInfo
class DRMInfoActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// 获取DRMInfo实例
val drmInfo = AndInfo.instance.drm
// 获取所有支持的DRM方案
val allDrmDetails = drmInfo.getAllDrmDetails()
// 显示每个DRM方案的信息
allDrmDetails.forEach { detail ->
displayDrmInfo(detail)
}
}
private fun displayDrmInfo(detail: DRMInfo.DRMDetail) {
// 在UI中显示DRM信息
val info = buildString {
appendLine("DRM名称: ${detail.name}")
appendLine("UUID: ${detail.uuid}")
appendLine("供应商: ${detail.vendor ?: "未知"}")
appendLine("版本: ${detail.version ?: "未知"}")
appendLine("描述: ${detail.description ?: "无"}")
appendLine("支持的算法: ${detail.algorithms?.joinToString(", ") ?: "无"}")
appendLine("设备唯一ID: ${detail.deviceUniqueId ?: "不可用"}")
appendLine("安全级别: ${detail.securityLevel ?: "未知"}")
appendLine("系统ID: ${detail.systemId ?: "未知"}")
detail.openSessionCount?.let {
appendLine("当前打开的会话数: $it")
}
detail.maxSessionCount?.let {
appendLine("最大会话数: $it")
}
detail.connectedHdcpLevel?.let {
appendLine("当前HDCP级别: ${AndInfo.instance.drm.getHdcpLevelDescription(it)}")
}
detail.maxHdcpLevel?.let {
appendLine("最高HDCP级别: ${AndInfo.instance.drm.getHdcpLevelDescription(it)}")
}
}
println(info)
}
}
```
## DRMDetail 数据类说明
```kotlin
data class DRMDetail(
val uuid: String, // DRM方案的UUID
val name: String, // DRM方案名称如"Widevine Content Protection"
val vendor: String?, // 供应商(如"Google"
val version: String?, // 版本号
val description: String?, // 描述信息
val algorithms: List<String>?, // 支持的加密算法列表(如["AES/CBC/NoPadding"]
val deviceUniqueId: String?, // 设备唯一ID十六进制字符串
val securityLevel: String?, // 安全级别(如"L1"、"L3"
val systemId: String?, // 系统ID
val openSessionCount: Int?, // 当前打开的会话数Android 9及以上
val maxSessionCount: Int?, // 最大会话数Android 9及以上
val connectedHdcpLevel: Int?, // 当前连接的HDCP级别Android 9及以上
val maxHdcpLevel: Int?, // 最高支持的HDCP级别Android 9及以上
)
```
## HDCP级别说明
HDCP (High-bandwidth Digital Content Protection) 高带宽数字内容保护
| 级别 | 名称 | 说明 |
|-----|------|------|
| 0 | HDCP_NONE | 无HDCP保护 |
| 1 | HDCP_V1 | HDCP 1.x |
| 2 | HDCP_V2 | HDCP 2.0 |
| 3 | HDCP_V2_1 | HDCP 2.1 |
| 4 | HDCP_V2_2 | HDCP 2.2 |
| 5 | HDCP_V2_3 | HDCP 2.3 |
| 255 | HDCP_NO_DIGITAL_OUTPUT | 无数字输出 |
## 常用DRM方案UUID
```kotlin
// Widevine DRM (Google)
DRMInfo.WIDEVINE_UUID = "edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"
// Microsoft PlayReady
DRMInfo.PLAYREADY_UUID = "9a04f079-9840-4286-ab92-e65be0885f95"
// ClearKey DASH-IF
DRMInfo.CLEARKEY_UUID = "e2719d58-a985-b3c9-781a-b030af78d30e"
```
## 支持的DRM方案
DRMInfo支持以下29种DRM方案的识别
1. ABV DRM (MoDRM)
2. Adobe Primetime DRM v4
3. Alticast
4. Apple FairPlay
5. Arris Titanium
6. ChinaDRM
7. ClearKey (多种变体)
8. CMLA (OMA DRM)
9. Commscope Titanium V3
10. CoreCrypt
11. DigiCAP SmartXess
12. DivX DRM Series 5
13. Irdeto Content Protection
14. Marlin Adaptive Streaming
15. Microsoft PlayReady
16. MobiTV DRM
17. Nagra MediaAccess PRM 3.0
18. SecureMedia
19. Synamedia/Cisco/NDS VideoGuard DRM
20. Unitend DRM (UDRM)
21. Verimatrix VCAS
22. Viaccess-Orca DRM (VODRM)
23. VisionCrypt
24. W3C Common PSSH box
25. Widevine Content Protection
## 注意事项
1. 不同设备支持的DRM方案可能不同
2. 某些DRM信息可能需要特定权限才能访问
3. Android 9 (API 28) 以下版本不支持会话数和HDCP级别信息
4. 设备唯一ID可能在某些设备上不可用
5. Widevine安全级别:
- L1: 最高安全级别,支持硬件级别的内容保护
- L3: 软件级别的内容保护
## 示例输出
```
=== Widevine Content Protection ===
UUID: edef8ba9-79d6-4ace-a3c8-27dcd51d21ed
供应商: Google
版本: 16.1.0
安全级别: L1
最高HDCP级别: HDCP_V2_2 (2.2)
支持的算法: AES/CBC/NoPadding
设备唯一ID: a1b2c3d4e5f6...
```