Fix crashes on root missing
This commit is contained in:
@@ -106,9 +106,7 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
|
||||
val conf = P2pSupplicantConfiguration()
|
||||
wifi.SSID = ssid
|
||||
wifi.preSharedKey = group.passphrase
|
||||
if (wifi.preSharedKey == null) {
|
||||
wifi.preSharedKey = conf.readPsk { SmartSnackbar.make(it.message.toString()).show() }
|
||||
}
|
||||
if (wifi.preSharedKey == null) wifi.preSharedKey = conf.readPsk()
|
||||
if (wifi.preSharedKey != null) {
|
||||
WifiP2pDialogFragment().apply {
|
||||
arguments = bundleOf(Pair(WifiP2pDialogFragment.KEY_CONFIGURATION, wifi),
|
||||
|
||||
@@ -21,7 +21,13 @@ abstract class IpMonitor : Runnable {
|
||||
private var monitor: Process? = null
|
||||
private var pool: ScheduledExecutorService? = null
|
||||
|
||||
private fun handleProcess(process: Process): Int {
|
||||
private fun handleProcess(builder: ProcessBuilder): Int {
|
||||
val process = try {
|
||||
builder.start()
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
return -1
|
||||
}
|
||||
val err = thread("${javaClass.simpleName}-error") {
|
||||
try {
|
||||
process.errorStream.bufferedReader().forEachLine {
|
||||
@@ -46,9 +52,8 @@ abstract class IpMonitor : Runnable {
|
||||
init {
|
||||
thread("${javaClass.simpleName}-input") {
|
||||
// monitor may get rejected by SELinux
|
||||
if (handleProcess(ProcessBuilder("ip", "monitor", monitoredObject).start()) == 0) return@thread
|
||||
if (handleProcess(ProcessBuilder("su", "-c", "exec ip monitor $monitoredObject").start()) == 0)
|
||||
return@thread
|
||||
if (handleProcess(ProcessBuilder("ip", "monitor", monitoredObject)) == 0) return@thread
|
||||
if (handleProcess(ProcessBuilder("su", "-c", "exec ip monitor $monitoredObject")) == 0) return@thread
|
||||
Crashlytics.log(Log.WARN, javaClass.simpleName, "Failed to set up monitor, switching to polling")
|
||||
Crashlytics.logException(MonitorFailure())
|
||||
val pool = Executors.newScheduledThreadPool(1)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user