Skip to content

Commit

Permalink
simplify SystemProperties#getAll
Browse files Browse the repository at this point in the history
  • Loading branch information
septs committed Feb 17, 2024
1 parent 23a78a8 commit f7c1212
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions app/src/main/java/app/septs/euiccprobe/SystemProperties.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@ object SystemProperties {
return p.inputStream.reader().readText().trim().ifEmpty { null }
}

fun getAll(): Map<String, String> {
fun getAll() = buildMap {
val p = Runtime.getRuntime().exec("getprop")
return buildMap {
p.inputStream.reader().forEachLine { line ->
val name = line.indexOf('[')
.let { (it + 1)..<line.indexOf(']', it) }
val value = line.indexOf('[', name.last)
.let { (it + 1)..<line.indexOf(']', it) }
if (value.isEmpty()) return@forEachLine
put(line.slice(name), line.slice(value))
}
p.inputStream.reader().forEachLine { line ->
val name = line.indexOf('[')
.let { (it + 1)..<line.indexOf(']', it) }
val value = line.indexOf('[', name.last)
.let { (it + 1)..<line.indexOf(']', it) }
if (value.isEmpty()) return@forEachLine
put(line.slice(name), line.slice(value))
}
}

Expand Down

0 comments on commit f7c1212

Please sign in to comment.