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:
tongtong committed 2026-11-27 20:55:54 +08:00
1 parent e2020ab595
commit a1c3f79cd8
17 files changed
+504 -25

No files matched your search

+13 -3
View File
@@ -1,9 +1,9 @@
use super::codec::{CodecError, ControlFrameCodec, ControlFrameHeader};
use super::events::{
ClipboardEvent, ConfigEvent, ControlEvent, ControlEventKind, FileEvent, KeyAction,
AccessEvent, ClipboardEvent, ConfigEvent, ControlEvent, ControlEventKind, FileEvent, KeyAction,
KeyboardEvent, MirrorEvent, MouseAction, MouseEvent, TouchAction, TouchEvent, WheelEvent,
MSG_CLIPBOARD, MSG_CONFIG, MSG_FILE, MSG_KEY, MSG_MIRROR, MSG_MOUSE, MSG_PING, MSG_PONG,
MSG_TOUCH, MSG_WHEEL, PROTOCOL_VERSION,
MSG_ACCESS, MSG_CLIPBOARD, MSG_CONFIG, MSG_FILE, MSG_KEY, MSG_MIRROR, MSG_MOUSE, MSG_PING,
MSG_PONG, MSG_TOUCH, MSG_WHEEL, PROTOCOL_VERSION,
};
#[derive(Debug, Default, Clone, Copy)]
@@ -59,6 +59,9 @@ impl ControlFrameCodec for BinaryCodec {
ControlEventKind::Config(payload) => {
buffer.extend_from_slice(payload.json.as_bytes());
}
ControlEventKind::Access(payload) => {
buffer.extend_from_slice(payload.json.as_bytes());
}
ControlEventKind::File(payload) => {
buffer.extend_from_slice(payload.json.as_bytes());
}
@@ -173,6 +176,10 @@ fn decode_payload(msg_type: u8, payload: &[u8]) -> Result<ControlEventKind, Code
let json = String::from_utf8(payload.to_vec()).map_err(|_| CodecError::InvalidUtf8)?;
Ok(ControlEventKind::Config(ConfigEvent { json }))
}
MSG_ACCESS => {
let json = String::from_utf8(payload.to_vec()).map_err(|_| CodecError::InvalidUtf8)?;
Ok(ControlEventKind::Access(AccessEvent { json }))
}
MSG_FILE => {
let json = String::from_utf8(payload.to_vec()).map_err(|_| CodecError::InvalidUtf8)?;
Ok(ControlEventKind::File(FileEvent { json }))
@@ -237,6 +244,9 @@ mod tests {
assert_roundtrip(ControlEventKind::Config(ConfigEvent {
json: r#"{"preferH265":true,"bitrateMbps":12}"#.to_string(),
}));
assert_roundtrip(ControlEventKind::Access(AccessEvent {
json: r#"{"level":1,"name":"control","max":2,"requested":2}"#.to_string(),
}));
assert_roundtrip(ControlEventKind::File(FileEvent {
json: r#"{"op":"list","path":""}"#.to_string(),
}));
+14 -1
View File
@@ -15,9 +15,13 @@ pub const MSG_FILE: u8 = 7;
pub const MSG_MIRROR: u8 = 8;
/// 会话配置。payload = UTF-8 JSON:`preferH265` / `bitrateMbps` /
/// `audioEnabled` / `clipboardSync`,字段全部可选。
/// `audioEnabled` / `clipboardSync` / `access`,字段全部可选。
pub const MSG_CONFIG: u8 = 9;
/// 权限等级应答。payload = UTF-8 JSON:
/// `{"level":0|1|2,"name":"view|control|full","max":0|1|2,"requested":0|1|2}`。
pub const MSG_ACCESS: u8 = 10;
/// 投屏控制动作,两端必须保持一致。
pub mod mirror_action {
pub const REQUEST: u8 = 0;
@@ -171,6 +175,13 @@ pub struct ConfigEvent {
pub json: String,
}
/// 权限等级应答负载(msgType=10)。`json` 是被控端计算后的有效等级,例如
/// `{"level":1,"name":"control","max":2,"requested":2}`。
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AccessEvent {
pub json: String,
}
/// 文件子协议负载(msgType=7)。`json` 是原样的 UTF-8 JSON,字段由子协议定义。
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FileEvent {
@@ -188,6 +199,7 @@ pub enum ControlEventKind {
Pong(u64),
Mirror(MirrorEvent),
Config(ConfigEvent),
Access(AccessEvent),
File(FileEvent),
}
@@ -217,6 +229,7 @@ impl ControlEvent {
ControlEventKind::Pong(_) => MSG_PONG,
ControlEventKind::Mirror(_) => MSG_MIRROR,
ControlEventKind::Config(_) => MSG_CONFIG,
ControlEventKind::Access(_) => MSG_ACCESS,
ControlEventKind::File(_) => MSG_FILE,
}
}
+15 -2
View File
@@ -15,8 +15,9 @@ use std::thread::{self, JoinHandle};
use std::time::{Duration, Instant};
use crate::control::events::{
ClipboardEvent, ConfigEvent, FileEvent, KeyAction, KeyboardEvent, MirrorEvent, MouseAction,
MouseEvent, TouchAction, TouchEvent, WheelEvent, MSG_CLIPBOARD, MSG_MIRROR,
AccessEvent, ClipboardEvent, ConfigEvent, FileEvent, KeyAction, KeyboardEvent, MirrorEvent,
MouseAction, MouseEvent, TouchAction, TouchEvent, WheelEvent, MSG_ACCESS, MSG_CLIPBOARD,
MSG_MIRROR,
};
use crate::control::{ControlEvent, ControlEventKind};
@@ -857,6 +858,11 @@ pub fn config_event(sequence: u16, json: String) -> ControlEvent {
ControlEvent::new(sequence, ControlEventKind::Config(ConfigEvent { json }))
}
/// msgType=10 权限等级应答:payload 是被控端算出的有效等级 JSON。
pub fn access_event(sequence: u16, json: String) -> ControlEvent {
ControlEvent::new(sequence, ControlEventKind::Access(AccessEvent { json }))
}
fn run_tcp(listener: TcpListener, shared: Arc<Shared>) {
while shared.running.load(Ordering::Relaxed) {
match listener.accept() {
@@ -1222,6 +1228,13 @@ fn dispatch_control_event(
text: mirror.message.clone(),
});
}
ControlEventKind::Access(access) => {
shared.push_inbound(InboundEvent {
msg_type: MSG_ACCESS,
action: 0,
text: access.json.clone(),
});
}
ControlEventKind::Clipboard(clipboard) => {
shared.push_inbound(InboundEvent {
msg_type: MSG_CLIPBOARD,
+7 -1
View File
@@ -302,6 +302,7 @@ pub unsafe extern "C" fn ttstd_control_decode(
ControlEventKind::Clipboard(_) => "clipboard",
ControlEventKind::Mirror(_) => "mirror",
ControlEventKind::Config(_) => "config",
ControlEventKind::Access(_) => "access",
ControlEventKind::File(_) => "file",
};
let json = format!(
@@ -315,7 +316,7 @@ pub unsafe extern "C" fn ttstd_control_decode(
/// 向当前被控端下发控制帧。payload 为各事件类型的二进制负载。
/// msg_type: 0=touch 1=mouse 2=key 3=wheel 4=clipboard(UTF-8) 5=ping(u64 LE)
/// 8=mirror([action:u8]+文本) 9=sessionConfig(UTF-8 JSON)
/// 8=mirror([action:u8]+文本) 9=sessionConfig(UTF-8 JSON) 10=access(UTF-8 JSON)
#[no_mangle]
pub unsafe extern "C" fn ttstd_demo_send_control(
sequence: u16,
@@ -373,6 +374,11 @@ pub unsafe extern "C" fn ttstd_demo_send_control(
sequence,
String::from_utf8_lossy(bytes).to_string(),
)),
// 10 = 权限等级应答:payload 就是 UTF-8 JSON
10 => Some(crate::demo_server::access_event(
sequence,
String::from_utf8_lossy(bytes).to_string(),
)),
_ => None,
};
match event {