Merge pull request #678 from Heap-Hop/master
Run Android InputService independently
This commit is contained in:
		
						commit
						cd78f76aff
					
				| @ -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<GestureDescription>() | ||||
|     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?) {} | ||||
|  | ||||
| @ -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() | ||||
|     } | ||||
|  | ||||
| @ -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<String, String> res = Map() | ||||
|         ..["name"] = "enable-keyboard" | ||||
|         ..["value"] = 'N'; | ||||
|       FFI.setByName('option', jsonEncode(res)); // input false by default | ||||
|       notifyListeners(); | ||||
|     }(); | ||||
| 
 | ||||
|  | ||||
| @ -17,7 +17,6 @@ use std::time::{Duration, Instant}; | ||||
| lazy_static! { | ||||
|     static ref JVM: RwLock<Option<JavaVM>> = RwLock::new(None); | ||||
|     static ref MAIN_SERVICE_CTX: RwLock<Option<GlobalRef>> = RwLock::new(None); // MainService -> video service / audio service / info
 | ||||
|     static ref INPUT_CTX: RwLock<Option<GlobalRef>> = RwLock::new(None); | ||||
|     static ref VIDEO_RAW: Mutex<FrameRaw> = Mutex::new(FrameRaw::new("video", MAX_VIDEO_FRAME_TIMEOUT)); | ||||
|     static ref AUDIO_RAW: Mutex<FrameRaw> = 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( | ||||
|  | ||||
| @ -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 { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user