mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-01-19 16:33:01 +08:00
fix android input service
This commit is contained in:
parent
d054da3404
commit
62f5352263
@ -5,20 +5,24 @@ import android.accessibilityservice.GestureDescription
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Path
|
import android.graphics.Path
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Handler
|
|
||||||
import android.os.Looper
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.accessibility.AccessibilityEvent
|
import android.view.accessibility.AccessibilityEvent
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import kotlin.concurrent.thread
|
|
||||||
|
|
||||||
class InputService : AccessibilityService() {
|
class InputService : AccessibilityService() {
|
||||||
|
|
||||||
companion object{
|
companion object {
|
||||||
var ctx:InputService? = null
|
var ctx: InputService? = null
|
||||||
val isOpen: Boolean
|
val isOpen: Boolean
|
||||||
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 mPath = Path()
|
private var mPath = Path()
|
||||||
@ -28,10 +32,21 @@ class InputService : AccessibilityService() {
|
|||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.N)
|
@RequiresApi(Build.VERSION_CODES.N)
|
||||||
fun rustMouseInput(mask: Int, _x: Int, _y: Int) {
|
fun rustMouseInput(mask: Int, _x: Int, _y: Int) {
|
||||||
|
val x = if (_x < 0) {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
_x
|
||||||
|
}
|
||||||
|
|
||||||
|
val y = if (_y < 0) {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
_y
|
||||||
|
}
|
||||||
|
|
||||||
if (!(mask == 9 || mask == 10)) {
|
if (!(mask == 9 || mask == 10)) {
|
||||||
mouseX = _x * INFO.scale
|
mouseX = x * INFO.scale
|
||||||
mouseY = _y * INFO.scale
|
mouseY = y * INFO.scale
|
||||||
}
|
}
|
||||||
|
|
||||||
// left button down ,was up
|
// left button down ,was up
|
||||||
@ -41,7 +56,7 @@ class InputService : AccessibilityService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// left down ,was down
|
// left down ,was down
|
||||||
if (mask == 9) {
|
if (leftIsDown) {
|
||||||
continueGesture(mouseX, mouseY)
|
continueGesture(mouseX, mouseY)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,30 +79,24 @@ class InputService : AccessibilityService() {
|
|||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.N)
|
@RequiresApi(Build.VERSION_CODES.N)
|
||||||
private fun endGesture(x: Int, y: Int) {
|
private fun endGesture(x: Int, y: Int) {
|
||||||
mPath.lineTo(x.toFloat(), y.toFloat())
|
try {
|
||||||
val stroke = GestureDescription.StrokeDescription(
|
mPath.lineTo(x.toFloat(), y.toFloat())
|
||||||
mPath,
|
var duration = System.currentTimeMillis() - mLastGestureStartTime
|
||||||
0,
|
if (duration <= 0) {
|
||||||
System.currentTimeMillis() - mLastGestureStartTime
|
duration = 1
|
||||||
)
|
|
||||||
val builder = GestureDescription.Builder()
|
|
||||||
builder.addStroke(stroke)
|
|
||||||
Log.d(logTag, "end gesture $x $y")
|
|
||||||
dispatchGesture(builder.build(), object : GestureResultCallback() {
|
|
||||||
override fun onCompleted(gestureDescription: GestureDescription) {
|
|
||||||
super.onCompleted(gestureDescription)
|
|
||||||
}
|
}
|
||||||
|
val stroke = GestureDescription.StrokeDescription(
|
||||||
override fun onCancelled(gestureDescription: GestureDescription) {
|
mPath,
|
||||||
super.onCancelled(gestureDescription)
|
0,
|
||||||
}
|
duration
|
||||||
}, null)
|
)
|
||||||
}
|
val builder = GestureDescription.Builder()
|
||||||
|
builder.addStroke(stroke)
|
||||||
private external fun init(ctx: Context)
|
Log.d(logTag, "end gesture x:$x y:$y time:$duration")
|
||||||
|
dispatchGesture(builder.build(), null, null)
|
||||||
init {
|
} catch (e: Exception) {
|
||||||
System.loadLibrary("rustdesk")
|
Log.e(logTag, "endGesture error:$e")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.O)
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
|
@ -82,10 +82,7 @@ class ServerModel with ChangeNotifier {
|
|||||||
|
|
||||||
toggleAudio() async {
|
toggleAudio() async {
|
||||||
if(!_audioOk && !await PermissionManager.check("audio")){
|
if(!_audioOk && !await PermissionManager.check("audio")){
|
||||||
debugPrint("toggleAudio 无权限 开始获取权限");
|
|
||||||
final res = await PermissionManager.request("audio");
|
final res = await PermissionManager.request("audio");
|
||||||
debugPrint("权限请求结果:$res");
|
|
||||||
|
|
||||||
if(!res){
|
if(!res){
|
||||||
// TODO handle fail
|
// TODO handle fail
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user