Group net package
This commit is contained in:
@@ -23,6 +23,7 @@ import android.view.*
|
|||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
import be.mygod.vpnhotspot.databinding.FragmentRepeaterBinding
|
import be.mygod.vpnhotspot.databinding.FragmentRepeaterBinding
|
||||||
import be.mygod.vpnhotspot.databinding.ListitemClientBinding
|
import be.mygod.vpnhotspot.databinding.ListitemClientBinding
|
||||||
|
import be.mygod.vpnhotspot.net.NetUtils
|
||||||
|
|
||||||
class RepeaterFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClickListener {
|
class RepeaterFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClickListener {
|
||||||
inner class Data : BaseObservable() {
|
inner class Data : BaseObservable() {
|
||||||
|
|||||||
@@ -19,10 +19,12 @@ import android.support.v4.content.LocalBroadcastManager
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import be.mygod.vpnhotspot.App.Companion.app
|
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.InetAddress
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
|
|
||||||
class RepeaterService : Service(), WifiP2pManager.ChannelListener, VpnListener.Callback {
|
class RepeaterService : Service(), WifiP2pManager.ChannelListener, VpnMonitor.Callback {
|
||||||
companion object {
|
companion object {
|
||||||
const val CHANNEL = "repeater"
|
const val CHANNEL = "repeater"
|
||||||
const val ACTION_STATUS_CHANGED = "be.mygod.vpnhotspot.RepeaterService.STATUS_CHANGED"
|
const val ACTION_STATUS_CHANGED = "be.mygod.vpnhotspot.RepeaterService.STATUS_CHANGED"
|
||||||
@@ -189,7 +191,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, VpnListener.C
|
|||||||
if (status != Status.IDLE) return START_NOT_STICKY
|
if (status != Status.IDLE) return START_NOT_STICKY
|
||||||
status = Status.STARTING
|
status = Status.STARTING
|
||||||
handler.postDelayed(onVpnUnavailable, 4000)
|
handler.postDelayed(onVpnUnavailable, 4000)
|
||||||
VpnListener.registerCallback(this)
|
VpnMonitor.registerCallback(this)
|
||||||
return START_NOT_STICKY
|
return START_NOT_STICKY
|
||||||
}
|
}
|
||||||
private fun startFailure(msg: CharSequence?, group: WifiP2pGroup? = null) {
|
private fun startFailure(msg: CharSequence?, group: WifiP2pGroup? = null) {
|
||||||
@@ -336,7 +338,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, VpnListener.C
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
private fun clean() {
|
private fun clean() {
|
||||||
VpnListener.unregisterCallback(this)
|
VpnMonitor.unregisterCallback(this)
|
||||||
unregisterReceiver()
|
unregisterReceiver()
|
||||||
if (routing?.stop() == false)
|
if (routing?.stop() == false)
|
||||||
Toast.makeText(this, getText(R.string.noisy_su_failure), Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, getText(R.string.noisy_su_failure), Toast.LENGTH_SHORT).show()
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import android.support.customtabs.CustomTabsIntent
|
|||||||
import android.support.v4.content.ContextCompat
|
import android.support.v4.content.ContextCompat
|
||||||
import android.support.v4.content.LocalBroadcastManager
|
import android.support.v4.content.LocalBroadcastManager
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
import be.mygod.vpnhotspot.net.Routing
|
||||||
import com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers
|
import com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import android.view.ViewGroup
|
|||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
import be.mygod.vpnhotspot.databinding.FragmentTetheringBinding
|
import be.mygod.vpnhotspot.databinding.FragmentTetheringBinding
|
||||||
import be.mygod.vpnhotspot.databinding.ListitemInterfaceBinding
|
import be.mygod.vpnhotspot.databinding.ListitemInterfaceBinding
|
||||||
|
import be.mygod.vpnhotspot.net.NetUtils
|
||||||
|
|
||||||
class TetheringFragment : Fragment(), Toolbar.OnMenuItemClickListener {
|
class TetheringFragment : Fragment(), Toolbar.OnMenuItemClickListener {
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
@@ -5,8 +5,11 @@ import android.content.Intent
|
|||||||
import android.support.v4.content.LocalBroadcastManager
|
import android.support.v4.content.LocalBroadcastManager
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
|
import be.mygod.vpnhotspot.net.NetUtils
|
||||||
|
import be.mygod.vpnhotspot.net.Routing
|
||||||
|
import be.mygod.vpnhotspot.net.VpnMonitor
|
||||||
|
|
||||||
class TetheringService : Service(), VpnListener.Callback {
|
class TetheringService : Service(), VpnMonitor.Callback {
|
||||||
companion object {
|
companion object {
|
||||||
const val ACTION_ACTIVE_INTERFACES_CHANGED = "be.mygod.vpnhotspot.TetheringService.ACTIVE_INTERFACES_CHANGED"
|
const val ACTION_ACTIVE_INTERFACES_CHANGED = "be.mygod.vpnhotspot.TetheringService.ACTIVE_INTERFACES_CHANGED"
|
||||||
const val EXTRA_ADD_INTERFACE = "interface.add"
|
const val EXTRA_ADD_INTERFACE = "interface.add"
|
||||||
@@ -62,7 +65,7 @@ class TetheringService : Service(), VpnListener.Callback {
|
|||||||
registerReceiver(receiver, intentFilter(NetUtils.ACTION_TETHER_STATE_CHANGED))
|
registerReceiver(receiver, intentFilter(NetUtils.ACTION_TETHER_STATE_CHANGED))
|
||||||
LocalBroadcastManager.getInstance(this)
|
LocalBroadcastManager.getInstance(this)
|
||||||
.registerReceiver(receiver, intentFilter(App.ACTION_CLEAN_ROUTINGS))
|
.registerReceiver(receiver, intentFilter(App.ACTION_CLEAN_ROUTINGS))
|
||||||
VpnListener.registerCallback(this)
|
VpnMonitor.registerCallback(this)
|
||||||
receiverRegistered = true
|
receiverRegistered = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,7 +117,7 @@ class TetheringService : Service(), VpnListener.Callback {
|
|||||||
if (receiverRegistered) {
|
if (receiverRegistered) {
|
||||||
unregisterReceiver(receiver)
|
unregisterReceiver(receiver)
|
||||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(receiver)
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(receiver)
|
||||||
VpnListener.unregisterCallback(this)
|
VpnMonitor.unregisterCallback(this)
|
||||||
upstream = null
|
upstream = null
|
||||||
receiverRegistered = false
|
receiverRegistered = false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package be.mygod.vpnhotspot
|
package be.mygod.vpnhotspot.net
|
||||||
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
package be.mygod.vpnhotspot
|
package be.mygod.vpnhotspot.net
|
||||||
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
|
import be.mygod.vpnhotspot.R
|
||||||
|
import be.mygod.vpnhotspot.noisySu
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.net.Inet4Address
|
import java.net.Inet4Address
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
@@ -12,6 +14,7 @@ class Routing(private val upstream: String, val downstream: String, ownerAddress
|
|||||||
companion object {
|
companion object {
|
||||||
/**
|
/**
|
||||||
* -w <seconds> is not supported on 7.1-.
|
* -w <seconds> is not supported on 7.1-.
|
||||||
|
* Fortunately there also isn't a time limit for starting a foreground service back in 7.1-.
|
||||||
*
|
*
|
||||||
* Source: https://android.googlesource.com/platform/external/iptables/+/android-5.0.0_r1/iptables/iptables.c#1574
|
* Source: https://android.googlesource.com/platform/external/iptables/+/android-5.0.0_r1/iptables/iptables.c#1574
|
||||||
*/
|
*/
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package be.mygod.vpnhotspot
|
package be.mygod.vpnhotspot.net
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.net.ConnectivityManager
|
import android.net.ConnectivityManager
|
||||||
@@ -6,14 +6,15 @@ import android.net.Network
|
|||||||
import android.net.NetworkCapabilities
|
import android.net.NetworkCapabilities
|
||||||
import android.net.NetworkRequest
|
import android.net.NetworkRequest
|
||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
|
import be.mygod.vpnhotspot.debugLog
|
||||||
|
|
||||||
object VpnListener : ConnectivityManager.NetworkCallback() {
|
object VpnMonitor : ConnectivityManager.NetworkCallback() {
|
||||||
interface Callback {
|
interface Callback {
|
||||||
fun onAvailable(ifname: String)
|
fun onAvailable(ifname: String)
|
||||||
fun onLost(ifname: String)
|
fun onLost(ifname: String)
|
||||||
}
|
}
|
||||||
|
|
||||||
private const val TAG = "VpnListener"
|
private const val TAG = "VpnMonitor"
|
||||||
|
|
||||||
val connectivityManager = app.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
val connectivityManager = app.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||||
private val request by lazy {
|
private val request by lazy {
|
||||||
Reference in New Issue
Block a user