Browse Source

上传移动需求优化

newdev_shunjiawei
liwei1dao 5 months ago
parent
commit
574395258f
  1. 9
      lib/data/services/ble_manager.dart
  2. 8
      lib/modules/devices/views/devices_view.dart
  3. 7
      local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt
  4. 15
      local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/StsAgent.kt
  5. 3
      local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift
  6. 18
      local_plugins/agent_service/ios/agent_service/Sources/agent_service/StsAgent.swift

9
lib/data/services/ble_manager.dart

@ -977,7 +977,13 @@ class BleManager extends GetxService {
);
stsCmei = matchedDevice.cmei;
} catch (_) {}
Logger.i('BleManager', '当前设备 CMEI: $stsCmei (MAC=$mac)');
// 当前连接设备的固件版本:原始为 "L1.L2.L3.R1.R2.R3",取左 3 段作为单一版本
final rawFw = deviceInfo.value?.firmwareVersion ?? '';
final fwParts = rawFw.split('.');
final stsFirmwareVersion =
fwParts.length >= 3 ? fwParts.take(3).join('.') : rawFw;
Logger.i('BleManager',
'当前设备 CMEI: $stsCmei (MAC=$mac) firmware=$stsFirmwareVersion');
final config = <String, dynamic>{
// STS 模式路由
@ -990,6 +996,7 @@ class BleManager extends GetxService {
'stsDeviceSecret': stsDeviceSecret,
'stsCmei': stsCmei,
'stsMac': mac,
'stsFirmwareVersion': stsFirmwareVersion,
// 语音代理配置参数
'azureSpeechKey': azureSpeechKey,
'azureSpeechRegion': azureSpeechRegion,

8
lib/modules/devices/views/devices_view.dart

@ -504,12 +504,10 @@ class DevicesView extends GetView<DevicesController> {
final info = bleManager.deviceInfo.value;
final fwVersion =
connected ? (info?.firmwareVersion ?? '') : '';
// 固件版本格式:左 3 段 + 右 3 段,拼成 "0.0.1.0.0.1";按 6 段拆左右
// 固件版本原始格式:左 3 段 + 右 3 段("0.0.1.0.0.1"),只展示左版本
final parts = fwVersion.split('.');
final hasLeftRight = parts.length >= 6;
final fwDisplay = hasLeftRight
? 'L ${parts.take(3).join('.')} · R ${parts.skip(3).take(3).join('.')}'
: fwVersion;
final fwDisplay =
parts.length >= 3 ? parts.take(3).join('.') : fwVersion;
final hasFirmware = fwVersion.isNotEmpty;
final hasLicense = device.license.isNotEmpty;
final hasCmei = device.cmei.isNotEmpty;

7
local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt

@ -497,6 +497,7 @@ object AgentService : CoroutineScope {
agentId = agentId,
cmei = config["stsCmei"]?.toString() ?: "",
mac = config["stsMac"]?.toString() ?: "",
firmwareVersion = config["stsFirmwareVersion"]?.toString() ?: "",
)
stsAgent = StsAgent(
context = context,
@ -632,7 +633,7 @@ object AgentService : CoroutineScope {
config["mcpServer"]?.toString() ?: "",
config["musicServiceType"]?.toString() ?: ""
)
// 更新 STS 模式参数(cmei / mac 等可能在首次初始化时尚未获取到)
// 更新 STS 模式参数(cmei / mac / firmwareVersion 等可能在首次初始化时尚未获取到)
val newCmei = config["stsCmei"]?.toString() ?: ""
if (newCmei.isNotEmpty()) {
stsAgent?.updateCmei(newCmei)
@ -641,6 +642,10 @@ object AgentService : CoroutineScope {
if (newMac.isNotEmpty()) {
stsAgent?.updateMac(newMac)
}
val newFirmwareVersion = config["stsFirmwareVersion"]?.toString() ?: ""
if (newFirmwareVersion.isNotEmpty()) {
stsAgent?.updateFirmwareVersion(newFirmwareVersion)
}
} catch (e: Exception) {
_log("ERROR", "[Agent] 应用配置更新失败: ${e.message}")
}

15
local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/StsAgent.kt

@ -42,6 +42,7 @@ data class StsConfig(
val agentId: String,
val cmei: String = "",
val mac: String = "",
val firmwareVersion: String = "",
)
/**
@ -62,7 +63,7 @@ class StsAgent(
override val coroutineContext = Dispatchers.IO + job
init {
Log.i(TAG, "[YIDONG] StsAgent初始化: productId=${config.productId} deviceNo=${config.deviceNo} deviceId=${config.deviceId} agentId=${config.agentId} cmei=${config.cmei} mac=${config.mac} hasSecret=${config.deviceSecret.isNotEmpty()}")
Log.i(TAG, "[YIDONG] StsAgent初始化: productId=${config.productId} deviceNo=${config.deviceNo} deviceId=${config.deviceId} agentId=${config.agentId} cmei=${config.cmei} mac=${config.mac} firmwareVersion=${config.firmwareVersion} hasSecret=${config.deviceSecret.isNotEmpty()}")
fetchCredentials()
}
@ -82,6 +83,14 @@ class StsAgent(
}
}
/** 动态更新固件版本(设备连接后由 BLE 上报,首次初始化时通常尚未获取到) */
fun updateFirmwareVersion(firmwareVersion: String) {
if (firmwareVersion.isNotEmpty() && firmwareVersion != config.firmwareVersion) {
config = config.copy(firmwareVersion = firmwareVersion)
Log.i(TAG, "[YIDONG] updateFirmwareVersion: firmwareVersion已更新为 $firmwareVersion")
}
}
// ── WebSocket ─────────────────────────────────────────────────────────────
private val okHttpClient: OkHttpClient = buildTrustAllClient()
private var webSocket: WebSocket? = null
@ -247,7 +256,7 @@ class StsAgent(
return
}
prefs.edit().putLong("last_heartbeat_ts", now).apply()
Log.i(TAG, "[YIDONG] reportHeartbeat: 开始上报 deviceId=${config.deviceId} deviceNo=${config.deviceNo} cmei=${config.cmei} mac=${config.mac}")
Log.i(TAG, "[YIDONG] reportHeartbeat: 开始上报 deviceId=${config.deviceId} deviceNo=${config.deviceNo} cmei=${config.cmei} mac=${config.mac} firmwareVersion=${config.firmwareVersion}")
launch {
try {
val netType = try {
@ -272,7 +281,7 @@ class StsAgent(
put("netType", netType)
put("platform", "")
put("sdkVersion", "ai_http_1.0")
put("firmwareVersion", "1.0.0")
put("firmwareVersion", config.firmwareVersion) // 当前连接设备的固件版本(左 3 段)
put("imei", "")
put("cmei", config.cmei) // 优先使用 UserDevice 的 CMEI
put("mac", config.mac) // 当前连接的 BLE 设备 MAC(由 Flutter 透传)

3
local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift

@ -272,7 +272,8 @@ class AgentServiceImpl: NSObject {
deviceSecret: config["stsDeviceSecret"] as? String ?? "",
agentId: agentId,
cmei: config["stsCmei"] as? String ?? "",
mac: config["stsMac"] as? String ?? ""
mac: config["stsMac"] as? String ?? "",
firmwareVersion: config["stsFirmwareVersion"] as? String ?? ""
)
stsAgent = StsAgent(
config: stsConfig,

18
local_plugins/agent_service/ios/agent_service/Sources/agent_service/StsAgent.swift

@ -16,6 +16,7 @@ struct StsConfig {
let agentId: String
var cmei: String = ""
var mac: String = ""
var firmwareVersion: String = ""
}
// MARK: - StsAgent
@ -88,9 +89,9 @@ class StsAgent: NSObject {
super.init()
let sessionConfig = URLSessionConfiguration.default
urlSession = URLSession(configuration: sessionConfig, delegate: nil, delegateQueue: OperationQueue())
os_log("StsAgent 初始化: productId=%{public}@ deviceNo=%{public}@ deviceId=%{public}@ cmei=%{public}@ mac=%{public}@ hasSecret=%{public}@",
os_log("StsAgent 初始化: productId=%{public}@ deviceNo=%{public}@ deviceId=%{public}@ cmei=%{public}@ mac=%{public}@ firmwareVersion=%{public}@ hasSecret=%{public}@",
log: logger, type: .info,
config.productId, config.deviceNo, config.deviceId, config.cmei, config.mac,
config.productId, config.deviceNo, config.deviceId, config.cmei, config.mac, config.firmwareVersion,
config.deviceSecret.isEmpty ? "false" : "true")
// 与 Android 行为对齐:凭证已有时立即尝试上报一次心跳(受 1 小时冷却保护)
if !config.deviceSecret.isEmpty && !config.deviceId.isEmpty {
@ -113,6 +114,13 @@ class StsAgent: NSObject {
os_log("updateMac: mac 已更新为 %{public}@", log: logger, type: .info, mac)
}
/// 动态更新固件版本(设备连接后由 BLE 上报,首次初始化时通常尚未获取到)
func updateFirmwareVersion(_ firmwareVersion: String) {
guard !firmwareVersion.isEmpty, firmwareVersion != config.firmwareVersion else { return }
config.firmwareVersion = firmwareVersion
os_log("updateFirmwareVersion: firmwareVersion 已更新为 %{public}@", log: logger, type: .info, firmwareVersion)
}
// MARK: - 公共接口
func startCall() {
@ -241,8 +249,8 @@ class StsAgent: NSObject {
return
}
defaults.set(now, forKey: HEARTBEAT_PREFS_KEY)
os_log("reportHeartbeat: 开始上报 deviceId=%{public}@ deviceNo=%{public}@ cmei=%{public}@ mac=%{public}@",
log: logger, type: .info, config.deviceId, config.deviceNo, config.cmei, config.mac)
os_log("reportHeartbeat: 开始上报 deviceId=%{public}@ deviceNo=%{public}@ cmei=%{public}@ mac=%{public}@ firmwareVersion=%{public}@",
log: logger, type: .info, config.deviceId, config.deviceNo, config.cmei, config.mac, config.firmwareVersion)
let urlStr = "https://ivs.chinamobiledevice.com:11443/v2/customer/device/report"
guard let url = URL(string: urlStr) else { return }
@ -257,7 +265,7 @@ class StsAgent: NSObject {
"netType": "WiFi",
"platform": "",
"sdkVersion": "ai_http_1.0",
"firmwareVersion": "1.0.0",
"firmwareVersion": config.firmwareVersion,
"imei": "",
"cmei": config.cmei,
"mac": config.mac,

Loading…
Cancel
Save