[Bug] Android 11/12 export failure when TMPDIR is not configured

Đang mở
#397 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@TimeToBuildBob đang làm issue này rồi.

Từ ngày 23/11/2026.

  • #398 của @TimeToBuildBob — đang mở

Đánh giá

Độ khó
1/5
Thời gian dự kiến
Dưới một giờ
Mức phù hợp với người mới
20/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
android, kotlin, rust
Lĩnh vực
mobile

Hướng nghiên cứu

The change belongs in RustInterface.kt, where SQLITE_TMPDIR is already set from context.cacheDir; the issue proposes also setting TMPDIR to the same path before the Rust native library loads. Pull request #398 already targets this fix, so review that first and do not start a parallel patch. Done means the proposed assignment is present and raw-data export succeeds on Android 11 and 12.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Summary

Android data export can fail on Android 11 and Android 12 because the Rust process may use an unwritable temporary directory when TMPDIR is not configured.

This appears to be a specific, reproducible cause of the export symptoms discussed in #143. This issue isolates the temporary-directory problem and proposes a small upstream fix.

Observed behavior

  • On Android 11 and Android 12, JSON export could report success while producing an empty file.
  • CSV export could fail before the system folder picker appeared.
  • Android 14 did not exhibit the same export failure in testing.
  • After setting TMPDIR to the app's cache directory, export completed successfully on the affected Android versions.

The fix was tested with app build 0.14.4b1.

No device manufacturer, model, vendor-specific Android skin, or other device-identifying details are included because they are not relevant to reproducing or fixing this issue.

Root cause

The current RustInterface.kt sets only the SQLite-specific variable:

if (context != null) {
    Os.setenv("SQLITE_TMPDIR", context.cacheDir.absolutePath, true)
}

This configures SQLite's temporary directory, but it does not configure the general temporary directory used by Rust.

Rust's std::env::temp_dir() uses the TMPDIR environment variable when it is set. According to the Rust standard-library documentation, when TMPDIR is unset, an app running in its application namespace uses its app cache directory on Android 13 and later, but falls back to /data/local/tmp on earlier Android versions. A regular Android app cannot write to that system directory.

The Rust tempfile crate uses std::env::temp_dir() as its default temporary directory. Therefore, setting SQLITE_TMPDIR alone does not fix temporary-file creation performed through Rust's general temporary-file mechanism.

References:

Proposed fix

Set TMPDIR to the app's writable cache directory before loading the Rust native library, while retaining the existing SQLITE_TMPDIR setting:

if (context != null) {
    val appTempDir = context.cacheDir.absolutePath

    // Rust's Android temp directory may otherwise resolve to /data/local/tmp,
    // which an ordinary application cannot write to.
    Os.setenv("TMPDIR", appTempDir, true)

    // SQLite uses its own temporary-directory environment variable.
    Os.setenv("SQLITE_TMPDIR", appTempDir, true)
}

Verification

The change above was applied and tested. Raw-data export then completed successfully on Android 11 and Android 12, where the failure had been observed. Android 14 did not show the same failure in testing.

This points to the missing TMPDIR assignment as the cause of the Android 11/12 export failure. The proposed change is limited to temporary-directory configuration and does not address the separate browser/server-access concern also mentioned in #143.

Suggested upstream action: add the TMPDIR assignment alongside the existing SQLITE_TMPDIR assignment in RustInterface.kt.

— ChatGPT (technical analysis and report drafting assistance)

Ngôn ngữ chính
Kotlin
Star
287
Fork
65
Merge trung bình
4 ngày 14 giờ
Pull request đã merge (30 ngày)
6

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ActivityWatch/aw-android

Tất cả issue của ActivityWatch/aw-android

Issue tương tự

Thêm issue về Kotlin

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.