fix android build errors and warnings

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2022-11-13 18:11:13 +08:00
parent a9eb285425
commit 6b3c2f3beb
11 changed files with 65 additions and 45 deletions

View File

@ -8,7 +8,6 @@ use std::{
}; };
use anyhow::Result; use anyhow::Result;
use directories_next::ProjectDirs;
use rand::Rng; use rand::Rng;
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use sodiumoxide::crypto::sign; use sodiumoxide::crypto::sign;
@ -375,12 +374,15 @@ impl Config {
pub fn get_home() -> PathBuf { pub fn get_home() -> PathBuf {
#[cfg(any(target_os = "android", target_os = "ios"))] #[cfg(any(target_os = "android", target_os = "ios"))]
return Self::path(APP_HOME_DIR.read().unwrap().as_str()); return Self::path(APP_HOME_DIR.read().unwrap().as_str());
if let Some(path) = dirs_next::home_dir() { #[cfg(not(any(target_os = "android", target_os = "ios")))]
patch(path) {
} else if let Ok(path) = std::env::current_dir() { if let Some(path) = dirs_next::home_dir() {
path patch(path)
} else { } else if let Ok(path) = std::env::current_dir() {
std::env::temp_dir() path
} else {
std::env::temp_dir()
}
} }
} }
@ -391,17 +393,20 @@ impl Config {
path.push(p); path.push(p);
return path; return path;
} }
#[cfg(not(target_os = "macos"))] #[cfg(not(any(target_os = "android", target_os = "ios")))]
let org = ""; {
#[cfg(target_os = "macos")] #[cfg(not(target_os = "macos"))]
let org = ORG.read().unwrap().clone(); let org = "";
// /var/root for root #[cfg(target_os = "macos")]
if let Some(project) = ProjectDirs::from("", &org, &*APP_NAME.read().unwrap()) { let org = ORG.read().unwrap().clone();
let mut path = patch(project.config_dir().to_path_buf()); // /var/root for root
path.push(p); if let Some(project) = directories_next::ProjectDirs::from("", &org, &*APP_NAME.read().unwrap()) {
return path; let mut path = patch(project.config_dir().to_path_buf());
path.push(p);
return path;
}
return "".into();
} }
return "".into();
} }
#[allow(unreachable_code)] #[allow(unreachable_code)]
@ -580,16 +585,19 @@ impl Config {
.to_string(), .to_string(),
); );
} }
let mut id = 0u32;
#[cfg(not(any(target_os = "android", target_os = "ios")))] #[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..] { let mut id = 0u32;
id = (id << 8) | (*x as u32); 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
} }
} }

View File

@ -1,6 +1,3 @@
pub mod ffi; pub mod ffi;
use std::sync::RwLock;
pub use ffi::*; pub use ffi::*;
use lazy_static::lazy_static;

View File

@ -6,10 +6,12 @@ use std::{
#[cfg(not(any(target_os = "android", target_os = "ios")))] #[cfg(not(any(target_os = "android", target_os = "ios")))]
pub use arboard::Clipboard as ClipboardContext; pub use arboard::Clipboard as ClipboardContext;
#[cfg(not(any(target_os = "android", target_os = "ios")))]
use hbb_common::compress::decompress;
use hbb_common::{ use hbb_common::{
allow_err, allow_err,
anyhow::bail, anyhow::bail,
compress::{compress as compress_func, decompress}, compress::{compress as compress_func},
config::{self, Config, COMPRESS_LEVEL, RENDEZVOUS_TIMEOUT}, config::{self, Config, COMPRESS_LEVEL, RENDEZVOUS_TIMEOUT},
get_version_number, log, get_version_number, log,
message_proto::*, message_proto::*,

View File

@ -16,8 +16,6 @@ use hbb_common::{
// use crate::hbbs_http::account::AuthResult; // use crate::hbbs_http::account::AuthResult;
use crate::flutter::{self, SESSIONS}; use crate::flutter::{self, SESSIONS};
#[cfg(target_os = "android")]
use crate::start_server;
use crate::ui_interface::{self, *}; use crate::ui_interface::{self, *};
#[cfg(not(any(target_os = "android", target_os = "ios")))] #[cfg(not(any(target_os = "android", target_os = "ios")))]
use crate::ui_session_interface::CUR_SESSION; use crate::ui_session_interface::CUR_SESSION;
@ -838,7 +836,12 @@ pub fn main_is_root() -> bool {
} }
pub fn get_double_click_time() -> SyncReturn<i32> { pub fn get_double_click_time() -> SyncReturn<i32> {
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() { pub fn main_start_dbus_server() {
@ -1133,7 +1136,7 @@ pub mod server_side {
JNIEnv, JNIEnv,
}; };
use hbb_common::{config::Config, log}; use hbb_common::log;
use crate::start_server; use crate::start_server;

View File

@ -14,6 +14,7 @@ pub mod macos;
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
pub mod linux; pub mod linux;
#[cfg(not(any(target_os = "android", target_os = "ios")))]
use hbb_common::{message_proto::CursorData, ResultType}; use hbb_common::{message_proto::CursorData, ResultType};
#[cfg(not(target_os = "macos"))] #[cfg(not(target_os = "macos"))]
const SERVICE_INTERVAL: u64 = 300; const SERVICE_INTERVAL: u64 = 300;

View File

@ -5,7 +5,7 @@ use hbb_common::{
allow_err, allow_err,
anyhow::{anyhow, Context}, anyhow::{anyhow, Context},
bail, bail,
config::{Config, Config2, CONNECT_TIMEOUT, RELAY_PORT}, config::{Config, CONNECT_TIMEOUT, RELAY_PORT},
log, log,
message_proto::*, message_proto::*,
protobuf::{Enum, Message as _}, protobuf::{Enum, Message as _},
@ -14,7 +14,11 @@ use hbb_common::{
sodiumoxide::crypto::{box_, secretbox, sign}, sodiumoxide::crypto::{box_, secretbox, sign},
timeout, tokio, ResultType, Stream, 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::{ use std::{
collections::HashMap, collections::HashMap,
net::SocketAddr, net::SocketAddr,

View File

@ -27,10 +27,12 @@ use scrap::android::call_main_service_mouse_input;
use serde_json::{json, value::Value}; use serde_json::{json, value::Value};
use sha2::{Digest, Sha256}; use sha2::{Digest, Sha256};
use std::sync::{ use std::sync::{
atomic::{AtomicI64, Ordering}, atomic::AtomicI64,
mpsc as std_mpsc, mpsc as std_mpsc,
}; };
#[cfg(not(any(target_os = "android", target_os = "ios")))] #[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; use system_shutdown;
pub type Sender = mpsc::UnboundedSender<(Instant, Arc<Message>)>; pub type Sender = mpsc::UnboundedSender<(Instant, Arc<Message>)>;

View File

@ -530,7 +530,7 @@ fn run(sp: GenericService) -> ResultType<()> {
frame_controller.set_send(now, send_conn_ids); frame_controller.set_send(now, send_conn_ids);
} }
scrap::Frame::RAW(data) => { scrap::Frame::RAW(data) => {
if (data.len() != 0) { if data.len() != 0 {
let send_conn_ids = let send_conn_ids =
handle_one_frame(&sp, data, ms, &mut encoder, recorder.clone())?; handle_one_frame(&sp, data, ms, &mut encoder, recorder.clone())?;
frame_controller.set_send(now, send_conn_ids); frame_controller.set_send(now, send_conn_ids);

View File

@ -15,7 +15,7 @@ use std::iter::FromIterator;
use clipboard::{cliprdr::CliprdrClientContext, empty_clipboard, set_conn_enabled, ContextSend}; use clipboard::{cliprdr::CliprdrClientContext, empty_clipboard, set_conn_enabled, ContextSend};
use serde_derive::Serialize; use serde_derive::Serialize;
use crate::ipc::{self, new_listener, Connection, Data}; use crate::ipc::{self, Connection, Data};
#[cfg(windows)] #[cfg(windows)]
use hbb_common::tokio::sync::Mutex as TokioMutex; use hbb_common::tokio::sync::Mutex as TokioMutex;
use hbb_common::{ use hbb_common::{
@ -434,7 +434,7 @@ pub async fn start_ipc<T: InvokeUiCM>(cm: ConnectionManager<T>) {
allow_err!(crate::ui::win_privacy::start()); allow_err!(crate::ui::win_privacy::start());
}); });
match new_listener("_cm").await { match ipc::new_listener("_cm").await {
Ok(mut incoming) => { Ok(mut incoming) => {
while let Some(result) = incoming.next().await { while let Some(result) = incoming.next().await {
match result { match result {

View File

@ -26,7 +26,7 @@ use hbb_common::{
#[cfg(feature = "flutter")] #[cfg(feature = "flutter")]
use crate::hbbs_http::account; 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"))] #[cfg(any(target_os = "android", target_os = "ios", feature = "flutter"))]
type Message = RendezvousMessage; type Message = RendezvousMessage;
@ -253,6 +253,7 @@ pub fn test_if_valid_server(host: String) -> String {
#[inline] #[inline]
#[cfg(feature = "flutter")] #[cfg(feature = "flutter")]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn get_sound_inputs() -> Vec<String> { pub fn get_sound_inputs() -> Vec<String> {
let mut a = Vec::new(); let mut a = Vec::new();
#[cfg(not(target_os = "linux"))] #[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")))] #[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") { let name = if cfg!(target_os = "macos") {
"Movies" "Movies"
} else { } else {

View File

@ -1,10 +1,10 @@
#[cfg(not(any(target_os = "android", target_os = "ios")))] #[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::io_loop::Remote;
use crate::client::{ use crate::client::{
check_if_retry, handle_hash, handle_login_from_ui, handle_test_delay, input_os_password, 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, load_config, send_mouse, start_video_audio_threads, FileManager, Key, LoginConfigHandler,
QualityStatus, KEY_MAP, SERVER_KEYBOARD_ENABLED, QualityStatus, KEY_MAP,
}; };
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
use crate::common::IS_X11; 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::{allow_err, message_proto::*};
use hbb_common::{fs, get_version_number, log, Stream}; use hbb_common::{fs, get_version_number, log, Stream};
#[cfg(not(any(target_os = "android", target_os = "ios")))] #[cfg(not(any(target_os = "android", target_os = "ios")))]
use rdev::Keyboard as RdevKeyboard; use rdev::{Keyboard as RdevKeyboard, KeyboardState};
use rdev::{Event, EventType, EventType::*, Key as RdevKey, KeyboardState}; use rdev::{Event, EventType, EventType::*, Key as RdevKey};
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
@ -30,6 +30,7 @@ pub static HOTKEY_HOOKED: AtomicBool = AtomicBool::new(false);
#[cfg(windows)] #[cfg(windows)]
static mut IS_ALT_GR: bool = false; static mut IS_ALT_GR: bool = false;
#[cfg(feature = "flutter")] #[cfg(feature = "flutter")]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
use crate::flutter::FlutterHandler; use crate::flutter::FlutterHandler;
lazy_static::lazy_static! { lazy_static::lazy_static! {
@ -1570,6 +1571,7 @@ fn get_all_hotkey_state(
} }
#[cfg(feature = "flutter")] #[cfg(feature = "flutter")]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn send_key_event_to_session(event: rdev::Event) { pub fn send_key_event_to_session(event: rdev::Event) {
if let Some(handler) = CUR_SESSION.lock().unwrap().as_ref() { if let Some(handler) = CUR_SESSION.lock().unwrap().as_ref() {
handler.handle_hotkey_event(event); handler.handle_hotkey_event(event);