Files
Obsidian/项目文档/徐工/三方对接授权文档.md
T
2026-11-05 14:35:04 +08:00

204 lines
15 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.
# 三方应用对接授权文档
一、概述
徐工车机项目的隐私授权系统通过 Android Settings.System 存储授权状态(0/1值),第三方应用通过读取这些
Key 的值来判断用户是否已授权,进而决定是否允许对应功能的访问。
二、读取授权状态
2.1 权限授权状态
全局开关和有效期
┌────────────────────────────────────────┬──────┬──────────────────────┐
│ Key │ 类型 │ 说明 │
├────────────────────────────────────────┼──────┼──────────────────────┤
│ xcmg_permission_global_switch │ int │ 0 = 关闭,1 = 开启 │
├────────────────────────────────────────┼──────┼──────────────────────┤
│ xcmg_permission_authorization_duration │ int │ 1 = 180天,2 = 360天 │
├────────────────────────────────────────┼──────┼──────────────────────┤
│ xcmg_permission_authorization_date │ long │ 授权开始时间戳(毫秒) │
└────────────────────────────────────────┴──────┴──────────────────────┘
具体权限Key及使用场景
┌────────────────────────────────────────────┬──────────────────────────────────────┐
│ Key │ 使用场景 │
├────────────────────────────────────────────┼──────────────────────────────────────┤
│ xcmg_permission_contacts_bluetooth_phone │ 联系人权限 - 蓝牙电话读取联系人 │
├────────────────────────────────────────────┼──────────────────────────────────────┤
│ xcmg_permission_microphone_voice_assistant │ 麦克风权限 - 语音助手录音 │
├────────────────────────────────────────────┼──────────────────────────────────────┤
│ xcmg_permission_microphone_bluetooth_phone │ 麦克风权限 - 蓝牙电话通话 │
├────────────────────────────────────────────┼──────────────────────────────────────┤
│ xcmg_permission_location_voice_assistant │ 位置权限 - 语音助手获取位置 │
├────────────────────────────────────────────┼──────────────────────────────────────┤
│ xcmg_permission_location_map │ 位置权限 - 地图/导航获取位置 │
├────────────────────────────────────────────┼──────────────────────────────────────┤
│ xcmg_permission_location_carlink │ 位置权限 - 亿连手机互联获取位置 │
├────────────────────────────────────────────┼──────────────────────────────────────┤
│ xcmg_permission_camera_dvr │ 摄像头权限 - 行车记录仪录像 │
└────────────────────────────────────────────┴──────────────────────────────────────┘
读取示例(Java):
// 读取某个具体权限状态
int locationMapPermission = Settings.System.getInt(
context.getContentResolver(), "xcmg_permission_location_map", 0);
// 1 = 已授权, 0 = 未授权
// 判断授权是否有效(完整判断逻辑)
boolean isAuthorized = false;
int globalSwitch = Settings.System.getInt(
context.getContentResolver(), "xcmg_permission_global_switch", 0);
if (globalSwitch == 1) {
long authDate = Settings.System.getLong(
context.getContentResolver(), "xcmg_permission_authorization_date", 0);
int duration = Settings.System.getInt(
context.getContentResolver(), "xcmg_permission_authorization_duration", 0);
int totalDays = (duration == 1) ? 180 : 360;
long daysPassed = (System.currentTimeMillis() - authDate) / (1000 * 60 * 60 * 24);
if (daysPassed < totalDays) {
// 有效期未过,读取具体权限
int permission = Settings.System.getInt(
context.getContentResolver(), "xcmg_permission_location_map", 0);
isAuthorized = (permission == 1);
}
}
三、判断逻辑
流程图:
┌─────────────┐ 否 ┌──────────┐
│ 隐私已授权? ├────────────►│ 未授权 │
└──────┬──────┘ └──────────┘
│是
▼
┌─────────────┐ 否 ┌──────────┐
│ 全局开关开启?├────────────►│ 未授权 │
└──────┬──────┘ └──────────┘
│是
▼
┌─────────────┐ 是 ┌──────────┐
│ 授权已过期? ├────────────►│ 未授权 │
└──────┬──────┘ └──────────┘
│否
▼
┌─────────────┐ 否 ┌──────────┐
│ 具体权限=1? ├────────────►│ 未授权 │
└──────┬──────┘ └──────────┘
│是
▼
┌──────────┐
│ 已授权 │
└──────────┘
四、具体弹窗代码
三方应用在读取权限Key为0(未授权)后,需弹出"允许/不允许"授权提示框。推荐通过广播触发系统弹窗(方式1),
系统已内置对话框和处理逻辑;
方式1:广播触发系统弹窗(推荐)
发送广播后,系统 PrivacyPolicyMonitorService 会自动弹出权限授权请求对话框,包含"允许"和"不允许"按钮,
用户点击"允许"后系统自动将对应 Settings.System Key 设为1,并继续检查下一个未授权权限。
/**
* 请求权限授权,触发系统弹出"允许/不允许"对话框
* @param context 上下文
* @param targetPackageName 目标应用包名(用于系统判断所需权限列表)
* @param permissionKey 具体的权限Key
*/
public static void requestPermission(Context context, String targetPackageName, String permissionKey) {
Intent intent = new Intent("com.yaxon.carcontrol.ACTION_OPEN_PERMISSION_UI");
intent.putExtra("package_name", targetPackageName);
intent.putExtra("permission_key", permissionKey);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
}
// 使用示例:百度地图检测到位置权限未授权
if (locationPermission == 0) {
requestPermission(context, "com.title.mapautosdk", "xcmg_permission_location_map");
}
系统弹窗样式:
┌─────────────────────────────────────┐
│ 提示 │
│ │
│ 位置权限-地图:是否允许开启 │
│ 位置权限? │
│ │
│ 开启后,地图将被授权可获取位置信息 │
│ │
│ [允许] [不允许] │
└─────────────────────────────────────┘
用户操作结果:
- 点击"允许" → Settings.System 写入该 Key=1 → 继续检查下一个未授权权限 → 全部授权后自动启动目标应用
- 点击"不允许" → Settings.System 写入该 Key=0 → 流程结束
五、应用包名与权限Key对照表
┌──────────────────────────────┬──────────────────────────────────────────────────────────┐
│ 应用包名 │ 权限Key │
├──────────────────────────────┼──────────────────────────────────────────────────────────┤
│ com.yaxon.bluetooth │ xcmg_permission_contacts_bluetooth_phone │
│ │ xcmg_permission_microphone_bluetooth_phone │
├──────────────────────────────┼──────────────────────────────────────────────────────────┤
│ com.txznet.txz │ xcmg_permission_microphone_voice_assistant │
│ (同行者语音助手) │ xcmg_permission_location_voice_assistant │
├──────────────────────────────┼──────────────────────────────────────────────────────────┤
│ com.txznet.adapter │ xcmg_permission_microphone_voice_assistant │
│ (同行者语音适配) │ xcmg_permission_location_voice_assistant │
├──────────────────────────────┼──────────────────────────────────────────────────────────┤
│ com.txzing.voiceassistant │ xcmg_permission_microphone_voice_assistant │
│ (语音助手) │ xcmg_permission_location_voice_assistant │
├──────────────────────────────┼──────────────────────────────────────────────────────────┤
│ com.title.mapautosdk │ xcmg_permission_location_map │
│ (百度地图) │ │
├──────────────────────────────┼──────────────────────────────────────────────────────────┤
│ net.easyconn │ xcmg_permission_location_carlink │
│ (亿连手机互联) │ │
├──────────────────────────────┼──────────────────────────────────────────────────────────┤
│ com.yaxon.dvr │ xcmg_permission_camera_dvr │
│ (行车记录仪) │ │
└──────────────────────────────┴──────────────────────────────────────────────────────────┘
---
六、Key 速查(可直接复制)
**全局控制:**
```
xcmg_permission_global_switch // 全局开关 0=关闭 1=开启
xcmg_permission_authorization_duration // 有效期 1=180天 2=360天
xcmg_permission_authorization_date // 授权开始时间戳(毫秒)
```
**权限 Key:**
```
xcmg_permission_contacts_bluetooth_phone // 联系人权限 - 蓝牙电话读取联系人
xcmg_permission_microphone_voice_assistant // 麦克风权限 - 语音助手录音
xcmg_permission_microphone_bluetooth_phone // 麦克风权限 - 蓝牙电话通话
xcmg_permission_location_voice_assistant // 位置权限 - 语音助手获取位置
xcmg_permission_location_map // 位置权限 - 地图/导航获取位置
xcmg_permission_location_carlink // 位置权限 - 亿连手机互联获取位置
xcmg_permission_camera_dvr // 摄像头权限 - 行车记录仪录像
```
**应用包名:**
```
com.yaxon.bluetooth // 蓝牙
com.txznet.txz // 同行者语音助手
com.txznet.adapter // 同行者语音适配
com.txzing.voiceassistant // 语音助手
com.title.mapautosdk // 百度地图
net.easyconn // 亿连手机互联
com.yaxon.dvr // 行车记录仪
```