Skip to content

Commit

Permalink
fix(android): screenrecorder pid parsing should validate the output f…
Browse files Browse the repository at this point in the history
…ormat of ps
  • Loading branch information
Malinskiy committed Aug 8, 2023
1 parent d6cab46 commit 0064661
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
object Versions {
val marathon = System.getenv("GIT_TAG_NAME") ?: "0.8.2"
val marathon = System.getenv("GIT_TAG_NAME") ?: "0.8.5"

val kotlin = "1.8.20"
val coroutines = "1.7.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ internal class ScreenRecorderStopper(private val device: AndroidDevice) {
if (output.isBlank()) {
return ""
}
val split = output.split("\\s+".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
val pid = split[1]

val lastLine = output.lines().last { it.isNotEmpty() }
val split = lastLine.split(' ').filter { it.isNotBlank() }
val pid = split.getOrNull(1)?.let { it.toIntOrNull()?.toString() } ?: ""
logger.trace("Extracted PID {} from output {}", pid, output)
return pid
}
Expand All @@ -37,7 +39,7 @@ internal class ScreenRecorderStopper(private val device: AndroidDevice) {
device.safeExecuteShellCommand("kill -2 $pid")
return true
} else {
logger.trace("Did not kill any screen recording process")
logger.warn { "Did not kill any screen recording process" }
}
} catch (e: Exception) {
logger.error("Error while killing recording processes", e)
Expand Down

0 comments on commit 0064661

Please sign in to comment.