From 14050f7dbfbea88e7fd94fddbd1782554f79c4f3 Mon Sep 17 00:00:00 2001 From: Mygod Date: Sun, 21 Jan 2018 16:25:05 -0800 Subject: [PATCH] Misc refinements --- .../be/mygod/vpnhotspot/RepeaterService.kt | 18 +++++++----------- .../src/main/java/be/mygod/vpnhotspot/Utils.kt | 10 +++++++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt index 2dd90115..7fd93c77 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt @@ -140,13 +140,9 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, VpnMonitor.Ca } App.ACTION_CLEAN_ROUTINGS -> { val routing = routing - try { - routing!!.started = false - if (status == Status.ACTIVE && !initRouting(upstream!!, routing.downstream, routing.hostAddress)) - Toast.makeText(this@RepeaterService, R.string.noisy_su_failure, Toast.LENGTH_SHORT).show() - } catch (e: Exception) { - Toast.makeText(this@RepeaterService, e.message, Toast.LENGTH_SHORT).show() - } + routing!!.started = false + if (status == Status.ACTIVE && !initRouting(upstream!!, routing.downstream, routing.hostAddress)) + Toast.makeText(this@RepeaterService, R.string.noisy_su_failure, Toast.LENGTH_SHORT).show() } } } @@ -240,7 +236,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, VpnMonitor.Ca if (!initRouting(ifname, routing.downstream, routing.hostAddress)) Toast.makeText(this, getText(R.string.noisy_su_failure), Toast.LENGTH_SHORT).show() } - else -> throw RuntimeException("RepeaterService is in unexpected state when receiving onAvailable") + else -> throw IllegalStateException("RepeaterService is in unexpected state when receiving onAvailable") } } override fun onLost(ifname: String) { @@ -273,9 +269,9 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, VpnMonitor.Ca debugLog(TAG, "P2P connection changed: $info\n$net\n$group") } private fun onGroupCreated(info: WifiP2pInfo, group: WifiP2pGroup) { - val owner = info.groupOwnerAddress - val downstream = group.`interface` - if (!info.groupFormed || !info.isGroupOwner || downstream == null || owner == null) return + if (!info.groupFormed || !info.isGroupOwner) return + val owner = info.groupOwnerAddress ?: return + val downstream = group.`interface` ?: return receiverRegistered = true try { if (initRouting(upstream!!, downstream, owner)) doStart(group) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/Utils.kt b/mobile/src/main/java/be/mygod/vpnhotspot/Utils.kt index 2d74cc42..4dc8821c 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/Utils.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/Utils.kt @@ -30,9 +30,13 @@ fun setImageResource(imageView: ImageView, @DrawableRes resource: Int) = imageVi private const val NOISYSU_TAG = "NoisySU" private const val NOISYSU_SUFFIX = "SUCCESS\n" fun loggerSu(command: String): String? { - val process = ProcessBuilder("su", "-c", command) - .redirectErrorStream(true) - .start() + val process = try { + ProcessBuilder("su", "-c", command) + .redirectErrorStream(true) + .start() + } catch (e: IOException) { + return null + } process.waitFor() try { val err = process.errorStream.bufferedReader().readText()