feat: 控制通道权限分级(仅查看 / 查看+控制 / 全权限)
- 协议新增 msgType=10 access 应答,sessionConfig 增加 access 请求字段,三端同步 - rust_core:解码/编码 Access 事件,收到后入队给界面;send_control 支持 msgType=10 - android_receiver:新增 AccessLevel,被控端按本机上限裁剪请求并回送有效等级 - android_receiver:越权帧真正丢弃——输入/剪贴板需 control,文件子协议需 full 且回错误响应 - android_receiver:主界面增加权限单选(持久化),调整后当前连接立即生效并通知主控端 - flutter_sender:AppSettings 增加请求等级并在设置页可选,连接后自动下发 - flutter_sender:接收 msgType=10 更新有效等级,越权操作在界面禁用并提示 - docs:README/AGENTS 补充权限协议与各操作的最低等级
This commit is contained in:
1 parent
e2020ab595
commit
a1c3f79cd8
17 files changed
+504
-25
No files matched your search
@@ -8,8 +8,7 @@ enum ConnectionPhase {
|
||||
failed,
|
||||
}
|
||||
|
||||
extension ConnectionPhaseX on ConnectionPhase {
|
||||
String get wireName => name;
|
||||
extension ConnectionPhaseX on ConnectionPhase { String get wireName => name;
|
||||
|
||||
String get label => switch (this) {
|
||||
ConnectionPhase.idle => '未连接',
|
||||
@@ -116,6 +115,51 @@ class DeviceInfo {
|
||||
}
|
||||
}
|
||||
|
||||
/// 会话权限等级,与被控端 `protocol/AccessLevel.kt` 一一对应。
|
||||
///
|
||||
/// 主控端只能「请求」等级,被控端按本机上限裁剪后用 msgType=10 回送有效等级;
|
||||
/// 界面按 [granted] 决定哪些操作可用,超出的操作在被控端也会被丢弃。
|
||||
enum AccessLevel {
|
||||
view(0, 'view', '仅查看'),
|
||||
control(1, 'control', '查看+控制'),
|
||||
full(2, 'full', '全权限');
|
||||
|
||||
const AccessLevel(this.value, this.code, this.label);
|
||||
|
||||
final int value;
|
||||
final String code;
|
||||
final String label;
|
||||
|
||||
/// 能否注入输入与同步剪贴板。
|
||||
bool get allowsControl => value >= control.value;
|
||||
|
||||
/// 能否使用文件子协议(浏览/上传/下载)。
|
||||
bool get allowsFiles => this == AccessLevel.full;
|
||||
|
||||
static AccessLevel fromValue(Object? raw, {AccessLevel fallback = AccessLevel.full}) {
|
||||
final value = raw is num ? raw.toInt() : int.tryParse('$raw');
|
||||
for (final level in AccessLevel.values) {
|
||||
if (level.value == value) return level;
|
||||
}
|
||||
return fromCode(raw, fallback: fallback);
|
||||
}
|
||||
|
||||
static AccessLevel fromCode(Object? raw, {AccessLevel fallback = AccessLevel.full}) {
|
||||
final text = (raw ?? '').toString().trim().toLowerCase();
|
||||
if (text.isEmpty) return fallback;
|
||||
for (final level in AccessLevel.values) {
|
||||
if (level.code == text || '${level.value}' == text) return level;
|
||||
}
|
||||
return switch (text) {
|
||||
'read' || 'readonly' || 'read-only' => AccessLevel.view,
|
||||
_ => fallback,
|
||||
};
|
||||
}
|
||||
|
||||
/// 取两者中更严格的等级。
|
||||
AccessLevel cap(AccessLevel max) => value <= max.value ? this : max;
|
||||
}
|
||||
|
||||
class AppSettings {
|
||||
final String signalingUrl;
|
||||
final bool useLocalSignaling;
|
||||
@@ -132,6 +176,8 @@ class AppSettings {
|
||||
final String fileToken;
|
||||
/// 连接时是否走信令中继(跨网段)。中继只承载控制通道,不能投屏。
|
||||
final bool relayEnabled;
|
||||
/// 向被控端请求的权限等级(被控端可能按其本机上限下调)。
|
||||
final AccessLevel access;
|
||||
|
||||
const AppSettings({
|
||||
this.signalingUrl = '',
|
||||
@@ -146,6 +192,7 @@ class AppSettings {
|
||||
this.filePort = 53317,
|
||||
this.fileToken = '',
|
||||
this.relayEnabled = false,
|
||||
this.access = AccessLevel.full,
|
||||
});
|
||||
|
||||
static const defaults = AppSettings();
|
||||
@@ -165,6 +212,7 @@ class AppSettings {
|
||||
int? filePort,
|
||||
String? fileToken,
|
||||
bool? relayEnabled,
|
||||
AccessLevel? access,
|
||||
}) {
|
||||
return AppSettings(
|
||||
signalingUrl: signalingUrl ?? this.signalingUrl,
|
||||
@@ -179,6 +227,7 @@ class AppSettings {
|
||||
filePort: filePort ?? this.filePort,
|
||||
fileToken: fileToken ?? this.fileToken,
|
||||
relayEnabled: relayEnabled ?? this.relayEnabled,
|
||||
access: access ?? this.access,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -198,6 +247,7 @@ class AppSettings {
|
||||
filePort: (json['filePort'] is num ? json['filePort'] as num : 53317).toInt(),
|
||||
fileToken: (json['fileToken'] ?? defaults.fileToken).toString(),
|
||||
relayEnabled: json['relayEnabled'] as bool? ?? defaults.relayEnabled,
|
||||
access: AccessLevel.fromCode(json['access'], fallback: defaults.access),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -214,5 +264,6 @@ class AppSettings {
|
||||
'filePort': filePort,
|
||||
'fileToken': fileToken,
|
||||
'relayEnabled': relayEnabled,
|
||||
'access': access.code,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user