Fix some SocketException crashes
This commit is contained in:
@@ -29,6 +29,7 @@ import be.mygod.vpnhotspot.net.IpNeighbourMonitor
|
||||
import be.mygod.vpnhotspot.net.ConnectivityManagerHelper
|
||||
import be.mygod.vpnhotspot.net.TetherType
|
||||
import java.net.NetworkInterface
|
||||
import java.net.SocketException
|
||||
import java.util.*
|
||||
|
||||
class RepeaterFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClickListener, IpNeighbourMonitor.Callback {
|
||||
@@ -59,7 +60,12 @@ class RepeaterFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClickL
|
||||
val ssid @Bindable get() = binder?.service?.ssid ?: getText(R.string.repeater_inactive)
|
||||
val password @Bindable get() = binder?.service?.password ?: ""
|
||||
val addresses @Bindable get(): String {
|
||||
return NetworkInterface.getByName(p2pInterface ?: return "")?.formatAddresses() ?: ""
|
||||
return try {
|
||||
NetworkInterface.getByName(p2pInterface ?: return "")?.formatAddresses() ?: ""
|
||||
} catch (e: SocketException) {
|
||||
e.printStackTrace()
|
||||
""
|
||||
}
|
||||
}
|
||||
|
||||
fun onStatusChanged() {
|
||||
|
||||
@@ -18,6 +18,7 @@ import be.mygod.vpnhotspot.App.Companion.app
|
||||
import be.mygod.vpnhotspot.net.Routing
|
||||
import be.mygod.vpnhotspot.net.VpnMonitor
|
||||
import java.net.InetAddress
|
||||
import java.net.SocketException
|
||||
import java.util.regex.Pattern
|
||||
|
||||
class RepeaterService : Service(), WifiP2pManager.ChannelListener, VpnMonitor.Callback {
|
||||
@@ -283,7 +284,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, VpnMonitor.Ca
|
||||
receiverRegistered = true
|
||||
try {
|
||||
if (initRouting(upstream, downstream, owner, dns)) doStart(group)
|
||||
} catch (e: Routing.InterfaceNotFoundException) {
|
||||
} catch (e: SocketException) {
|
||||
startFailure(e.message, group)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import be.mygod.vpnhotspot.databinding.ListitemInterfaceBinding
|
||||
import be.mygod.vpnhotspot.net.ConnectivityManagerHelper
|
||||
import be.mygod.vpnhotspot.net.TetherType
|
||||
import java.net.NetworkInterface
|
||||
import java.net.SocketException
|
||||
|
||||
class TetheringFragment : Fragment(), ServiceConnection {
|
||||
companion object {
|
||||
@@ -84,7 +85,12 @@ class TetheringFragment : Fragment(), ServiceConnection {
|
||||
private val tethered = SortedList(TetheredInterface::class.java, TetheredInterfaceSorter)
|
||||
|
||||
fun update(data: Set<String>) {
|
||||
val lookup = NetworkInterface.getNetworkInterfaces().asSequence().associateBy { it.name }
|
||||
val lookup = try {
|
||||
NetworkInterface.getNetworkInterfaces().asSequence().associateBy { it.name }
|
||||
} catch (e: SocketException) {
|
||||
e.printStackTrace()
|
||||
emptyMap<String, NetworkInterface>()
|
||||
}
|
||||
tethered.clear()
|
||||
tethered.addAll(data.map { TetheredInterface(it, lookup) })
|
||||
notifyDataSetChanged()
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.widget.Toast
|
||||
import be.mygod.vpnhotspot.App.Companion.app
|
||||
import be.mygod.vpnhotspot.net.*
|
||||
import java.net.InetAddress
|
||||
import java.net.SocketException
|
||||
|
||||
class TetheringService : Service(), VpnMonitor.Callback, IpNeighbourMonitor.Callback {
|
||||
companion object {
|
||||
@@ -48,7 +49,7 @@ class TetheringService : Service(), VpnMonitor.Callback, IpNeighbourMonitor.Call
|
||||
val upstream = upstream
|
||||
if (upstream != null) {
|
||||
var failed = false
|
||||
for ((downstream, value) in routings) if (value == null) {
|
||||
for ((downstream, value) in routings) if (value == null) try {
|
||||
// system tethering already has working forwarding rules
|
||||
// so it doesn't make sense to add additional forwarding rules
|
||||
val routing = Routing(upstream, downstream).rule().forward().dnsRedirect(dns)
|
||||
@@ -57,6 +58,9 @@ class TetheringService : Service(), VpnMonitor.Callback, IpNeighbourMonitor.Call
|
||||
routing.stop()
|
||||
routings.remove(downstream)
|
||||
}
|
||||
} catch (e: SocketException) {
|
||||
e.printStackTrace()
|
||||
failed = true
|
||||
}
|
||||
if (failed) Toast.makeText(this, getText(R.string.noisy_su_failure), Toast.LENGTH_SHORT).show()
|
||||
} else if (!receiverRegistered) {
|
||||
|
||||
@@ -12,6 +12,7 @@ import be.mygod.vpnhotspot.App.Companion.app
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.net.NetworkInterface
|
||||
import java.net.SocketException
|
||||
|
||||
fun debugLog(tag: String?, message: String?) {
|
||||
if (BuildConfig.DEBUG) Log.d(tag, message)
|
||||
@@ -31,10 +32,15 @@ fun intentFilter(vararg actions: String): IntentFilter {
|
||||
fun setImageResource(imageView: ImageView, @DrawableRes resource: Int) = imageView.setImageResource(resource)
|
||||
|
||||
fun NetworkInterface.formatAddresses() =
|
||||
(this.interfaceAddresses.asSequence()
|
||||
(interfaceAddresses.asSequence()
|
||||
.map { "${it.address.hostAddress}/${it.networkPrefixLength}" }
|
||||
.toList() +
|
||||
listOfNotNull(this.hardwareAddress?.joinToString(":") { "%02x".format(it) }))
|
||||
listOfNotNull(try {
|
||||
hardwareAddress?.joinToString(":") { "%02x".format(it) }
|
||||
} catch (e: SocketException) {
|
||||
e.printStackTrace()
|
||||
null
|
||||
}))
|
||||
.joinToString("\n")
|
||||
|
||||
private const val NOISYSU_TAG = "NoisySU"
|
||||
|
||||
@@ -6,11 +6,11 @@ import be.mygod.vpnhotspot.R
|
||||
import be.mygod.vpnhotspot.debugLog
|
||||
import be.mygod.vpnhotspot.loggerSuStream
|
||||
import be.mygod.vpnhotspot.noisySu
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.net.Inet4Address
|
||||
import java.net.InetAddress
|
||||
import java.net.NetworkInterface
|
||||
import java.net.SocketException
|
||||
import java.util.*
|
||||
|
||||
class Routing(val upstream: String?, val downstream: String, ownerAddress: InetAddress? = null) {
|
||||
@@ -55,7 +55,7 @@ class Routing(val upstream: String?, val downstream: String, ownerAddress: InetA
|
||||
}
|
||||
}
|
||||
|
||||
class InterfaceNotFoundException : IOException() {
|
||||
class InterfaceNotFoundException : SocketException() {
|
||||
override val message: String get() = app.getString(R.string.exception_interface_not_found)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user