Skip to content

Commit 203ea3b

Browse files
authored
[docs][refactor] update README/CHANGELOG for maxLogcatEntries + refactor LogcatDataSource (#249)
## Summary by CodeRabbit * **Refactor** * [LogcatDataSource] Swap Runtime.getRuntime().exec(String) for ProcessBuilder with an explicit argument list, in both the streaming producer and the one-shot snapshot capture * **Documentation** * Updated changelog with new capabilities. * Added configuration guide for customizing logcat buffer limits.
1 parent 57b9d70 commit 203ea3b

3 files changed

Lines changed: 29 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### New Features
66

77
* **Thermal status row** – Optional thermal-status indicator for the compact overlay, opt-in via `OverlayMode.FullMetrics(showThermal = true)`. Combines `PowerManager.getCurrentThermalStatus()` with `getThermalHeadroom()` per [Google's ADPF guidance](https://developer.android.com/games/optimize/adpf/thermal#device-limitations-of-the-thermal-api) so devices with an incomplete thermal HAL still surface a useful signal. Requires Android 11 (API 30) or above; row stays hidden on older devices. Resolves [#246](https://github.com/Manabu-GT/DebugOverlay-Android/issues/246).
8+
* **Configurable Logcat buffer size** – New `Config.maxLogcatEntries` controls how many entries the built-in Logcat tab retains (default 300). Also bounds `logcat -T N` / `-t N` so it caps OS replay on panel open and on bug-report snapshots. Reassignable at runtime via `DebugOverlay.configure { maxLogcatEntries = … }`.
89

910
## Version 2.5.0 *(2026-05-12)*
1011

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,18 @@ DebugOverlay.configure {
191191

192192
The row shows the current thermal-throttling level with a color-coded dot. Labels are abbreviated to fit the compact panel — `None` / `Light` / `Mod` / `Sev` / `Crit` / `Emer` / `Shut` — mapping to `PowerManager.THERMAL_STATUS_NONE` / `_LIGHT` / `_MODERATE` / `_SEVERE` / `_CRITICAL` / `_EMERGENCY` / `_SHUTDOWN` respectively. Requires Android 11 (API 30) or above with a working thermal HAL — the row stays hidden on older devices and on API 30+ devices whose HAL doesn't expose `getThermalHeadroom` data. If the HAL later starts reporting, the row appears on the next poll.
193193

194+
### Logcat buffer size
195+
196+
The built-in Logcat tab keeps the last 300 entries by default. Override via `maxLogcatEntries`:
197+
198+
```kotlin
199+
DebugOverlay.configure {
200+
maxLogcatEntries = 1000
201+
}
202+
```
203+
204+
The value also bounds the `logcat -T N` / `-t N` calls, so it caps how many lines the OS replays when the panel opens and when a bug report snapshot is captured.
205+
194206
### Network request tracking
195207

196208
```kotlin

debugoverlay-core/src/main/kotlin/com/ms/square/debugoverlay/internal/data/source/LogcatDataSource.kt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import kotlin.time.Duration.Companion.milliseconds
3939
internal class LogcatDataSource(
4040
scope: CoroutineScope,
4141
private val parser: LogcatEntryParser = LogcatEntryParser(),
42-
initialMaxEntries: Int,
42+
@IntRange(from = 1) initialMaxEntries: Int,
4343
) : LogSource,
4444
Clearable,
4545
Closeable {
@@ -91,9 +91,15 @@ internal class LogcatDataSource(
9191
try {
9292
/**
9393
* NOTE: The -T flag with a number fetches the last N lines from this app and continue to listens
94-
* for new logs (-t option fetches once and exists immediately).
94+
* for new logs (-t option fetches once and exits immediately).
9595
*/
96-
val process = Runtime.getRuntime().exec("logcat -v threadtime,printable,epoch -T $maxEntries").also {
96+
val process = ProcessBuilder(
97+
"logcat",
98+
"-v",
99+
"threadtime,printable,epoch",
100+
"-T",
101+
maxEntries.toString()
102+
).start().also {
97103
synchronized(processLock) {
98104
currentProcess = it
99105
}
@@ -167,8 +173,13 @@ internal class LogcatDataSource(
167173
private suspend fun captureLogcatOnce(): List<LogEntry> = withContext(Dispatchers.IO) {
168174
buildList {
169175
// -t N = fetch N recent lines and EXIT (vs -T which streams continuously)
170-
val process = Runtime.getRuntime()
171-
.exec("logcat -v threadtime,printable,epoch -t $maxEntries")
176+
val process = ProcessBuilder(
177+
"logcat",
178+
"-v",
179+
"threadtime,printable,epoch",
180+
"-t",
181+
maxEntries.toString()
182+
).start()
172183

173184
try {
174185
InputStreamReader(process.inputStream).useLines { lines ->

0 commit comments

Comments
 (0)