Reduce battery usage from background log streaming#6
Merged
Conversation
The logcat reader was spawned in Application.onCreate and ran forever, reading and string-matching every line of the device's system log even while the UI was closed. Scope it to the Activity lifecycle so it only runs while the user is looking at the log view, and filter at the logcat level (Morganite:V *:S) so unrelated system log lines never reach our process. Also drop the AlarmManager.RTC_WAKEUP indirection used to start the foreground service (startForegroundService directly does the same job without a wake alarm) and remove the NostrClientLoggerListener whose only purpose was to emit a Log.d for every websocket event.
The kernel-side filter form 'logcat Morganite:V *:S' was not matching in practice, so no lines reached the UI. Go back to reading the full logcat stream and filtering by tag in Kotlin like the original code. The lifecycle scoping from the previous commit is what actually saves battery (logcat no longer runs while the UI is closed); the kernel filter was only a minor optimization on top of that and isn't worth losing the log view over.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The logcat reader was spawned in Application.onCreate and ran forever,
reading and string-matching every line of the device's system log even
while the UI was closed. Scope it to the Activity lifecycle so it only
runs while the user is looking at the log view, and filter at the
logcat level (Morganite:V *:S) so unrelated system log lines never
reach our process.
Also drop the AlarmManager.RTC_WAKEUP indirection used to start the
foreground service (startForegroundService directly does the same job
without a wake alarm) and remove the NostrClientLoggerListener whose
only purpose was to emit a Log.d for every websocket event.