Merge branch 'master' of github.com-flutter_hbb:open-trade/flutter_hbb
This commit is contained in:
commit
a2f0a54110
@ -47,14 +47,15 @@ class InputService : AccessibilityService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!(mask == 9 || mask == 10)) {
|
if (!(mask == 9 || mask == 10)) {
|
||||||
mouseX = x * INFO.scale
|
mouseX = x * SCREEN_INFO.scale
|
||||||
mouseY = y * INFO.scale
|
mouseY = y * SCREEN_INFO.scale
|
||||||
}
|
}
|
||||||
|
|
||||||
// left button down ,was up
|
// left button down ,was up
|
||||||
if (mask == 9) {
|
if (mask == 9) {
|
||||||
leftIsDown = true
|
leftIsDown = true
|
||||||
startGesture(mouseX, mouseY)
|
startGesture(mouseX, mouseY)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// left down ,was down
|
// left down ,was down
|
||||||
@ -66,6 +67,17 @@ class InputService : AccessibilityService() {
|
|||||||
if (mask == 10) {
|
if (mask == 10) {
|
||||||
leftIsDown = false
|
leftIsDown = false
|
||||||
endGesture(mouseX, mouseY)
|
endGesture(mouseX, mouseY)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mask == 18) {
|
||||||
|
performGlobalAction(GLOBAL_ACTION_BACK)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mask == 34) {
|
||||||
|
performGlobalAction(GLOBAL_ACTION_HOME)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ import android.media.projection.MediaProjectionManager
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
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
|
||||||
@ -31,7 +30,6 @@ class MainActivity : FlutterActivity() {
|
|||||||
@RequiresApi(Build.VERSION_CODES.M)
|
@RequiresApi(Build.VERSION_CODES.M)
|
||||||
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
||||||
super.configureFlutterEngine(flutterEngine)
|
super.configureFlutterEngine(flutterEngine)
|
||||||
updateMachineInfo()
|
|
||||||
flutterMethodChannel = MethodChannel(
|
flutterMethodChannel = MethodChannel(
|
||||||
flutterEngine.dartExecutor.binaryMessenger,
|
flutterEngine.dartExecutor.binaryMessenger,
|
||||||
channelTag
|
channelTag
|
||||||
@ -190,37 +188,6 @@ class MainActivity : FlutterActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateMachineInfo() {
|
|
||||||
val dm = DisplayMetrics()
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
||||||
display?.getRealMetrics(dm)
|
|
||||||
} else {
|
|
||||||
windowManager.defaultDisplay.getRealMetrics(dm)
|
|
||||||
}
|
|
||||||
var w = dm.widthPixels
|
|
||||||
var h = dm.heightPixels
|
|
||||||
var scale = 1
|
|
||||||
if (w != 0 && h != 0) {
|
|
||||||
if (w > MAX_SCREEN_SIZE || h > MAX_SCREEN_SIZE) {
|
|
||||||
scale = 2
|
|
||||||
w /= scale
|
|
||||||
h /= scale
|
|
||||||
}
|
|
||||||
|
|
||||||
INFO.screenWidth = w
|
|
||||||
INFO.screenHeight = h
|
|
||||||
INFO.scale = scale
|
|
||||||
INFO.username = "test"
|
|
||||||
INFO.hostname = "hostname"
|
|
||||||
// TODO username hostname
|
|
||||||
Log.d(logTag, "INIT INFO:$INFO")
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.e(logTag, "Got Screen Size Fail!")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
Log.e(logTag, "onDestroy")
|
Log.e(logTag, "onDestroy")
|
||||||
mainService?.let {
|
mainService?.let {
|
||||||
|
@ -12,6 +12,7 @@ import android.app.PendingIntent.FLAG_UPDATE_CURRENT
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
|
import android.content.res.Configuration
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.graphics.PixelFormat
|
import android.graphics.PixelFormat
|
||||||
import android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC
|
import android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC
|
||||||
@ -20,9 +21,11 @@ import android.media.*
|
|||||||
import android.media.projection.MediaProjection
|
import android.media.projection.MediaProjection
|
||||||
import android.media.projection.MediaProjectionManager
|
import android.media.projection.MediaProjectionManager
|
||||||
import android.os.*
|
import android.os.*
|
||||||
|
import android.util.DisplayMetrics
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.Surface
|
import android.view.Surface
|
||||||
import android.view.Surface.FRAME_RATE_COMPATIBILITY_DEFAULT
|
import android.view.Surface.FRAME_RATE_COMPATIBILITY_DEFAULT
|
||||||
|
import android.view.WindowManager
|
||||||
import androidx.annotation.Keep
|
import androidx.annotation.Keep
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.core.app.ActivityCompat
|
import androidx.core.app.ActivityCompat
|
||||||
@ -68,7 +71,7 @@ class MainService : Service() {
|
|||||||
@Keep
|
@Keep
|
||||||
fun rustGetByName(name: String): String {
|
fun rustGetByName(name: String): String {
|
||||||
return when (name) {
|
return when (name) {
|
||||||
"screen_size" -> "${INFO.screenWidth}:${INFO.screenHeight}"
|
"screen_size" -> "${SCREEN_INFO.width}:${SCREEN_INFO.height}"
|
||||||
else -> ""
|
else -> ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -127,8 +130,10 @@ class MainService : Service() {
|
|||||||
private external fun init(ctx: Context)
|
private external fun init(ctx: Context)
|
||||||
private external fun startServer()
|
private external fun startServer()
|
||||||
private external fun onVideoFrameUpdate(buf: ByteBuffer)
|
private external fun onVideoFrameUpdate(buf: ByteBuffer)
|
||||||
|
private external fun releaseVideoFrame()
|
||||||
private external fun onAudioFrameUpdate(buf: ByteBuffer)
|
private external fun onAudioFrameUpdate(buf: ByteBuffer)
|
||||||
private external fun translateLocale(localeName: String, input: String): String
|
private external fun translateLocale(localeName: String, input: String): String
|
||||||
|
private external fun refreshScreen()
|
||||||
// private external fun sendVp9(data: ByteArray)
|
// private external fun sendVp9(data: ByteArray)
|
||||||
|
|
||||||
private fun translate(input: String): String {
|
private fun translate(input: String): String {
|
||||||
@ -167,10 +172,50 @@ class MainService : Service() {
|
|||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
updateScreenInfo()
|
||||||
initNotification()
|
initNotification()
|
||||||
startServer()
|
startServer()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateScreenInfo() {
|
||||||
|
var w: Int
|
||||||
|
var h: Int
|
||||||
|
val windowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
|
val m = windowManager.maximumWindowMetrics
|
||||||
|
w = m.bounds.width()
|
||||||
|
h = m.bounds.height()
|
||||||
|
} else {
|
||||||
|
val dm = DisplayMetrics()
|
||||||
|
windowManager.defaultDisplay.getRealMetrics(dm)
|
||||||
|
w = dm.widthPixels
|
||||||
|
h = dm.heightPixels
|
||||||
|
}
|
||||||
|
|
||||||
|
var scale = 1
|
||||||
|
if (w != 0 && h != 0) {
|
||||||
|
if (w > MAX_SCREEN_SIZE || h > MAX_SCREEN_SIZE) {
|
||||||
|
scale = 2
|
||||||
|
w /= scale
|
||||||
|
h /= scale
|
||||||
|
}
|
||||||
|
if (SCREEN_INFO.width != w) {
|
||||||
|
SCREEN_INFO.width = w
|
||||||
|
SCREEN_INFO.height = h
|
||||||
|
SCREEN_INFO.scale = scale
|
||||||
|
if (isStart) {
|
||||||
|
stopCapture()
|
||||||
|
refreshScreen()
|
||||||
|
startCapture()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onBind(intent: Intent): IBinder {
|
override fun onBind(intent: Intent): IBinder {
|
||||||
Log.d(logTag, "service onBind")
|
Log.d(logTag, "service onBind")
|
||||||
return binder
|
return binder
|
||||||
@ -195,7 +240,6 @@ class MainService : Service() {
|
|||||||
mediaProjection =
|
mediaProjection =
|
||||||
mMediaProjectionManager.getMediaProjection(Activity.RESULT_OK, it)
|
mMediaProjectionManager.getMediaProjection(Activity.RESULT_OK, it)
|
||||||
checkMediaPermission()
|
checkMediaPermission()
|
||||||
surface = createSurface()
|
|
||||||
init(this)
|
init(this)
|
||||||
_isReady = true
|
_isReady = true
|
||||||
} ?: let {
|
} ?: let {
|
||||||
@ -206,17 +250,22 @@ class MainService : Service() {
|
|||||||
return super.onStartCommand(intent, flags, startId)
|
return super.onStartCommand(intent, flags, startId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||||
|
super.onConfigurationChanged(newConfig)
|
||||||
|
updateScreenInfo()
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressLint("WrongConstant")
|
@SuppressLint("WrongConstant")
|
||||||
private fun createSurface(): Surface? {
|
private fun createSurface(): Surface? {
|
||||||
return if (useVP9) {
|
return if (useVP9) {
|
||||||
// TODO
|
// TODO
|
||||||
null
|
null
|
||||||
} else {
|
} else {
|
||||||
Log.d(logTag, "ImageReader.newInstance:INFO:$INFO")
|
Log.d(logTag, "ImageReader.newInstance:INFO:$SCREEN_INFO")
|
||||||
imageReader =
|
imageReader =
|
||||||
ImageReader.newInstance(
|
ImageReader.newInstance(
|
||||||
INFO.screenWidth,
|
SCREEN_INFO.width,
|
||||||
INFO.screenHeight,
|
SCREEN_INFO.height,
|
||||||
PixelFormat.RGBA_8888,
|
PixelFormat.RGBA_8888,
|
||||||
4
|
4
|
||||||
).apply {
|
).apply {
|
||||||
@ -247,6 +296,7 @@ class MainService : Service() {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
Log.d(logTag, "Start Capture")
|
Log.d(logTag, "Start Capture")
|
||||||
|
surface = createSurface()
|
||||||
|
|
||||||
if (useVP9) {
|
if (useVP9) {
|
||||||
startVP9VideoRecorder(mediaProjection!!)
|
startVP9VideoRecorder(mediaProjection!!)
|
||||||
@ -266,6 +316,9 @@ class MainService : Service() {
|
|||||||
Log.d(logTag, "Stop Capture")
|
Log.d(logTag, "Stop Capture")
|
||||||
_isStart = false
|
_isStart = false
|
||||||
// release video
|
// release video
|
||||||
|
imageReader?.close()
|
||||||
|
releaseVideoFrame()
|
||||||
|
surface?.release()
|
||||||
virtualDisplay?.release()
|
virtualDisplay?.release()
|
||||||
videoEncoder?.let {
|
videoEncoder?.let {
|
||||||
it.signalEndOfInputStream()
|
it.signalEndOfInputStream()
|
||||||
@ -309,14 +362,14 @@ class MainService : Service() {
|
|||||||
|
|
||||||
@SuppressLint("WrongConstant")
|
@SuppressLint("WrongConstant")
|
||||||
private fun startRawVideoRecorder(mp: MediaProjection) {
|
private fun startRawVideoRecorder(mp: MediaProjection) {
|
||||||
Log.d(logTag, "startRawVideoRecorder,screen info:$INFO")
|
Log.d(logTag, "startRawVideoRecorder,screen info:$SCREEN_INFO")
|
||||||
if (surface == null) {
|
if (surface == null) {
|
||||||
Log.d(logTag, "startRawVideoRecorder failed,surface is null")
|
Log.d(logTag, "startRawVideoRecorder failed,surface is null")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
virtualDisplay = mp.createVirtualDisplay(
|
virtualDisplay = mp.createVirtualDisplay(
|
||||||
"RustDesk",
|
"RustDesk",
|
||||||
INFO.screenWidth, INFO.screenHeight, 200, VIRTUAL_DISPLAY_FLAG_PUBLIC,
|
SCREEN_INFO.width, SCREEN_INFO.height, 200, VIRTUAL_DISPLAY_FLAG_PUBLIC,
|
||||||
surface, null, null
|
surface, null, null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -333,7 +386,7 @@ class MainService : Service() {
|
|||||||
it.start()
|
it.start()
|
||||||
virtualDisplay = mp.createVirtualDisplay(
|
virtualDisplay = mp.createVirtualDisplay(
|
||||||
"RustDeskVD",
|
"RustDeskVD",
|
||||||
INFO.screenWidth, INFO.screenHeight, 200, VIRTUAL_DISPLAY_FLAG_PUBLIC,
|
SCREEN_INFO.width, SCREEN_INFO.height, 200, VIRTUAL_DISPLAY_FLAG_PUBLIC,
|
||||||
surface, null, null
|
surface, null, null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -367,7 +420,8 @@ class MainService : Service() {
|
|||||||
private fun createMediaCodec() {
|
private fun createMediaCodec() {
|
||||||
Log.d(logTag, "MediaFormat.MIMETYPE_VIDEO_VP9 :$MIME_TYPE")
|
Log.d(logTag, "MediaFormat.MIMETYPE_VIDEO_VP9 :$MIME_TYPE")
|
||||||
videoEncoder = MediaCodec.createEncoderByType(MIME_TYPE)
|
videoEncoder = MediaCodec.createEncoderByType(MIME_TYPE)
|
||||||
val mFormat = MediaFormat.createVideoFormat(MIME_TYPE, INFO.screenWidth, INFO.screenHeight)
|
val mFormat =
|
||||||
|
MediaFormat.createVideoFormat(MIME_TYPE, SCREEN_INFO.width, SCREEN_INFO.height)
|
||||||
mFormat.setInteger(MediaFormat.KEY_BIT_RATE, VIDEO_KEY_BIT_RATE)
|
mFormat.setInteger(MediaFormat.KEY_BIT_RATE, VIDEO_KEY_BIT_RATE)
|
||||||
mFormat.setInteger(MediaFormat.KEY_FRAME_RATE, VIDEO_KEY_FRAME_RATE)
|
mFormat.setInteger(MediaFormat.KEY_FRAME_RATE, VIDEO_KEY_FRAME_RATE)
|
||||||
mFormat.setInteger(
|
mFormat.setInteger(
|
||||||
|
@ -18,12 +18,10 @@ import java.util.*
|
|||||||
|
|
||||||
@SuppressLint("ConstantLocale")
|
@SuppressLint("ConstantLocale")
|
||||||
val LOCAL_NAME = Locale.getDefault().toString()
|
val LOCAL_NAME = Locale.getDefault().toString()
|
||||||
|
val SCREEN_INFO = Info(0, 0)
|
||||||
val INFO = Info("", "", 0, 0)
|
|
||||||
|
|
||||||
data class Info(
|
data class Info(
|
||||||
var username: String, var hostname: String, var screenWidth: Int, var screenHeight: Int,
|
var width: Int, var height: Int, var scale: Int = 1
|
||||||
var scale: Int = 1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
|
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
|
||||||
@ -33,8 +31,8 @@ fun testVP9Support(): Boolean {
|
|||||||
.findEncoderForFormat(
|
.findEncoderForFormat(
|
||||||
MediaFormat.createVideoFormat(
|
MediaFormat.createVideoFormat(
|
||||||
MediaFormat.MIMETYPE_VIDEO_VP9,
|
MediaFormat.MIMETYPE_VIDEO_VP9,
|
||||||
INFO.screenWidth,
|
SCREEN_INFO.width,
|
||||||
INFO.screenWidth
|
SCREEN_INFO.width
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return res != null
|
return res != null
|
||||||
|
Loading…
x
Reference in New Issue
Block a user