diff options
| author | Lena <lena@omega> | 2026-01-01 00:00:00 +0000 |
|---|---|---|
| committer | Lena <lena@omega> | 2026-06-24 22:14:50 +0300 |
| commit | eb0c8951196c637e44daf3c0617b131b997d5d2c (patch) | |
| tree | 2f83b6a41cee745467e53fc401942b82cea286ea /app/src/main/java/invalid/lena/scrcpy/Crashlog.java | |
| download | scrcpy-android-eb0c8951196c637e44daf3c0617b131b997d5d2c.tar.gz | |
scrcpy-android: mirror an Android device over wireless ADB0.1
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.
Diffstat (limited to 'app/src/main/java/invalid/lena/scrcpy/Crashlog.java')
| -rw-r--r-- | app/src/main/java/invalid/lena/scrcpy/Crashlog.java | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/app/src/main/java/invalid/lena/scrcpy/Crashlog.java b/app/src/main/java/invalid/lena/scrcpy/Crashlog.java new file mode 100644 index 0000000..00bd3d8 --- /dev/null +++ b/app/src/main/java/invalid/lena/scrcpy/Crashlog.java @@ -0,0 +1,48 @@ +package invalid.lena.scrcpy; + +import android.content.Context; + +import java.io.File; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + +// Catches uncaught exceptions on any thread, writes them as plain +// text to <externalFilesDir>/crash-<timestamp>.log, then chains to +// the system default handler so the OS crash dialog still appears. +// Testers can share the file from the app's storage instead of +// fishing for it in adb logcat. +public final class Crashlog { + + private Crashlog() {} + + public static void install(Context ctx) { + File dir = ctx.getExternalFilesDir(null); + if (dir == null) { + Log.w("crashlog: no external storage, skipping install"); + return; + } + Thread.UncaughtExceptionHandler prev = + Thread.getDefaultUncaughtExceptionHandler(); + Thread.setDefaultUncaughtExceptionHandler((t, e) -> { + try { + String ts = new SimpleDateFormat("yyyyMMdd-HHmmss", + Locale.ROOT).format(new Date()); + File out = new File(dir, "crash-" + ts + ".log"); + try (PrintWriter pw = new PrintWriter(new FileWriter(out))) { + pw.println("# " + new Date()); + pw.println("# thread=" + t.getName()); + pw.println(); + e.printStackTrace(pw); + } + Log.e(e, "crashlog: wrote %s", out.getAbsolutePath()); + } catch (Throwable ignored) { + // best effort - do not mask the original crash + } + if (prev != null) prev.uncaughtException(t, e); + }); + Log.i("crashlog: installed -> %s", dir.getAbsolutePath()); + } +} |