Skip to content

fix(android): log Rust panics to logcat via android_log - #654

Merged
ErikBjare merged 1 commit into
ActivityWatch:masterfrom
0xbrayo:fix/220-log-rust-panics-to-logcat
Aug 25, 2026
Merged

ErikBjare merged 1 commit into
ActivityWatch:masterfrom
0xbrayo:fix/220-log-rust-panics-to-logcat

Conversation

@0xbrayo

@0xbrayo 0xbrayo commented Aug 24, 2026

Copy link
Copy Markdown
Member

First follow-up from ActivityWatch/aw-android#220.

Rust's default panic hook writes to stderr, which Android discards, so a panic in libaw_sync.so currently surfaces only as SIGABRT with no message in logcat.

This installs:

  • aw-sync: android_logger plus a panic hook that writes the payload, location, and backtrace via __android_log_write (tag aw-sync), installed from JNI_OnLoad and each JNI entry
  • aw-server: log_panics::init() during Android initialize() so panics in libaw_server.so are diagnosable the same way (tag aw-server-rust)

This does not fix the abort itself; it makes the panic diagnosable.

Verified: cargo test -p aw-sync (5/5) and ./compile-android.sh arm64 (JNI_OnLoad exported from libaw_sync.so).

The default panic hook writes to stderr, which Android discards, so a
panic in libaw_sync.so surfaces only as SIGABRT with no message
(ActivityWatch/aw-android#220).

Install a panic hook in aw-sync (JNI_OnLoad plus each JNI entry) that
writes the panic payload, location, and backtrace through
__android_log_write, and initialize android_logger so existing log
macros also reach logcat.

Also call log_panics::init() from aw-server's Android initialize() so
panics in libaw_server.so are diagnosable the same way.
@greptile-apps

greptile-apps Bot commented Aug 24, 2026

Copy link
Copy Markdown

Greptile Summary

This PR makes Android-native Rust panics visible in logcat without changing panic termination behavior.

  • Adds Android logging and a panic hook to aw-sync, initialized during library loading and at every JNI entry point.
  • Initializes log_panics after the Android logger in aw-server.
  • Adds the target-specific android_logger dependency and corresponding lockfile edge.

Confidence Score: 5/5

The PR appears safe to merge, with no concrete changed-code failure identified.

The logging setup is target-scoped and idempotent, JNI calls retain a fallback initialization path, and the dependency update does not introduce a newly resolved vulnerable package.

Important Files Changed

Filename Overview
aw-sync/src/android.rs Adds idempotent Android logger setup, direct fatal logcat output, panic diagnostics, JNI_OnLoad, and defensive initialization at each JNI boundary.
aw-server/src/android/mod.rs Installs log_panics after Android logger initialization so server panics are routed to logcat.
aw-sync/Cargo.toml Adds android_logger only for Android targets.
Cargo.lock Records android_logger as an aw-sync dependency without changing resolved package versions.

Sequence Diagram

sequenceDiagram
    participant App as Android app
    participant VM as JVM loader
    participant Sync as libaw_sync.so
    participant Server as libaw_server.so
    participant Logcat
    App->>VM: Load aw_sync
    VM->>Sync: JNI_OnLoad
    Sync->>Sync: Initialize android_logger and panic hook
    App->>Server: initialize()
    Server->>Server: Initialize logger and log_panics
    App->>Sync: Invoke sync JNI operation
    Sync->>Sync: Ensure logging initialized once
    alt Rust panic
        Sync->>Logcat: Payload, location, and backtrace
    end
Loading

Reviews (1): Last reviewed commit: "fix(android): log Rust panics to logcat ..." | Re-trigger Greptile

@codecov

codecov Bot commented Aug 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.11%. Comparing base (656f3c9) to head (34814ce).
⚠️ Report is 88 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #654      +/-   ##
==========================================
+ Coverage   70.81%   77.11%   +6.29%     
==========================================
  Files          51       65      +14     
  Lines        2916     5370    +2454     
==========================================
+ Hits         2065     4141    +2076     
- Misses        851     1229     +378     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants