Create more noise if SU fails
This commit is contained in:
@@ -181,7 +181,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, VpnListener.C
|
|||||||
VpnListener.registerCallback(this)
|
VpnListener.registerCallback(this)
|
||||||
return START_NOT_STICKY
|
return START_NOT_STICKY
|
||||||
}
|
}
|
||||||
private fun startFailure(msg: String?, group: WifiP2pGroup? = null) {
|
private fun startFailure(msg: CharSequence?, group: WifiP2pGroup? = null) {
|
||||||
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
|
||||||
showNotification()
|
showNotification()
|
||||||
if (group != null) removeGroup() else clean()
|
if (group != null) removeGroup() else clean()
|
||||||
@@ -227,13 +227,15 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, VpnListener.C
|
|||||||
Status.ACTIVE -> {
|
Status.ACTIVE -> {
|
||||||
val routing = routing
|
val routing = routing
|
||||||
check(!routing!!.started)
|
check(!routing!!.started)
|
||||||
initRouting(ifname, routing.downstream, routing.hostAddress)
|
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 RuntimeException("RepeaterService is in unexpected state when receiving onAvailable")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
override fun onLost(ifname: String) {
|
override fun onLost(ifname: String) {
|
||||||
routing?.stop()
|
if (routing?.stop() == false)
|
||||||
|
Toast.makeText(this, getText(R.string.noisy_su_failure), Toast.LENGTH_SHORT).show()
|
||||||
upstream = null
|
upstream = null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,7 +269,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, VpnListener.C
|
|||||||
receiverRegistered = true
|
receiverRegistered = true
|
||||||
try {
|
try {
|
||||||
if (initRouting(upstream!!, downstream, owner)) doStart(group)
|
if (initRouting(upstream!!, downstream, owner)) doStart(group)
|
||||||
else startFailure("Something went wrong, please check logcat.", group)
|
else startFailure(getText(R.string.noisy_su_failure), group)
|
||||||
} catch (e: Routing.InterfaceNotFoundException) {
|
} catch (e: Routing.InterfaceNotFoundException) {
|
||||||
startFailure(e.message, group)
|
startFailure(e.message, group)
|
||||||
return
|
return
|
||||||
@@ -323,7 +325,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, VpnListener.C
|
|||||||
VpnListener.unregisterCallback(this)
|
VpnListener.unregisterCallback(this)
|
||||||
unregisterReceiver()
|
unregisterReceiver()
|
||||||
if (routing?.stop() == false)
|
if (routing?.stop() == false)
|
||||||
Toast.makeText(this, "Something went wrong, please check logcat.", Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, getText(R.string.noisy_su_failure), Toast.LENGTH_SHORT).show()
|
||||||
routing = null
|
routing = null
|
||||||
status = Status.IDLE
|
status = Status.IDLE
|
||||||
stopForeground(true)
|
stopForeground(true)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package be.mygod.vpnhotspot
|
|||||||
import android.app.Service
|
import android.app.Service
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.support.v4.content.LocalBroadcastManager
|
import android.support.v4.content.LocalBroadcastManager
|
||||||
|
import android.widget.Toast
|
||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
|
|
||||||
class TetheringService : Service(), VpnListener.Callback {
|
class TetheringService : Service(), VpnListener.Callback {
|
||||||
@@ -26,7 +27,8 @@ class TetheringService : Service(), VpnListener.Callback {
|
|||||||
private val receiver = broadcastReceiver { _, intent ->
|
private val receiver = broadcastReceiver { _, intent ->
|
||||||
val remove = routings.keys - NetUtils.getTetheredIfaces(intent.extras)
|
val remove = routings.keys - NetUtils.getTetheredIfaces(intent.extras)
|
||||||
if (remove.isEmpty()) return@broadcastReceiver
|
if (remove.isEmpty()) return@broadcastReceiver
|
||||||
for (iface in remove) routings.remove(iface)?.stop()
|
val failed = remove.any { routings.remove(it)?.stop() == false }
|
||||||
|
if (failed) Toast.makeText(this, getText(R.string.noisy_su_failure), Toast.LENGTH_SHORT).show()
|
||||||
updateRoutings()
|
updateRoutings()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,10 +40,16 @@ class TetheringService : Service(), VpnListener.Callback {
|
|||||||
} else {
|
} else {
|
||||||
val upstream = upstream
|
val upstream = upstream
|
||||||
if (upstream != null) {
|
if (upstream != null) {
|
||||||
|
var failed = false
|
||||||
for ((downstream, value) in routings) if (value == null) {
|
for ((downstream, value) in routings) if (value == null) {
|
||||||
val routing = Routing(upstream, downstream).rule().forward().dnsRedirect(app.dns)
|
val routing = Routing(upstream, downstream).rule().forward().dnsRedirect(app.dns)
|
||||||
if (routing.start()) routings[downstream] = routing else routing.stop()
|
if (routing.start()) routings[downstream] = routing else {
|
||||||
|
failed = true
|
||||||
|
routing.stop()
|
||||||
|
routings.remove(downstream)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (failed) Toast.makeText(this, getText(R.string.noisy_su_failure), Toast.LENGTH_SHORT).show()
|
||||||
} else if (!receiverRegistered) {
|
} else if (!receiverRegistered) {
|
||||||
registerReceiver(receiver, intentFilter(NetUtils.ACTION_TETHER_STATE_CHANGED))
|
registerReceiver(receiver, intentFilter(NetUtils.ACTION_TETHER_STATE_CHANGED))
|
||||||
VpnListener.registerCallback(this)
|
VpnListener.registerCallback(this)
|
||||||
@@ -56,7 +64,8 @@ class TetheringService : Service(), VpnListener.Callback {
|
|||||||
if (intent != null) { // otw service is recreated after being killed
|
if (intent != null) { // otw service is recreated after being killed
|
||||||
val iface = intent.getStringExtra(EXTRA_ADD_INTERFACE)
|
val iface = intent.getStringExtra(EXTRA_ADD_INTERFACE)
|
||||||
if (iface != null) routings.put(iface, null)
|
if (iface != null) routings.put(iface, null)
|
||||||
routings.remove(intent.getStringExtra(EXTRA_REMOVE_INTERFACE))?.stop()
|
if (routings.remove(intent.getStringExtra(EXTRA_REMOVE_INTERFACE))?.stop() == false)
|
||||||
|
Toast.makeText(this, getText(R.string.noisy_su_failure), Toast.LENGTH_SHORT).show()
|
||||||
} else active.forEach { routings.put(it, null) }
|
} else active.forEach { routings.put(it, null) }
|
||||||
updateRoutings()
|
updateRoutings()
|
||||||
return START_STICKY
|
return START_STICKY
|
||||||
@@ -71,10 +80,12 @@ class TetheringService : Service(), VpnListener.Callback {
|
|||||||
override fun onLost(ifname: String) {
|
override fun onLost(ifname: String) {
|
||||||
check(upstream == null || upstream == ifname)
|
check(upstream == null || upstream == ifname)
|
||||||
upstream = null
|
upstream = null
|
||||||
|
var failed = false
|
||||||
for ((iface, routing) in routings) {
|
for ((iface, routing) in routings) {
|
||||||
routing?.stop()
|
if (routing?.stop() == false) failed = true
|
||||||
routings[iface] = null
|
routings[iface] = null
|
||||||
}
|
}
|
||||||
|
if (failed) Toast.makeText(this, getText(R.string.noisy_su_failure), Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
@@ -82,7 +93,7 @@ class TetheringService : Service(), VpnListener.Callback {
|
|||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unregisterReceiver() {
|
private fun unregisterReceiver() {
|
||||||
if (receiverRegistered) {
|
if (receiverRegistered) {
|
||||||
unregisterReceiver(receiver)
|
unregisterReceiver(receiver)
|
||||||
VpnListener.unregisterCallback(this)
|
VpnListener.unregisterCallback(this)
|
||||||
|
|||||||
@@ -8,4 +8,5 @@
|
|||||||
<string name="exception_interface_not_found">Fatal: Downstream interface not found</string>
|
<string name="exception_interface_not_found">Fatal: Downstream interface not found</string>
|
||||||
<string name="tethering_no_interfaces"><![CDATA[To use this feature, turn on any <a href="#">system
|
<string name="tethering_no_interfaces"><![CDATA[To use this feature, turn on any <a href="#">system
|
||||||
tethering</a> first.]]></string>
|
tethering</a> first.]]></string>
|
||||||
|
<string name="noisy_su_failure">Something went wrong, please check logcat.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user