From eb0c8951196c637e44daf3c0617b131b997d5d2c Mon Sep 17 00:00:00 2001 From: Lena Date: Thu, 1 Jan 2026 00:00:00 +0000 Subject: scrcpy-android: mirror an Android device over wireless ADB Native Java app for Android 12+ that mirrors another Android device over wireless ADB, forwarding video, audio, touch input, and clipboard. Bundles a pinned scrcpy-server.jar and the vendored libadb-android stack. Supports h264/h265/av1 video and raw/opus audio with in-app codec selection. No NDK, no Kotlin. Includes JVM unit tests and a Docker-based emulator e2e rig. --- .../java/invalid/lena/scrcpy/AtomicFilesTest.java | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 app/src/test/java/invalid/lena/scrcpy/AtomicFilesTest.java (limited to 'app/src/test/java/invalid/lena/scrcpy/AtomicFilesTest.java') diff --git a/app/src/test/java/invalid/lena/scrcpy/AtomicFilesTest.java b/app/src/test/java/invalid/lena/scrcpy/AtomicFilesTest.java new file mode 100644 index 0000000..7124fd2 --- /dev/null +++ b/app/src/test/java/invalid/lena/scrcpy/AtomicFilesTest.java @@ -0,0 +1,54 @@ +package invalid.lena.scrcpy; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertFalse; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import java.io.File; +import java.nio.file.Files; + +public class AtomicFilesTest { + + @Rule + public TemporaryFolder dir = new TemporaryFolder(); + + @Test + public void writeCreatesFile() throws Exception { + File f = new File(dir.getRoot(), "x"); + AtomicFiles.write(f, "hello".getBytes()); + assertArrayEquals("hello".getBytes(), Files.readAllBytes(f.toPath())); + } + + @Test + public void writeReplacesExistingWhole() throws Exception { + File f = new File(dir.getRoot(), "x"); + AtomicFiles.write(f, "old".getBytes()); + AtomicFiles.write(f, "new-and-longer".getBytes()); + assertArrayEquals("new-and-longer".getBytes(), Files.readAllBytes(f.toPath())); + } + + @Test + public void writeLeavesNoTempBehind() throws Exception { + File f = new File(dir.getRoot(), "x"); + AtomicFiles.write(f, "data".getBytes()); + assertFalse(new File(dir.getRoot(), "x.tmp").exists()); + } + + @Test + public void staleTempDoesNotCorruptDestination() throws Exception { + // A crash after staging but before the rename leaves a partial ".tmp". + // The destination must still hold the previous good content, and the + // next successful write must overwrite the stale temp cleanly. + File f = new File(dir.getRoot(), "x"); + AtomicFiles.write(f, "good".getBytes()); + Files.write(new File(dir.getRoot(), "x.tmp").toPath(), "partial".getBytes()); + assertArrayEquals("good".getBytes(), Files.readAllBytes(f.toPath())); + + AtomicFiles.write(f, "good2".getBytes()); + assertArrayEquals("good2".getBytes(), Files.readAllBytes(f.toPath())); + assertFalse(new File(dir.getRoot(), "x.tmp").exists()); + } +} -- cgit v1.2.3