Refinements

This commit is contained in:
Mygod
2018-01-21 13:33:10 -08:00
parent de7c6c5d8c
commit 1e97032630
7 changed files with 42 additions and 25 deletions

View File

@@ -60,7 +60,7 @@ data class IpNeighbour(val ip: String, val dev: String, val lladdr: String, val
private const val ARP_CACHE_EXPIRE = 1L * 1000 * 1000 * 1000
private var arpCache = emptyList<List<String>>()
private var arpCacheTime = -ARP_CACHE_EXPIRE
fun arp(): List<List<String>> {
private fun arp(): List<List<String>> {
if (System.nanoTime() - arpCacheTime >= ARP_CACHE_EXPIRE) try {
arpCache = File("/proc/net/arp").bufferedReader().useLines {
it.map { it.split(spaces) }

View File

@@ -1,8 +1,9 @@
package be.mygod.vpnhotspot.net
import android.content.res.Resources
import be.mygod.vpnhotspot.App
import be.mygod.vpnhotspot.App.Companion.app
import be.mygod.vpnhotspot.R
import java.util.regex.Pattern
enum class TetherType {
NONE, WIFI_P2P, USB, WIFI, WIMAX, BLUETOOTH;
@@ -15,21 +16,30 @@ enum class TetherType {
}
companion object {
private val usbRegexes: List<Pattern>
private val wifiRegexes: List<Pattern>
private val wimaxRegexes: List<Pattern>
private val bluetoothRegexes: List<Pattern>
/**
* Source: https://android.googlesource.com/platform/frameworks/base/+/61fa313/core/res/res/values/config.xml#328
*/
private val usbRegexes = App.app.resources.getStringArray(Resources.getSystem()
.getIdentifier("config_tether_usb_regexs", "array", "android"))
.map { it.toPattern() }
private val wifiRegexes = App.app.resources.getStringArray(Resources.getSystem()
.getIdentifier("config_tether_wifi_regexs", "array", "android"))
.map { it.toPattern() }
private val wimaxRegexes = App.app.resources.getStringArray(Resources.getSystem()
.getIdentifier("config_tether_wimax_regexs", "array", "android"))
.map { it.toPattern() }
private val bluetoothRegexes = App.app.resources.getStringArray(Resources.getSystem()
.getIdentifier("config_tether_bluetooth_regexs", "array", "android"))
.map { it.toPattern() }
init {
val appRes = app.resources
val sysRes = Resources.getSystem()
usbRegexes = appRes.getStringArray(sysRes
.getIdentifier("config_tether_usb_regexs", "array", "android"))
.map { it.toPattern() }
wifiRegexes = appRes.getStringArray(sysRes
.getIdentifier("config_tether_wifi_regexs", "array", "android"))
.map { it.toPattern() }
wimaxRegexes = appRes.getStringArray(sysRes
.getIdentifier("config_tether_wimax_regexs", "array", "android"))
.map { it.toPattern() }
bluetoothRegexes = appRes.getStringArray(sysRes
.getIdentifier("config_tether_bluetooth_regexs", "array", "android"))
.map { it.toPattern() }
}
fun ofInterface(iface: String, p2pDev: String? = null) = when {
iface == p2pDev -> WIFI_P2P