From ff7acf898b48359275a5b09b82ed926a945233f8 Mon Sep 17 00:00:00 2001 From: Lena Date: Wed, 1 Jul 2026 00:00:00 +0000 Subject: app: fix session lifecycle, teardown, and opus playback Opus playback never worked: feed() called dequeueInputBuffer() on a codec in async-callback mode, which always throws, so every packet was silently dropped. Feed input through the async callback with a bounded pending queue instead. Make bring-up transactional: roll back partially opened streams and the server shell on failure, join reader threads on stop, and close the owning ADB streams before releasing sinks. Replace the openAbstract watchdog thread with a real timeout in the vendored AdbConnection.open(), which also removes the half-open stream from the lookup table on failure. Harden the activity: release owned Surfaces, gate callbacks on a destroyed flag and a session generation, serialize reconnect, and handle target replacement via singleTask + onNewIntent. Propagate device-list write failures instead of swallowing them, bound the clipboard payload and the video pending queue against hostile peers, and discard incomplete recordings instead of keeping corrupt files. Use the mediaPlayback foreground-service type; Android 15 stops dataSync services after six hours. Drop the unused ACCESS_NETWORK_STATE permission. --- app/src/main/java/invalid/lena/scrcpy/Sessions.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'app/src/main/java/invalid/lena/scrcpy/Sessions.java') diff --git a/app/src/main/java/invalid/lena/scrcpy/Sessions.java b/app/src/main/java/invalid/lena/scrcpy/Sessions.java index 95c0a1f..91144be 100644 --- a/app/src/main/java/invalid/lena/scrcpy/Sessions.java +++ b/app/src/main/java/invalid/lena/scrcpy/Sessions.java @@ -16,8 +16,8 @@ import android.os.IBinder; // briefly backgrounded (rotation, IME, swipe-to-home) without the // scrcpy server tearing down. // -// Type is FOREGROUND_SERVICE_DATA_SYNC: we are pulling a continuous -// data stream (encoded video + raw PCM) from another device. +// Type is FOREGROUND_SERVICE_MEDIA_PLAYBACK: the app continuously plays +// remote audio/video for as long as the user keeps a mirror session open. // // No binder API - the service does not own Session. Mirror owns it. public final class Sessions extends Service { @@ -41,7 +41,7 @@ public final class Sessions extends Service { .setContentIntent(reopenIntent()) .setOngoing(true) .build(); - startForeground(NOTIF_ID, n, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC); + startForeground(NOTIF_ID, n, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK); return START_NOT_STICKY; } -- cgit v1.2.3