run android InputService independently

This commit is contained in:
csf
2022-06-01 21:14:02 +08:00
parent 6e1f4cfeca
commit 75b920079b
5 changed files with 17 additions and 44 deletions

View File

@@ -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?) {}

View File

@@ -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()
}