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/Devices.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'app/src/main/java/invalid/lena/scrcpy/Devices.java') diff --git a/app/src/main/java/invalid/lena/scrcpy/Devices.java b/app/src/main/java/invalid/lena/scrcpy/Devices.java index 2883025..c3e5141 100644 --- a/app/src/main/java/invalid/lena/scrcpy/Devices.java +++ b/app/src/main/java/invalid/lena/scrcpy/Devices.java @@ -6,6 +6,7 @@ import org.json.JSONArray; import org.json.JSONObject; import java.io.File; +import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.ArrayList; @@ -97,18 +98,14 @@ public final class Devices { } } - public static void save(Context ctx, List devices) { + public static void save(Context ctx, List devices) throws IOException { File f = new File(ctx.getFilesDir(), FILE); - try { - AtomicFiles.write(f, serialize(devices).getBytes(StandardCharsets.UTF_8)); - } catch (Exception e) { - Log.e(e, "devices: save failed"); - } + AtomicFiles.write(f, serialize(devices).getBytes(StandardCharsets.UTF_8)); } // Add or replace by host+port. Context-rooted; the in-place helper // is the test seam. - public static List upsert(Context ctx, Device d) { + public static synchronized List upsert(Context ctx, Device d) throws IOException { List list = load(ctx); list.removeIf(d::equals); list.add(d); @@ -117,7 +114,7 @@ public final class Devices { } // Remove the matching device (by host+port). Returns the updated list. - public static List remove(Context ctx, Device d) { + public static synchronized List remove(Context ctx, Device d) throws IOException { List list = load(ctx); list.removeIf(d::equals); save(ctx, list); -- cgit v1.2.3