Fix crashes on root missing

This commit is contained in:
Mygod
2018-09-07 11:27:37 +08:00
parent 22b4dd6438
commit 1db6d6e9ad
3 changed files with 12 additions and 11 deletions

View File

@@ -43,7 +43,7 @@ class P2pSupplicantConfiguration(private val initContent: String? = null) : Parc
private val contentDelegate = lazy { initContent ?: RootSession.use { it.execOut("cat $confPath") } }
private val content by contentDelegate
fun readPsk(handler: ((RuntimeException) -> Unit)? = null): String? {
fun readPsk(): String? {
return try {
val match = pskParser.findAll(content).single()
if (match.groups[2] == null && match.groups[3] == null) "" else {
@@ -53,13 +53,11 @@ class P2pSupplicantConfiguration(private val initContent: String? = null) : Parc
result
}
} catch (e: NoSuchElementException) {
handler?.invoke(e)
null
} catch (e: RuntimeException) {
Crashlytics.log(Log.WARN, TAG, content)
if (contentDelegate.isInitialized()) Crashlytics.log(Log.WARN, TAG, content)
e.printStackTrace()
Crashlytics.logException(e)
handler?.invoke(e)
null
}
}