diff --git a/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/InputService.kt b/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/InputService.kt index e061037db..fa6a348c1 100644 --- a/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/InputService.kt +++ b/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/InputService.kt @@ -32,12 +32,6 @@ class InputService : AccessibilityService() { get() = ctx != null } - private external fun init(ctx: Context) - - init { - System.loadLibrary("rustdesk") - } - private val logTag = "input service" private var leftIsDown = false private var touchPath = Path() @@ -50,9 +44,8 @@ class InputService : AccessibilityService() { private val wheelActionsQueue = LinkedList() private var isWheelActionsPolling = false - @Keep @RequiresApi(Build.VERSION_CODES.N) - fun rustMouseInput(mask: Int, _x: Int, _y: Int) { + fun onMouseInput(mask: Int, _x: Int, _y: Int) { val x = if (_x < 0) { 0 } else { @@ -212,7 +205,11 @@ class InputService : AccessibilityService() { super.onServiceConnected() ctx = this Log.d(logTag, "onServiceConnected!") - init(this) + } + + override fun onDestroy() { + ctx = null + super.onDestroy() } override fun onAccessibilityEvent(event: AccessibilityEvent?) {} diff --git a/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/MainService.kt b/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/MainService.kt index 62376ae5f..dc86cea45 100644 --- a/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/MainService.kt +++ b/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/MainService.kt @@ -69,6 +69,12 @@ class MainService : Service() { System.loadLibrary("rustdesk") } + @Keep + @RequiresApi(Build.VERSION_CODES.N) + fun rustMouseInput(mask: Int, x: Int, y: Int) { + InputService.ctx?.onMouseInput(mask,x,y) + } + @Keep fun rustGetByName(name: String): String { return when (name) { @@ -197,10 +203,6 @@ class MainService : Service() { } override fun onDestroy() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - InputService.ctx?.disableSelf() - } - InputService.ctx = null checkMediaPermission() super.onDestroy() } @@ -389,10 +391,6 @@ class MainService : Service() { mediaProjection = null checkMediaPermission() - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - InputService.ctx?.disableSelf() - } - InputService.ctx = null stopForeground(true) stopSelf() } diff --git a/flutter/lib/models/server_model.dart b/flutter/lib/models/server_model.dart index f3a366cf1..1ecad67ef 100644 --- a/flutter/lib/models/server_model.dart +++ b/flutter/lib/models/server_model.dart @@ -49,7 +49,6 @@ class ServerModel with ChangeNotifier { * 2. check config * audio true by default (if permission on) (false default < Android 10) * file true by default (if permission on) - * input false by default (it need turning on manually everytime) */ await Future.delayed(Duration(seconds: 1)); @@ -79,11 +78,6 @@ class ServerModel with ChangeNotifier { _fileOk = fileOption.isEmpty; } - // input (mouse control) - Map res = Map() - ..["name"] = "enable-keyboard" - ..["value"] = 'N'; - FFI.setByName('option', jsonEncode(res)); // input false by default notifyListeners(); }(); diff --git a/libs/scrap/src/android/ffi.rs b/libs/scrap/src/android/ffi.rs index 7723d3ace..3515bab9f 100644 --- a/libs/scrap/src/android/ffi.rs +++ b/libs/scrap/src/android/ffi.rs @@ -17,7 +17,6 @@ use std::time::{Duration, Instant}; lazy_static! { static ref JVM: RwLock> = RwLock::new(None); static ref MAIN_SERVICE_CTX: RwLock> = RwLock::new(None); // MainService -> video service / audio service / info - static ref INPUT_CTX: RwLock> = RwLock::new(None); static ref VIDEO_RAW: Mutex = Mutex::new(FrameRaw::new("video", MAX_VIDEO_FRAME_TIMEOUT)); static ref AUDIO_RAW: Mutex = Mutex::new(FrameRaw::new("audio", MAX_AUDIO_FRAME_TIMEOUT)); } @@ -148,25 +147,10 @@ pub extern "system" fn Java_com_carriez_flutter_1hbb_MainService_init( *MAIN_SERVICE_CTX.write().unwrap() = Some(context); } -#[no_mangle] -pub extern "system" fn Java_com_carriez_flutter_1hbb_InputService_init( - env: JNIEnv, - _class: JClass, - ctx: JObject, -) { - log::debug!("InputService init from java"); - let jvm = env.get_java_vm().unwrap(); - - *JVM.write().unwrap() = Some(jvm); - - let context = env.new_global_ref(ctx).unwrap(); - *INPUT_CTX.write().unwrap() = Some(context); -} - -pub fn call_input_service_mouse_input(mask: i32, x: i32, y: i32) -> JniResult<()> { +pub fn call_main_service_mouse_input(mask: i32, x: i32, y: i32) -> JniResult<()> { if let (Some(jvm), Some(ctx)) = ( JVM.read().unwrap().as_ref(), - INPUT_CTX.read().unwrap().as_ref(), + MAIN_SERVICE_CTX.read().unwrap().as_ref(), ) { let env = jvm.attach_current_thread_as_daemon()?; env.call_method( diff --git a/src/server/connection.rs b/src/server/connection.rs index 3a026d924..baa67f84d 100644 --- a/src/server/connection.rs +++ b/src/server/connection.rs @@ -22,7 +22,7 @@ use hbb_common::{ tokio_util::codec::{BytesCodec, Framed}, }; #[cfg(any(target_os = "android", target_os = "ios"))] -use scrap::android::call_input_service_mouse_input; +use scrap::android::call_main_service_mouse_input; use serde_json::{json, value::Value}; use sha2::{Digest, Sha256}; use std::sync::{ @@ -895,8 +895,8 @@ impl Connection { match msg.union { Some(message::Union::mouse_event(me)) => { #[cfg(any(target_os = "android", target_os = "ios"))] - if let Err(e) = call_input_service_mouse_input(me.mask, me.x, me.y) { - log::debug!("call_input_service_mouse_input fail:{}", e); + if let Err(e) = call_main_service_mouse_input(me.mask, me.x, me.y) { + log::debug!("call_main_service_mouse_input fail:{}", e); } #[cfg(not(any(target_os = "android", target_os = "ios")))] if self.keyboard {