Misc refinements

This commit is contained in:
Mygod
2018-01-21 16:25:05 -08:00
parent cc7da9b8a8
commit 14050f7dbf
2 changed files with 14 additions and 14 deletions

View File

@@ -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()
}
}
}
}
@@ -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)

View File

@@ -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)
val process = try {
ProcessBuilder("su", "-c", command)
.redirectErrorStream(true)
.start()
} catch (e: IOException) {
return null
}
process.waitFor()
try {
val err = process.errorStream.bufferedReader().readText()