run android InputService independently
This commit is contained in:
parent
6e1f4cfeca
commit
75b920079b
@ -32,12 +32,6 @@ class InputService : AccessibilityService() {
|
|||||||
get() = ctx != null
|
get() = ctx != null
|
||||||
}
|
}
|
||||||
|
|
||||||
private external fun init(ctx: Context)
|
|
||||||
|
|
||||||
init {
|
|
||||||
System.loadLibrary("rustdesk")
|
|
||||||
}
|
|
||||||
|
|
||||||
private val logTag = "input service"
|
private val logTag = "input service"
|
||||||
private var leftIsDown = false
|
private var leftIsDown = false
|
||||||
private var touchPath = Path()
|
private var touchPath = Path()
|
||||||
@ -50,9 +44,8 @@ class InputService : AccessibilityService() {
|
|||||||
private val wheelActionsQueue = LinkedList<GestureDescription>()
|
private val wheelActionsQueue = LinkedList<GestureDescription>()
|
||||||
private var isWheelActionsPolling = false
|
private var isWheelActionsPolling = false
|
||||||
|
|
||||||
@Keep
|
|
||||||
@RequiresApi(Build.VERSION_CODES.N)
|
@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) {
|
val x = if (_x < 0) {
|
||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
@ -212,7 +205,11 @@ class InputService : AccessibilityService() {
|
|||||||
super.onServiceConnected()
|
super.onServiceConnected()
|
||||||
ctx = this
|
ctx = this
|
||||||
Log.d(logTag, "onServiceConnected!")
|
Log.d(logTag, "onServiceConnected!")
|
||||||
init(this)
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
ctx = null
|
||||||
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onAccessibilityEvent(event: AccessibilityEvent?) {}
|
override fun onAccessibilityEvent(event: AccessibilityEvent?) {}
|
||||||
|
@ -69,6 +69,12 @@ class MainService : Service() {
|
|||||||
System.loadLibrary("rustdesk")
|
System.loadLibrary("rustdesk")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Keep
|
||||||
|
@RequiresApi(Build.VERSION_CODES.N)
|
||||||
|
fun rustMouseInput(mask: Int, x: Int, y: Int) {
|
||||||
|
InputService.ctx?.onMouseInput(mask,x,y)
|
||||||
|
}
|
||||||
|
|
||||||
@Keep
|
@Keep
|
||||||
fun rustGetByName(name: String): String {
|
fun rustGetByName(name: String): String {
|
||||||
return when (name) {
|
return when (name) {
|
||||||
@ -197,10 +203,6 @@ class MainService : Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
||||||
InputService.ctx?.disableSelf()
|
|
||||||
}
|
|
||||||
InputService.ctx = null
|
|
||||||
checkMediaPermission()
|
checkMediaPermission()
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
@ -389,10 +391,6 @@ class MainService : Service() {
|
|||||||
|
|
||||||
mediaProjection = null
|
mediaProjection = null
|
||||||
checkMediaPermission()
|
checkMediaPermission()
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
||||||
InputService.ctx?.disableSelf()
|
|
||||||
}
|
|
||||||
InputService.ctx = null
|
|
||||||
stopForeground(true)
|
stopForeground(true)
|
||||||
stopSelf()
|
stopSelf()
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,6 @@ class ServerModel with ChangeNotifier {
|
|||||||
* 2. check config
|
* 2. check config
|
||||||
* audio true by default (if permission on) (false default < Android 10)
|
* audio true by default (if permission on) (false default < Android 10)
|
||||||
* file true by default (if permission on)
|
* file true by default (if permission on)
|
||||||
* input false by default (it need turning on manually everytime)
|
|
||||||
*/
|
*/
|
||||||
await Future.delayed(Duration(seconds: 1));
|
await Future.delayed(Duration(seconds: 1));
|
||||||
|
|
||||||
@ -79,11 +78,6 @@ class ServerModel with ChangeNotifier {
|
|||||||
_fileOk = fileOption.isEmpty;
|
_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();
|
notifyListeners();
|
||||||
}();
|
}();
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ use std::time::{Duration, Instant};
|
|||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref JVM: RwLock<Option<JavaVM>> = RwLock::new(None);
|
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 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 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));
|
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);
|
*MAIN_SERVICE_CTX.write().unwrap() = Some(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
pub fn call_main_service_mouse_input(mask: i32, x: i32, y: i32) -> JniResult<()> {
|
||||||
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<()> {
|
|
||||||
if let (Some(jvm), Some(ctx)) = (
|
if let (Some(jvm), Some(ctx)) = (
|
||||||
JVM.read().unwrap().as_ref(),
|
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()?;
|
let env = jvm.attach_current_thread_as_daemon()?;
|
||||||
env.call_method(
|
env.call_method(
|
||||||
|
@ -22,7 +22,7 @@ use hbb_common::{
|
|||||||
tokio_util::codec::{BytesCodec, Framed},
|
tokio_util::codec::{BytesCodec, Framed},
|
||||||
};
|
};
|
||||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
#[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 serde_json::{json, value::Value};
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
use std::sync::{
|
use std::sync::{
|
||||||
@ -895,8 +895,8 @@ impl Connection {
|
|||||||
match msg.union {
|
match msg.union {
|
||||||
Some(message::Union::mouse_event(me)) => {
|
Some(message::Union::mouse_event(me)) => {
|
||||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||||
if let Err(e) = call_input_service_mouse_input(me.mask, me.x, me.y) {
|
if let Err(e) = call_main_service_mouse_input(me.mask, me.x, me.y) {
|
||||||
log::debug!("call_input_service_mouse_input fail:{}", e);
|
log::debug!("call_main_service_mouse_input fail:{}", e);
|
||||||
}
|
}
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
if self.keyboard {
|
if self.keyboard {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user