update android
This commit is contained in:
parent
6ca487e3e0
commit
2e73f29ce9
@ -11,9 +11,7 @@ import androidx.annotation.RequiresApi
|
|||||||
import kotlin.concurrent.thread
|
import kotlin.concurrent.thread
|
||||||
|
|
||||||
class InputService : AccessibilityService() {
|
class InputService : AccessibilityService() {
|
||||||
// companion object {
|
|
||||||
// var inputService:InputService? = null
|
|
||||||
// }
|
|
||||||
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()
|
||||||
@ -22,14 +20,14 @@ class InputService : AccessibilityService() {
|
|||||||
private var mouseY = 0
|
private var mouseY = 0
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.N)
|
@RequiresApi(Build.VERSION_CODES.N)
|
||||||
fun mouseInput(mask: Int, _x: Int, _y: Int) {
|
fun rustMouseInput(mask: Int, _x: Int, _y: Int) {
|
||||||
Log.w(logTag, "got mouse input:x:$_x ,y:$_y ,mask:$mask ")
|
Log.w(logTag, "got mouse input:x:$_x ,y:$_y ,mask:$mask ")
|
||||||
|
|
||||||
// TODO 临时倍数
|
// TODO 临时倍数
|
||||||
// TODO 按键抬起按下时候 x y 都是0
|
// TODO 按键抬起按下时候 x y 都是0
|
||||||
if ( !(mask == 9 || mask == 10) ) {
|
if ( !(mask == 9 || mask == 10) ) {
|
||||||
mouseX = _x * 2
|
mouseX = _x * SCALE
|
||||||
mouseY = _y * 2
|
mouseY = _y * SCALE
|
||||||
}
|
}
|
||||||
|
|
||||||
// left button down ,was up
|
// left button down ,was up
|
||||||
|
@ -2,36 +2,34 @@ package com.carriez.flutter_hbb
|
|||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.app.AlertDialog
|
import android.app.AlertDialog
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.media.projection.MediaProjectionManager
|
import android.media.projection.MediaProjectionManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
|
||||||
import android.os.PersistableBundle
|
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
|
import android.util.DisplayMetrics
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import io.flutter.embedding.android.FlutterActivity
|
import io.flutter.embedding.android.FlutterActivity
|
||||||
import io.flutter.embedding.engine.FlutterEngine
|
import io.flutter.embedding.engine.FlutterEngine
|
||||||
import io.flutter.plugin.common.MethodCall
|
|
||||||
import io.flutter.plugin.common.MethodChannel
|
import io.flutter.plugin.common.MethodChannel
|
||||||
import java.nio.ByteBuffer
|
|
||||||
import kotlin.concurrent.thread
|
|
||||||
|
|
||||||
|
const val MAX_SIZE = 1400
|
||||||
|
|
||||||
class MainActivity : FlutterActivity() {
|
class MainActivity : FlutterActivity() {
|
||||||
private val channelTag = "mChannel"
|
private val channelTag = "mChannel"
|
||||||
|
private val logTag = "mMainActivity"
|
||||||
private var mediaProjectionResultIntent: Intent? = null
|
private var mediaProjectionResultIntent: Intent? = null
|
||||||
private val requestCode = 1
|
private val requestCode = 1
|
||||||
private val buf = ByteBuffer.allocate(16)
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
System.loadLibrary("rustdesk")
|
System.loadLibrary("rustdesk")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
external fun rustSetInfo(username: String, hostname: String, width: Int, height: Int)
|
||||||
|
|
||||||
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
||||||
super.configureFlutterEngine(flutterEngine) // 必要 否则无法正确初始化flutter
|
super.configureFlutterEngine(flutterEngine) // 必要 否则无法正确初始化flutter
|
||||||
|
updateMachineInfo()
|
||||||
MethodChannel(
|
MethodChannel(
|
||||||
flutterEngine.dartExecutor.binaryMessenger,
|
flutterEngine.dartExecutor.binaryMessenger,
|
||||||
channelTag
|
channelTag
|
||||||
@ -52,7 +50,7 @@ class MainActivity : FlutterActivity() {
|
|||||||
mStopService()
|
mStopService()
|
||||||
result.success(true)
|
result.success(true)
|
||||||
}
|
}
|
||||||
"checkInput" ->{
|
"checkInput" -> {
|
||||||
checkInput()
|
checkInput()
|
||||||
result.success(true)
|
result.success(true)
|
||||||
}
|
}
|
||||||
@ -128,4 +126,40 @@ class MainActivity : FlutterActivity() {
|
|||||||
mediaProjectionResultIntent = data
|
mediaProjectionResultIntent = data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateMachineInfo() {
|
||||||
|
// 屏幕尺寸 控制最长边不超过1400 超过则减半直到1400 并储存缩放比例 实际发送给手机端的尺寸为缩小后的尺寸
|
||||||
|
// input控制时再通过缩放比例恢复原始尺寸进行path入参
|
||||||
|
val dm = DisplayMetrics()
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
|
display?.getRealMetrics(dm)
|
||||||
|
} else {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
windowManager.defaultDisplay.getRealMetrics(dm)
|
||||||
|
} else {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
windowManager.defaultDisplay.getMetrics(dm)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var w = dm.widthPixels
|
||||||
|
var h = dm.heightPixels
|
||||||
|
var scale = 1
|
||||||
|
if (w != 0 && h != 0) {
|
||||||
|
if (w > MAX_SIZE || h > MAX_SIZE) {
|
||||||
|
scale = 2
|
||||||
|
w /= scale
|
||||||
|
h /= scale
|
||||||
|
}
|
||||||
|
Log.d(logTag, "Real size - width:$w,height:$h")
|
||||||
|
|
||||||
|
FIXED_WIDTH = 540
|
||||||
|
FIXED_HEIGHT = 1140
|
||||||
|
SCALE = scale
|
||||||
|
// TODO username hostname
|
||||||
|
rustSetInfo("csf", "Android", FIXED_WIDTH, FIXED_HEIGHT)
|
||||||
|
} else {
|
||||||
|
Log.e(logTag, "Got Screen Size Fail!")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,10 @@ import android.media.projection.MediaProjection
|
|||||||
import android.media.projection.MediaProjectionManager
|
import android.media.projection.MediaProjectionManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
|
import android.util.DisplayMetrics
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.Surface
|
import android.view.Surface
|
||||||
|
import android.view.WindowManager
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
@ -26,9 +28,9 @@ const val START_SERVICE = "start_service"
|
|||||||
const val STOP_SERVICE = "stop_service"
|
const val STOP_SERVICE = "stop_service"
|
||||||
const val MIME_TYPE = MediaFormat.MIMETYPE_VIDEO_VP9
|
const val MIME_TYPE = MediaFormat.MIMETYPE_VIDEO_VP9
|
||||||
|
|
||||||
// 获取手机尺寸 建立连接时发送尺寸和基础信息
|
var FIXED_WIDTH = 0 // 编码器有上限
|
||||||
const val FIXED_WIDTH = 500 // 编码器有上限
|
var FIXED_HEIGHT = 0
|
||||||
const val FIXED_HEIGHT = 1000
|
var SCALE = 1 // RealScreenWidth = screenWidth * scale
|
||||||
const val M_KEY_BIT_RATE = 1024_000
|
const val M_KEY_BIT_RATE = 1024_000
|
||||||
const val M_KEY_FRAME_RATE = 30
|
const val M_KEY_FRAME_RATE = 30
|
||||||
|
|
||||||
|
@ -139,6 +139,8 @@ pub unsafe extern "system" fn Java_com_carriez_flutter_1hbb_MainActivity_init(
|
|||||||
```
|
```
|
||||||
- 注意,原项目包名flutter_hbb 带有下划线,通过安卓的编译提示获得的命名方式为如上。
|
- 注意,原项目包名flutter_hbb 带有下划线,通过安卓的编译提示获得的命名方式为如上。
|
||||||
|
|
||||||
|
- 使用jni的时候会出现无输出崩溃的情况
|
||||||
|
|
||||||
- 将安卓的对象实例(Context)在init的过程中传入rust端,
|
- 将安卓的对象实例(Context)在init的过程中传入rust端,
|
||||||
context通过env.new_global_ref()变成全局引用
|
context通过env.new_global_ref()变成全局引用
|
||||||
env.get_java_vm()获取到jvm
|
env.get_java_vm()获取到jvm
|
||||||
@ -158,3 +160,14 @@ Kotlin 中的 ByteArray 类 会在JVM中编译成为java的byte[]
|
|||||||
byte[]通过jni传递到rust端时
|
byte[]通过jni传递到rust端时
|
||||||
通过jni.rs的方法
|
通过jni.rs的方法
|
||||||
env.convert_byte_array()即可转化为Vec<u8>
|
env.convert_byte_array()即可转化为Vec<u8>
|
||||||
|
|
||||||
|
- 关于 sig
|
||||||
|
- (I)V : 输入为Int 输出为Void
|
||||||
|
- (I)Ljava/nio/ByteBuffer : 输入为Int 输出为ByteBuffer 对应jni JByteBuffer 且env 有对应解析方法
|
||||||
|
- ()[B : 输入为空 输出为byte[](java) == ByteArray(kotlin) == jbytearray(jni env 中有对应解析方法到Vec\<u8\>)
|
||||||
|
- 使用JValue枚举定义java变量
|
||||||
|
|
||||||
|
# BIG TODO
|
||||||
|
音频
|
||||||
|
连续输入
|
||||||
|
服务关闭操作
|
@ -180,7 +180,7 @@ class PermissionRow extends StatelessWidget {
|
|||||||
TextSpan(
|
TextSpan(
|
||||||
text: isOk ? "已开启" : "未开启",
|
text: isOk ? "已开启" : "未开启",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 16.0, color: isOk ? Colors.green : Colors.red)),
|
fontSize: 16.0, color: isOk ? Colors.green : Colors.grey)),
|
||||||
])),
|
])),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: onPressed,
|
onPressed: onPressed,
|
||||||
@ -202,7 +202,7 @@ Widget cardTitle(String text) {
|
|||||||
fontFamily: 'WorkSans',
|
fontFamily: 'WorkSans',
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
fontSize: 25,
|
fontSize: 25,
|
||||||
color: Color(0xFF00B6F0),
|
color: MyTheme.accent80,
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user