Skip to content

Conversation

chenxiaolong
Copy link
Contributor

(Please feel free to close this PR if you're not a fan of this approach or of this functionality in general.)


This updates the worker to spawn and kill logcat and the start and end of every operation. The output is written to sms-ie's external files directory (/sdcard/Android/data/com.github.tmo1.sms_ie/files), which is guaranteed to exist and be accessible using regular filesystem APIs. This is useful when an error is not easily reproducible and the user isn't able to get to their computer and grab a logcat via adb before the logs rotate.

When an error occurs, the error dialog has a new button to open the directory containing the log file in the system file manager (DocumentsUI). DocumentsUI and USB access are the only two ways to access the external files directory in newer versions of Android. However, DocumentsUI is full featured enough that the user can share the log file or copy it elsewhere.

The downside of these logs compared to adb logcat is that they will only contain our own logs. Logs from other apps or other system components (eg. telephony provider) are excluded.

screenshot of new error dialog button screenshot of directory opened in DocumentsUI

@tmo1
Copy link
Owner

tmo1 commented Jul 24, 2025

Looks interesting and potentially useful - thanks! Just to make sure I understood what we're doing here - we're creating a new logcat process of our own and redirecting its output to a file (via STDOUT), but the standard system logcat process will still run, and the standard logcat will still be available via the regular means?

@chenxiaolong
Copy link
Contributor Author

Looks interesting and potentially useful - thanks! Just to make sure I understood what we're doing here - we're creating a new logcat process of our own and redirecting its output to a file (via STDOUT), but the standard system logcat process will still run, and the standard logcat will still be available via the regular means?

Yep! Android internally runs a daemon called logd that's responsible for receiving logs from all apps. The logcat process is just a dumb client that connects to this daemon and asks for the logs the daemon has collected. Any number of logcat processes can run at the same time without affecting each other.

@tmo1
Copy link
Owner

tmo1 commented Jul 27, 2025

I still like the basic idea of making log capture much easier and simpler than the standard methods, but I'm not sure how I feel about having the app do this on its own, without user opt-in. We do try not to write sensitive data or metadata to the logs, but I'm not sure that we never do. I don't know that I can articulate a specific way in which this could lead to a breach of user privacy, but I have a general feeling that it would be better to not dump app logs to a semi-documented location without at least some user confirmation.

I was thinking of leaving this behavior off by default and allowing users to enable it via a settings toggle under "Debug options," although I understand that this won't help for a non-reproducible error that occurs before the option is enabled. What do you think?

@chenxiaolong
Copy link
Contributor Author

Yep, I think that's perfectly reasonable. I can look into adding a toggle for it tomorrow.

This updates the worker to spawn and kill logcat and the start and end
of every operation. The output is written to sms-ie's external files
directory, which is guaranteed to exist and be accessible using regular
filesystem APIs. This is useful when an error is not easily reproducible
and the user isn't able to get to their computer and grab a logcat via
adb before the logs rotate.

When an error occurs, the error dialog has a new button to open the
directory containing the log file in the system file manager
(DocumentsUI). DocumentsUI and USB access are the only two ways to
access the external files directory in newer versions of Android.
However, DocumentsUI is full featured enough that the user can share the
log file or copy it elsewhere.

The downside of these logs compared to `adb logcat` is that they will
only contain our own logs. Logs from other apps or other system
components (eg. telephony provider) are excluded.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
@chenxiaolong
Copy link
Contributor Author

Done! I updated the error dialog so that the "Open log directory" button only shows up if logcat was enabled for that operation. If it wasn't, it'll include a message pointing the user to the new debug setting:

screenshot with save logcat disabled screenshot with save logcat enabled

@tmo1 tmo1 merged commit 734a231 into tmo1:master Jul 29, 2025
5 checks passed
@chenxiaolong chenxiaolong deleted the logcat branch July 29, 2025 15:36
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