feat(security): 加固令牌与会话隔离,完善局域网授权与相册分页

- 令牌改用安全存储持久化,登录/登出按会话版本重建 ProviderScope 并清理账号缓存
- dio 401 刷新改为并发共享单次刷新,避免旧会话覆盖新账号令牌
- Android 17 增加局域网权限申请与网络安全配置,iOS 补充本地网络说明与钥匙串权限
- 相册分页加载并及时释放缩略图/媒体缓存,远程连接销毁时释放信令与 WebRTC
- 升级 AGP 9 / Gradle 9 / compileSdk 37,统一第三方插件 compileSdk,Windows 启用 /utf-8
- 新增 dio 刷新、会话隔离与相册分页单元测试
This commit is contained in:
tongtong committed 2026-11-05 11:19:52 +08:00
1 parent 7435588fa7
commit 4976a26892
41 files changed
+1232 -654

No files matched your search

@@ -1,3 +1,4 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_webrtc/flutter_webrtc.dart';
@@ -27,17 +28,22 @@ class ConnectionSessionState {
/// 是否正在录制远程视频。
final bool recording;
/// 录制状态提示(已保存路径等)。
final String recordStatus;
/// 当前选中的分辨率预设下标。
final int selectedResolution;
/// 分辨率预设列表。
final List<Map<String, Object>> resolutionOptions;
/// 帧率档位(收到被控端上报后以上报列表为准)。
final List<int> fpsOptions;
/// 被控端当前采集帧率(0 表示尚未收到上报)。
final int currentFps;
/// 被控端最近上报的实际采集尺寸(切帧率时保持分辨率不变)。
final int lastReportedWidth;
final int lastReportedHeight;
@@ -92,10 +98,29 @@ class ConnectionController extends Notifier<ConnectionSessionState> {
@override
ConnectionSessionState build() {
final signaling = ref.read(signalingClientProvider);
ref.onDispose(() {
_disposed = true;
signaling.onMessage = null;
signaling.onError = null;
signaling.dispose();
final orchestrator = _orchestrator;
_orchestrator = null;
if (orchestrator != null) {
orchestrator.onConnectionState = null;
orchestrator.onReport = null;
}
unawaited(
_videoRecorder.dispose().whenComplete(() async {
await orchestrator?.dispose();
}),
);
});
return const ConnectionSessionState();
}
/// 目标设备 SN(页面初始化时设置)。
bool _disposed = false;
String? _targetSn;
set targetSn(String? value) => _targetSn = value;
@@ -151,8 +176,10 @@ class ConnectionController extends Notifier<ConnectionSessionState> {
try {
await signaling.connect(signalServerUrl, targetSn: sn);
await _orchestrator!.start();
if (_disposed) return;
await _orchestrator?.start();
} catch (e) {
if (_disposed) return;
state = ConnectionSessionState(
state: ConnectionState.error,
errorMessage: '连接失败: $e',
@@ -162,17 +189,11 @@ class ConnectionController extends Notifier<ConnectionSessionState> {
void _onRtcState(bool connected) {
if (connected) {
state = state.copyWith(
state: ConnectionState.connected,
hasVideo: true,
);
state = state.copyWith(state: ConnectionState.connected, hasVideo: true);
// 连接成功后按默认分辨率(1080P)下发一次,确保默认生效。
selectResolution(state.selectedResolution);
} else {
state = state.copyWith(
state: ConnectionState.ended,
hasVideo: false,
);
state = state.copyWith(state: ConnectionState.ended, hasVideo: false);
}
}
@@ -194,23 +215,31 @@ class ConnectionController extends Notifier<ConnectionSessionState> {
/// 发送点击(相对坐标 0~1)。
void sendTap(double relX, double relY) {
debugPrint('[touch] TAP rel=(${relX.toStringAsFixed(3)}, ${relY.toStringAsFixed(3)})');
debugPrint(
'[touch] TAP rel=(${relX.toStringAsFixed(3)}, ${relY.toStringAsFixed(3)})',
);
_orchestrator?.sendTap(relX, relY);
}
void sendLongPress(double relX, double relY) {
debugPrint('[touch] LONG_PRESS rel=(${relX.toStringAsFixed(3)}, ${relY.toStringAsFixed(3)})');
debugPrint(
'[touch] LONG_PRESS rel=(${relX.toStringAsFixed(3)}, ${relY.toStringAsFixed(3)})',
);
_orchestrator?.sendLongPress(relX, relY);
}
void sendSwipe(double relX1, double relY1, double relX2, double relY2) {
debugPrint('[touch] SWIPE rel=(${relX1.toStringAsFixed(3)}, ${relY1.toStringAsFixed(3)}) -> (${relX2.toStringAsFixed(3)}, ${relY2.toStringAsFixed(3)})');
debugPrint(
'[touch] SWIPE rel=(${relX1.toStringAsFixed(3)}, ${relY1.toStringAsFixed(3)}) -> (${relX2.toStringAsFixed(3)}, ${relY2.toStringAsFixed(3)})',
);
_orchestrator?.sendSwipe(relX1, relY1, relX2, relY2);
}
/// 发送实时触摸事件(MOTION_EVENT,跟手用)。action:0=DOWN,1=UP,2=MOVE。
void sendMotionEvent(int action, double relX, double relY) {
debugPrint('[touch] MOTION action=$action rel=(${relX.toStringAsFixed(3)}, ${relY.toStringAsFixed(3)})');
debugPrint(
'[touch] MOTION action=$action rel=(${relX.toStringAsFixed(3)}, ${relY.toStringAsFixed(3)})',
);
_orchestrator?.sendMotionEvent(action, relX, relY);
}
@@ -283,10 +312,20 @@ class ConnectionController extends Notifier<ConnectionSessionState> {
/// 关闭并清理。
Future<void> disconnect() async {
await _videoRecorder.dispose();
await _orchestrator?.dispose();
final signaling = ref.read(signalingClientProvider);
final orchestrator = _orchestrator;
_orchestrator = null;
ref.read(signalingClientProvider).dispose();
state = const ConnectionSessionState(state: ConnectionState.ended);
signaling.onMessage = null;
signaling.onError = null;
signaling.dispose();
if (orchestrator != null) {
orchestrator.onConnectionState = null;
orchestrator.onReport = null;
}
await _videoRecorder.dispose();
await orchestrator?.dispose();
if (!_disposed) {
state = const ConnectionSessionState(state: ConnectionState.ended);
}
}
}