mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-03-13 08:11:01 +03:00
fix: android clipboard permission (#10223)
* fix: android clipboard permission Signed-off-by: fufesou <linlong1266@gmail.com> * refact: Android, clipboard, floating ball Call rust to check if clipboard is enabled. Signed-off-by: fufesou <linlong1266@gmail.com> --------- Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
@@ -8,6 +8,8 @@ use crate::ipc::{self, ClipboardFile, ClipboardNonFile, Data};
|
||||
use clipboard_master::{CallbackResult, ClipboardHandler};
|
||||
#[cfg(target_os = "android")]
|
||||
use hbb_common::config::{keys, option2bool};
|
||||
#[cfg(target_os = "android")]
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::{
|
||||
io,
|
||||
sync::mpsc::{channel, RecvTimeoutError, Sender},
|
||||
@@ -16,6 +18,9 @@ use std::{
|
||||
#[cfg(windows)]
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
static CLIPBOARD_SERVICE_OK: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
struct Handler {
|
||||
sp: EmptyExtraFieldService,
|
||||
@@ -27,6 +32,11 @@ struct Handler {
|
||||
rt: Option<Runtime>,
|
||||
}
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
pub fn is_clipboard_service_ok() -> bool {
|
||||
CLIPBOARD_SERVICE_OK.load(Ordering::SeqCst)
|
||||
}
|
||||
|
||||
pub fn new() -> GenericService {
|
||||
let svc = EmptyExtraFieldService::new(NAME.to_owned(), false);
|
||||
GenericService::run(&svc.clone(), run);
|
||||
@@ -224,11 +234,13 @@ impl Handler {
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
fn run(sp: EmptyExtraFieldService) -> ResultType<()> {
|
||||
CLIPBOARD_SERVICE_OK.store(sp.ok(), Ordering::SeqCst);
|
||||
while sp.ok() {
|
||||
if let Some(msg) = crate::clipboard::get_clipboards_msg(false) {
|
||||
sp.send(msg);
|
||||
}
|
||||
std::thread::sleep(Duration::from_millis(INTERVAL));
|
||||
}
|
||||
CLIPBOARD_SERVICE_OK.store(false, Ordering::SeqCst);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -463,11 +463,6 @@ impl Connection {
|
||||
conn.on_close("connection manager", true).await;
|
||||
break;
|
||||
}
|
||||
#[cfg(target_os = "android")]
|
||||
ipc::Data::InputControl(v) => {
|
||||
conn.keyboard = v;
|
||||
conn.send_permission(Permission::Keyboard, v).await;
|
||||
}
|
||||
ipc::Data::CmErr(e) => {
|
||||
if e != "expected" {
|
||||
// cm closed before connection
|
||||
@@ -492,6 +487,9 @@ impl Connection {
|
||||
conn.keyboard = enabled;
|
||||
conn.send_permission(Permission::Keyboard, enabled).await;
|
||||
if let Some(s) = conn.server.upgrade() {
|
||||
s.write().unwrap().subscribe(
|
||||
super::clipboard_service::NAME,
|
||||
conn.inner.clone(), conn.can_sub_clipboard_service());
|
||||
s.write().unwrap().subscribe(
|
||||
NAME_CURSOR,
|
||||
conn.inner.clone(), enabled || conn.show_remote_cursor);
|
||||
@@ -502,7 +500,7 @@ impl Connection {
|
||||
if let Some(s) = conn.server.upgrade() {
|
||||
s.write().unwrap().subscribe(
|
||||
super::clipboard_service::NAME,
|
||||
conn.inner.clone(), conn.clipboard_enabled() && conn.peer_keyboard_enabled());
|
||||
conn.inner.clone(), conn.can_sub_clipboard_service());
|
||||
}
|
||||
} else if &name == "audio" {
|
||||
conn.audio = enabled;
|
||||
@@ -1372,16 +1370,7 @@ impl Connection {
|
||||
if !self.follow_remote_window {
|
||||
noperms.push(NAME_WINDOW_FOCUS);
|
||||
}
|
||||
// Do not consider the clipboard and keyboard permissions on Android.
|
||||
// Because syncing the clipboard on Android is manually triggered by the user in the floating ball.
|
||||
#[cfg(target_os = "android")]
|
||||
let keyboard_clip_noperm = self.disable_keyboard || self.disable_clipboard;
|
||||
#[cfg(not(target_os = "android"))]
|
||||
let keyboard_clip_noperm =
|
||||
!self.clipboard_enabled() || !self.peer_keyboard_enabled();
|
||||
if keyboard_clip_noperm
|
||||
|| crate::get_builtin_option(keys::OPTION_ONE_WAY_CLIPBOARD_REDIRECTION) == "Y"
|
||||
{
|
||||
if !self.can_sub_clipboard_service() {
|
||||
noperms.push(super::clipboard_service::NAME);
|
||||
}
|
||||
if !self.audio_enabled() {
|
||||
@@ -1453,6 +1442,13 @@ impl Connection {
|
||||
self.clipboard && !self.disable_clipboard
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn can_sub_clipboard_service(&self) -> bool {
|
||||
self.clipboard_enabled()
|
||||
&& self.peer_keyboard_enabled()
|
||||
&& crate::get_builtin_option(keys::OPTION_ONE_WAY_CLIPBOARD_REDIRECTION) != "Y"
|
||||
}
|
||||
|
||||
fn audio_enabled(&self) -> bool {
|
||||
self.audio && !self.disable_audio
|
||||
}
|
||||
@@ -2930,7 +2926,7 @@ impl Connection {
|
||||
s.write().unwrap().subscribe(
|
||||
super::clipboard_service::NAME,
|
||||
self.inner.clone(),
|
||||
self.clipboard_enabled() && self.peer_keyboard_enabled(),
|
||||
self.can_sub_clipboard_service(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2942,7 +2938,7 @@ impl Connection {
|
||||
s.write().unwrap().subscribe(
|
||||
super::clipboard_service::NAME,
|
||||
self.inner.clone(),
|
||||
self.clipboard_enabled() && self.peer_keyboard_enabled(),
|
||||
self.can_sub_clipboard_service(),
|
||||
);
|
||||
s.write().unwrap().subscribe(
|
||||
NAME_CURSOR,
|
||||
|
||||
Reference in New Issue
Block a user