fix MiuiHelper npe

This commit is contained in:
HaliksaR 2020-11-15 06:24:15 +07:00
parent be23fe821d
commit 31162db145
1 changed files with 9 additions and 17 deletions

View File

@ -6,28 +6,20 @@ import java.io.InputStreamReader
object MiuiHelper {
fun isMiui(): Boolean = getSystemProps("ro.miui.ui.version.name")!!.isNotEmpty()
private const val MIUI_PROP_NAME = "ro.miui.ui.version.name"
fun isMiui(): Boolean = !getSystemProps(MIUI_PROP_NAME).isNullOrEmpty()
private fun getSystemProps(propname: String): String? {
val line: String
var input: BufferedReader? = null
try {
val p = Runtime.getRuntime().exec("getprop $propname")
input = BufferedReader(InputStreamReader(p.inputStream), 1024)
line = input.readLine()
input.close()
return try {
val process = Runtime.getRuntime().exec("getprop $propname")
input = BufferedReader(InputStreamReader(process.inputStream), 1024)
input.readLine()
} catch (e: IOException) {
return null
null
} finally {
if (input != null) {
try {
input.close()
} catch (e: IOException) {
e.printStackTrace()
}
}
input?.close()
}
return line
}
}