From 6b3c2f3beb32c5f59c82d104e62afdbb93ebf24e Mon Sep 17 00:00:00 2001 From: fufesou Date: Sun, 13 Nov 2022 18:11:13 +0800 Subject: [PATCH] fix android build errors and warnings Signed-off-by: fufesou --- libs/hbb_common/src/config.rs | 58 ++++++++++++++++++++--------------- libs/scrap/src/android/mod.rs | 3 -- src/common.rs | 4 ++- src/flutter_ffi.rs | 11 ++++--- src/platform/mod.rs | 1 + src/server.rs | 8 +++-- src/server/connection.rs | 4 ++- src/server/video_service.rs | 2 +- src/ui_cm_interface.rs | 4 +-- src/ui_interface.rs | 5 +-- src/ui_session_interface.rs | 10 +++--- 11 files changed, 65 insertions(+), 45 deletions(-) diff --git a/libs/hbb_common/src/config.rs b/libs/hbb_common/src/config.rs index cc9da6420..a7836cef7 100644 --- a/libs/hbb_common/src/config.rs +++ b/libs/hbb_common/src/config.rs @@ -8,7 +8,6 @@ use std::{ }; use anyhow::Result; -use directories_next::ProjectDirs; use rand::Rng; use serde_derive::{Deserialize, Serialize}; use sodiumoxide::crypto::sign; @@ -375,12 +374,15 @@ impl Config { pub fn get_home() -> PathBuf { #[cfg(any(target_os = "android", target_os = "ios"))] return Self::path(APP_HOME_DIR.read().unwrap().as_str()); - if let Some(path) = dirs_next::home_dir() { - patch(path) - } else if let Ok(path) = std::env::current_dir() { - path - } else { - std::env::temp_dir() + #[cfg(not(any(target_os = "android", target_os = "ios")))] + { + if let Some(path) = dirs_next::home_dir() { + patch(path) + } else if let Ok(path) = std::env::current_dir() { + path + } else { + std::env::temp_dir() + } } } @@ -391,17 +393,20 @@ impl Config { path.push(p); return path; } - #[cfg(not(target_os = "macos"))] - let org = ""; - #[cfg(target_os = "macos")] - let org = ORG.read().unwrap().clone(); - // /var/root for root - if let Some(project) = ProjectDirs::from("", &org, &*APP_NAME.read().unwrap()) { - let mut path = patch(project.config_dir().to_path_buf()); - path.push(p); - return path; + #[cfg(not(any(target_os = "android", target_os = "ios")))] + { + #[cfg(not(target_os = "macos"))] + let org = ""; + #[cfg(target_os = "macos")] + let org = ORG.read().unwrap().clone(); + // /var/root for root + if let Some(project) = directories_next::ProjectDirs::from("", &org, &*APP_NAME.read().unwrap()) { + let mut path = patch(project.config_dir().to_path_buf()); + path.push(p); + return path; + } + return "".into(); } - return "".into(); } #[allow(unreachable_code)] @@ -580,16 +585,19 @@ impl Config { .to_string(), ); } - let mut id = 0u32; + #[cfg(not(any(target_os = "android", target_os = "ios")))] - if let Ok(Some(ma)) = mac_address::get_mac_address() { - for x in &ma.bytes()[2..] { - id = (id << 8) | (*x as u32); + { + let mut id = 0u32; + if let Ok(Some(ma)) = mac_address::get_mac_address() { + for x in &ma.bytes()[2..] { + id = (id << 8) | (*x as u32); + } + id = id & 0x1FFFFFFF; + Some(id.to_string()) + } else { + None } - id = id & 0x1FFFFFFF; - Some(id.to_string()) - } else { - None } } diff --git a/libs/scrap/src/android/mod.rs b/libs/scrap/src/android/mod.rs index 92d84676e..9040395fa 100644 --- a/libs/scrap/src/android/mod.rs +++ b/libs/scrap/src/android/mod.rs @@ -1,6 +1,3 @@ pub mod ffi; -use std::sync::RwLock; pub use ffi::*; - -use lazy_static::lazy_static; diff --git a/src/common.rs b/src/common.rs index 85fcae304..ea02cf810 100644 --- a/src/common.rs +++ b/src/common.rs @@ -6,10 +6,12 @@ use std::{ #[cfg(not(any(target_os = "android", target_os = "ios")))] pub use arboard::Clipboard as ClipboardContext; +#[cfg(not(any(target_os = "android", target_os = "ios")))] +use hbb_common::compress::decompress; use hbb_common::{ allow_err, anyhow::bail, - compress::{compress as compress_func, decompress}, + compress::{compress as compress_func}, config::{self, Config, COMPRESS_LEVEL, RENDEZVOUS_TIMEOUT}, get_version_number, log, message_proto::*, diff --git a/src/flutter_ffi.rs b/src/flutter_ffi.rs index a0f94fdbd..3c9ce96b9 100644 --- a/src/flutter_ffi.rs +++ b/src/flutter_ffi.rs @@ -16,8 +16,6 @@ use hbb_common::{ // use crate::hbbs_http::account::AuthResult; use crate::flutter::{self, SESSIONS}; -#[cfg(target_os = "android")] -use crate::start_server; use crate::ui_interface::{self, *}; #[cfg(not(any(target_os = "android", target_os = "ios")))] use crate::ui_session_interface::CUR_SESSION; @@ -838,7 +836,12 @@ pub fn main_is_root() -> bool { } pub fn get_double_click_time() -> SyncReturn { - SyncReturn(crate::platform::get_double_click_time() as _) + #[cfg(not(any(target_os = "android", target_os = "ios")))] + { + return SyncReturn(crate::platform::get_double_click_time() as _); + } + #[cfg(any(target_os = "android", target_os = "ios"))] + SyncReturn(500i32) } pub fn main_start_dbus_server() { @@ -1133,7 +1136,7 @@ pub mod server_side { JNIEnv, }; - use hbb_common::{config::Config, log}; + use hbb_common::log; use crate::start_server; diff --git a/src/platform/mod.rs b/src/platform/mod.rs index 37164de31..f6b79da59 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -14,6 +14,7 @@ pub mod macos; #[cfg(target_os = "linux")] pub mod linux; +#[cfg(not(any(target_os = "android", target_os = "ios")))] use hbb_common::{message_proto::CursorData, ResultType}; #[cfg(not(target_os = "macos"))] const SERVICE_INTERVAL: u64 = 300; diff --git a/src/server.rs b/src/server.rs index 08b8c5b5b..6e549c9f4 100644 --- a/src/server.rs +++ b/src/server.rs @@ -5,7 +5,7 @@ use hbb_common::{ allow_err, anyhow::{anyhow, Context}, bail, - config::{Config, Config2, CONNECT_TIMEOUT, RELAY_PORT}, + config::{Config, CONNECT_TIMEOUT, RELAY_PORT}, log, message_proto::*, protobuf::{Enum, Message as _}, @@ -14,7 +14,11 @@ use hbb_common::{ sodiumoxide::crypto::{box_, secretbox, sign}, timeout, tokio, ResultType, Stream, }; -use service::{GenericService, Service, ServiceTmpl, Subscriber}; +#[cfg(not(any(target_os = "android", target_os = "ios")))] +use hbb_common::config::Config2; +#[cfg(not(any(target_os = "android", target_os = "ios")))] +use service::ServiceTmpl; +use service::{GenericService, Service, Subscriber}; use std::{ collections::HashMap, net::SocketAddr, diff --git a/src/server/connection.rs b/src/server/connection.rs index 96d202199..891c48888 100644 --- a/src/server/connection.rs +++ b/src/server/connection.rs @@ -27,10 +27,12 @@ use scrap::android::call_main_service_mouse_input; use serde_json::{json, value::Value}; use sha2::{Digest, Sha256}; use std::sync::{ - atomic::{AtomicI64, Ordering}, + atomic::AtomicI64, mpsc as std_mpsc, }; #[cfg(not(any(target_os = "android", target_os = "ios")))] +use std::sync::atomic::Ordering; +#[cfg(not(any(target_os = "android", target_os = "ios")))] use system_shutdown; pub type Sender = mpsc::UnboundedSender<(Instant, Arc)>; diff --git a/src/server/video_service.rs b/src/server/video_service.rs index 9696ef08d..81ab494e5 100644 --- a/src/server/video_service.rs +++ b/src/server/video_service.rs @@ -530,7 +530,7 @@ fn run(sp: GenericService) -> ResultType<()> { frame_controller.set_send(now, send_conn_ids); } scrap::Frame::RAW(data) => { - if (data.len() != 0) { + if data.len() != 0 { let send_conn_ids = handle_one_frame(&sp, data, ms, &mut encoder, recorder.clone())?; frame_controller.set_send(now, send_conn_ids); diff --git a/src/ui_cm_interface.rs b/src/ui_cm_interface.rs index 09e259fa2..72225b3fb 100644 --- a/src/ui_cm_interface.rs +++ b/src/ui_cm_interface.rs @@ -15,7 +15,7 @@ use std::iter::FromIterator; use clipboard::{cliprdr::CliprdrClientContext, empty_clipboard, set_conn_enabled, ContextSend}; use serde_derive::Serialize; -use crate::ipc::{self, new_listener, Connection, Data}; +use crate::ipc::{self, Connection, Data}; #[cfg(windows)] use hbb_common::tokio::sync::Mutex as TokioMutex; use hbb_common::{ @@ -434,7 +434,7 @@ pub async fn start_ipc(cm: ConnectionManager) { allow_err!(crate::ui::win_privacy::start()); }); - match new_listener("_cm").await { + match ipc::new_listener("_cm").await { Ok(mut incoming) => { while let Some(result) = incoming.next().await { match result { diff --git a/src/ui_interface.rs b/src/ui_interface.rs index 7d520662d..a334fb6fb 100644 --- a/src/ui_interface.rs +++ b/src/ui_interface.rs @@ -26,7 +26,7 @@ use hbb_common::{ #[cfg(feature = "flutter")] use crate::hbbs_http::account; -use crate::{common::SOFTWARE_UPDATE_URL, ipc, platform}; +use crate::{common::SOFTWARE_UPDATE_URL, ipc}; #[cfg(any(target_os = "android", target_os = "ios", feature = "flutter"))] type Message = RendezvousMessage; @@ -253,6 +253,7 @@ pub fn test_if_valid_server(host: String) -> String { #[inline] #[cfg(feature = "flutter")] +#[cfg(not(any(target_os = "android", target_os = "ios")))] pub fn get_sound_inputs() -> Vec { let mut a = Vec::new(); #[cfg(not(target_os = "linux"))] @@ -782,7 +783,7 @@ pub fn default_video_save_directory() -> String { } #[cfg(not(any(target_os = "android", target_os = "ios")))] - if let Some(home) = platform::get_active_user_home() { + if let Some(home) = crate::platform::get_active_user_home() { let name = if cfg!(target_os = "macos") { "Movies" } else { diff --git a/src/ui_session_interface.rs b/src/ui_session_interface.rs index ead60299a..4467fee00 100644 --- a/src/ui_session_interface.rs +++ b/src/ui_session_interface.rs @@ -1,10 +1,10 @@ #[cfg(not(any(target_os = "android", target_os = "ios")))] -use crate::client::get_key_state; +use crate::client::{get_key_state, SERVER_KEYBOARD_ENABLED}; use crate::client::io_loop::Remote; use crate::client::{ check_if_retry, handle_hash, handle_login_from_ui, handle_test_delay, input_os_password, load_config, send_mouse, start_video_audio_threads, FileManager, Key, LoginConfigHandler, - QualityStatus, KEY_MAP, SERVER_KEYBOARD_ENABLED, + QualityStatus, KEY_MAP, }; #[cfg(target_os = "linux")] use crate::common::IS_X11; @@ -16,8 +16,8 @@ use hbb_common::tokio::{self, sync::mpsc}; use hbb_common::{allow_err, message_proto::*}; use hbb_common::{fs, get_version_number, log, Stream}; #[cfg(not(any(target_os = "android", target_os = "ios")))] -use rdev::Keyboard as RdevKeyboard; -use rdev::{Event, EventType, EventType::*, Key as RdevKey, KeyboardState}; +use rdev::{Keyboard as RdevKeyboard, KeyboardState}; +use rdev::{Event, EventType, EventType::*, Key as RdevKey}; use std::collections::{HashMap, HashSet}; use std::ops::{Deref, DerefMut}; use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; @@ -30,6 +30,7 @@ pub static HOTKEY_HOOKED: AtomicBool = AtomicBool::new(false); #[cfg(windows)] static mut IS_ALT_GR: bool = false; #[cfg(feature = "flutter")] +#[cfg(not(any(target_os = "android", target_os = "ios")))] use crate::flutter::FlutterHandler; lazy_static::lazy_static! { @@ -1570,6 +1571,7 @@ fn get_all_hotkey_state( } #[cfg(feature = "flutter")] +#[cfg(not(any(target_os = "android", target_os = "ios")))] pub fn send_key_event_to_session(event: rdev::Event) { if let Some(handler) = CUR_SESSION.lock().unwrap().as_ref() { handler.handle_hotkey_event(event);