fix(android): reduce Connected & Screen messages when host screen is off

Signed-off-by: Amirhossein Akhlaghpour <m9.akhlaghpoor@gmail.com>
This commit is contained in:
Amirhossein Akhlaghpour 2026-04-26 17:38:28 +03:30
parent 38f1300717
commit c915bfbf86
No known key found for this signature in database
GPG key ID: D7A35F11FB70A961
2 changed files with 43 additions and 0 deletions

View file

@ -91,6 +91,10 @@ class InputService : AccessibilityService() {
private val volumeController: VolumeController by lazy { VolumeController(applicationContext.getSystemService(AUDIO_SERVICE) as AudioManager) }
fun wakeUpDevice() {
performGlobalAction(GLOBAL_ACTION_HOME)
}
@RequiresApi(Build.VERSION_CODES.N)
fun onMouseInput(mask: Int, _x: Int, _y: Int) {
val x = max(0, _x)

View file

@ -62,6 +62,8 @@ const val VIDEO_KEY_FRAME_RATE = 30
class MainService : Service() {
private val wakeRetryHandler = Handler(Looper.getMainLooper())
@Keep
@RequiresApi(Build.VERSION_CODES.N)
fun rustPointerInput(kind: Int, mask: Int, x: Int, y: Int) {
@ -128,6 +130,7 @@ class MainService : Service() {
}
if (authorized) {
if (!isFileTransfer && !isStart) {
wakeAndRefreshIncomingScreenIfNeeded("authorized_connection")
startCapture()
}
onClientAuthorizedNotification(id, type, username, peerId)
@ -228,6 +231,41 @@ class MainService : Service() {
private lateinit var notificationChannel: String
private lateinit var notificationBuilder: NotificationCompat.Builder
private fun wakeScreen(reason: String) {
if (wakeLock.isHeld) {
Log.d(logTag, "WakeLock release before wake, reason:$reason")
wakeLock.release()
}
Log.d(logTag, "Wake screen, reason:$reason")
wakeLock.acquire(5000)
}
private fun wakeAndRefreshIncomingScreenIfNeeded(reason: String) {
if (powerManager.isInteractive) {
return
}
wakeRetryHandler.removeCallbacksAndMessages(null)
wakeScreen(reason)
wakeRetryHandler.postDelayed({
if (powerManager.isInteractive) {
Log.d(logTag, "Skip delayed wake refresh, device already interactive, reason:$reason")
return@postDelayed
}
// HOME works better here than faking a tap.
InputService.ctx?.wakeUpDevice()
FFI.refreshScreen()
}, 500)
wakeRetryHandler.postDelayed({
if (powerManager.isInteractive) {
Log.d(logTag, "Skip retry wake refresh, device already interactive, reason:$reason")
return@postDelayed
}
wakeScreen("$reason-retry")
InputService.ctx?.wakeUpDevice()
FFI.refreshScreen()
}, 1200)
}
override fun onCreate() {
super.onCreate()
Log.d(logTag,"MainService onCreate, sdk int:${Build.VERSION.SDK_INT} reuseVirtualDisplay:$reuseVirtualDisplay")
@ -249,6 +287,7 @@ class MainService : Service() {
}
override fun onDestroy() {
wakeRetryHandler.removeCallbacksAndMessages(null)
checkMediaPermission()
stopService(Intent(this, FloatingWindowService::class.java))
super.onDestroy()