mirror of
https://github.com/VallierDev/uu-remote-linux.git
synced 2026-11-16 16:50:41 +01:00
fix(privacy): accept the Windows viewer's enable=0 encoding (#202)
This commit is contained in:
1 parent
ac9606b872
commit
101123797a
4 files changed
+53
-5
No files matched your search
+5
-2
@@ -81,7 +81,7 @@ fn finger_held(finger: Finger, now: std::time::Instant) -> Option<(i32,i32)> {
|
||||
/// Viewer platform from the connect header `controller_platform` (website enum: 1 windows, 2 android,
|
||||
/// 3 ios, 4 macos, 5 tv).
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub enum Controller { #[default] Other, Mac, Mobile, Ios }
|
||||
pub enum Controller { #[default] Other, Windows, Mac, Mobile, Ios }
|
||||
impl Controller {
|
||||
/// Touch semantics cover both mobile platforms; the iOS RPC 7 screen-off encoding is its own quirk.
|
||||
pub fn is_mobile(self) -> bool { matches!(self, Self::Mobile | Self::Ios) }
|
||||
@@ -92,9 +92,11 @@ impl Controller {
|
||||
Some(4) => Self::Mac,
|
||||
Some(3) => Self::Ios,
|
||||
Some(2) => Self::Mobile,
|
||||
Some(1) => Self::Windows,
|
||||
_ if text.as_deref().is_some_and(|s| s.contains("mac") || s.contains("darwin")) => Self::Mac,
|
||||
_ if text.as_deref().is_some_and(|s| s.contains("ios") || s.contains("iphone") || s.contains("ipad")) => Self::Ios,
|
||||
_ if text.as_deref().is_some_and(|s| s.contains("android")) => Self::Mobile,
|
||||
_ if text.as_deref().is_some_and(|s| s.contains("windows")) => Self::Windows,
|
||||
_ => Self::Other,
|
||||
}
|
||||
}
|
||||
@@ -1310,7 +1312,8 @@ mod touch_tests {
|
||||
assert!(!Controller::Mac.is_mobile());
|
||||
assert_eq!(Controller::from_platform(Some(&json!(4))), Controller::Mac);
|
||||
assert_eq!(Controller::from_platform(Some(&json!("MacOS"))), Controller::Mac);
|
||||
assert_eq!(Controller::from_platform(Some(&json!(1))), Controller::Other);
|
||||
assert_eq!(Controller::from_platform(Some(&json!(1))), Controller::Windows);
|
||||
assert_eq!(Controller::from_platform(Some(&json!("Windows"))), Controller::Windows);
|
||||
assert_eq!(Controller::from_platform(None), Controller::Other);
|
||||
}
|
||||
#[test]
|
||||
|
||||
@@ -25,14 +25,17 @@ static POINTER: Mutex<Option<[f64; 4]>> = Mutex::new(None);
|
||||
/// ends. An auto-enable never overrides it, including an RPC that arrives after the connection
|
||||
/// opens but before `session_started` bumps the counter.
|
||||
static VIEWER_OVERRIDE: AtomicBool = AtomicBool::new(false);
|
||||
/// iOS viewers encode "screen off" as `enable=0, type=3`; see
|
||||
/// `protocol::Request::normalize_ios_screen_off`.
|
||||
/// iOS viewers encode "screen off" as `enable=0, type=3`, and Windows viewers carry every request
|
||||
/// in `type` with `enable=0`; see `protocol::Request::normalize_ios_screen_off` and
|
||||
/// `protocol::Request::normalize_windows`.
|
||||
static VIEWER_IOS: AtomicBool = AtomicBool::new(false);
|
||||
static VIEWER_WINDOWS: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
pub fn supported() -> bool { backend::detect().is_some() }
|
||||
/// Record the desktop controller's platform for the iOS RPC 7 encoder quirk.
|
||||
/// Record the desktop controller's platform for the RPC 7 encoder quirks.
|
||||
pub fn set_viewer_controller(controller: crate::input::Controller) {
|
||||
VIEWER_IOS.store(controller == crate::input::Controller::Ios, Ordering::Relaxed);
|
||||
VIEWER_WINDOWS.store(controller == crate::input::Controller::Windows, Ordering::Relaxed);
|
||||
}
|
||||
pub fn active() -> bool { ACTIVE.load(Ordering::Relaxed) }
|
||||
/// The viewer's privacy_type now in effect.
|
||||
@@ -125,6 +128,9 @@ pub fn rpc_accept(rpc: &[crate::protocol::WireField]) -> Option<(Vec<u8>, Option
|
||||
// as an accepted request would.
|
||||
VIEWER_OVERRIDE.store(true, Ordering::Relaxed);
|
||||
log::info!("Privacy request: iOS screen-off encoding normalized (enable=0 type=3)");
|
||||
} else if request.normalize_windows(VIEWER_WINDOWS.load(Ordering::Relaxed)) {
|
||||
VIEWER_OVERRIDE.store(true, Ordering::Relaxed);
|
||||
log::info!("Privacy request: Windows encoding normalized (enable=0 mode={:?})", request.mode);
|
||||
}
|
||||
if let Some(e) = refuse(request.enable, request.mode) {
|
||||
log::warn!("Privacy request refused: enable={} mode={:?}: {e}", request.enable, request.mode);
|
||||
|
||||
@@ -17,6 +17,16 @@ impl Request {
|
||||
}
|
||||
false
|
||||
}
|
||||
/// Windows viewers send every privacy request with `enable=0` and carry the intent in
|
||||
/// `privacy_type`: `0/0` is off, `0/2` picture and `0/3` screen-off (verified live on the
|
||||
/// Windows client). Android 4.43.0 and macOS keep field 1 as the master switch.
|
||||
pub fn normalize_windows(&mut self, windows: bool) -> bool {
|
||||
if windows && !self.enable && self.mode.is_some() {
|
||||
self.enable = true;
|
||||
return true;
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse(rpc: &[crate::protocol::WireField]) -> Option<(Vec<u8>, Request)> {
|
||||
@@ -106,4 +116,31 @@ mod tests {
|
||||
assert!(!request.normalize_ios_screen_off(true));
|
||||
assert!(request.enable);
|
||||
}
|
||||
#[test]
|
||||
fn normalizes_windows_encoding_only() {
|
||||
// Windows: enable is always 0, the type carries the intent.
|
||||
for (wire, mode) in [(2u8, Mode::Picture), (3u8, Mode::ScreenOff)] {
|
||||
let bytes = [10, 2, 8, 42, 58, 4, 8, 0, 16, wire];
|
||||
let (_, mut request) = parse(&crate::protocol::decode_wire(&bytes).unwrap()).unwrap();
|
||||
assert!(request.normalize_windows(true));
|
||||
assert!(request.enable);
|
||||
assert_eq!(request.mode, Some(mode));
|
||||
}
|
||||
// Off stays off: type 0 (seen when the Windows switch is turned off) and type 1.
|
||||
for wire in [0u8, 1] {
|
||||
let bytes = [10, 2, 8, 42, 58, 4, 8, 0, 16, wire];
|
||||
let (_, mut request) = parse(&crate::protocol::decode_wire(&bytes).unwrap()).unwrap();
|
||||
assert!(!request.normalize_windows(true));
|
||||
assert!(!request.enable);
|
||||
}
|
||||
// Other platforms and explicit enables are untouched.
|
||||
let picture = crate::protocol::decode_wire(&[10, 2, 8, 42, 58, 4, 8, 0, 16, 2]).unwrap();
|
||||
let (_, mut request) = parse(&picture).unwrap();
|
||||
assert!(!request.normalize_windows(false));
|
||||
assert!(!request.enable);
|
||||
let explicit = crate::protocol::decode_wire(&[10, 2, 8, 42, 58, 4, 8, 1, 16, 2]).unwrap();
|
||||
let (_, mut request) = parse(&explicit).unwrap();
|
||||
assert!(!request.normalize_windows(true));
|
||||
assert!(request.enable);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user