From 1db6d6e9ad4e82cd7990ec541227fb77829bff10 Mon Sep 17 00:00:00 2001 From: Mygod Date: Fri, 7 Sep 2018 11:27:37 +0800 Subject: [PATCH] Fix crashes on root missing --- .../be/mygod/vpnhotspot/manage/RepeaterManager.kt | 4 +--- .../main/java/be/mygod/vpnhotspot/net/IpMonitor.kt | 13 +++++++++---- .../net/wifi/P2pSupplicantConfiguration.kt | 6 ++---- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/RepeaterManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/RepeaterManager.kt index 9072c591..e3f4765f 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/RepeaterManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/RepeaterManager.kt @@ -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), diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/IpMonitor.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/IpMonitor.kt index 901938ab..d669ec94 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/IpMonitor.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/IpMonitor.kt @@ -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) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/P2pSupplicantConfiguration.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/P2pSupplicantConfiguration.kt index 6eb77b09..c8e6b01a 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/P2pSupplicantConfiguration.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/P2pSupplicantConfiguration.kt @@ -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 } }