mirror of
https://github.com/MatsuriDayo/NekoBoxForAndroid.git
synced 2025-12-19 22:50:05 +08:00
updateUnderlyingNetwork
This commit is contained in:
parent
be5962df8b
commit
796a9cd9b0
@ -246,6 +246,9 @@ class BaseService {
|
|||||||
suspend fun preInit() {
|
suspend fun preInit() {
|
||||||
DefaultNetworkListener.start(this) {
|
DefaultNetworkListener.start(this) {
|
||||||
SagerNet.connectivity.getLinkProperties(it)?.also { link ->
|
SagerNet.connectivity.getLinkProperties(it)?.also { link ->
|
||||||
|
SagerNet.underlyingNetwork = it
|
||||||
|
DataStore.vpnService?.updateUnderlyingNetwork()
|
||||||
|
//
|
||||||
val oldName = upstreamInterfaceName
|
val oldName = upstreamInterfaceName
|
||||||
if (oldName != link.interfaceName) {
|
if (oldName != link.interfaceName) {
|
||||||
upstreamInterfaceName = link.interfaceName
|
upstreamInterfaceName = link.interfaceName
|
||||||
|
|||||||
@ -127,13 +127,7 @@ class VpnService : BaseVpnService(),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ?
|
updateUnderlyingNetwork(builder)
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
|
||||||
// TODO listen for change?
|
|
||||||
if (SagerNet.underlyingNetwork != null) {
|
|
||||||
builder.setUnderlyingNetworks(arrayOf(SagerNet.underlyingNetwork))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) builder.setMetered(metered)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) builder.setMetered(metered)
|
||||||
|
|
||||||
// app route
|
// app route
|
||||||
@ -212,51 +206,14 @@ class VpnService : BaseVpnService(),
|
|||||||
return conn!!.fd
|
return conn!!.fd
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
fun updateUnderlyingNetwork(builder: Builder? = null) {
|
||||||
// val appStats = mutableListOf<AppStats>()
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||||
//
|
SagerNet.underlyingNetwork?.let {
|
||||||
// override fun updateStats(stats: AppStats) {
|
builder?.setUnderlyingNetworks(arrayOf(SagerNet.underlyingNetwork))
|
||||||
// appStats.add(stats)
|
?: setUnderlyingNetworks(arrayOf(SagerNet.underlyingNetwork))
|
||||||
// }
|
}
|
||||||
//
|
}
|
||||||
// fun persistAppStats() {
|
}
|
||||||
// if (!DataStore.appTrafficStatistics) return
|
|
||||||
// val tun = getTun() ?: return
|
|
||||||
// appStats.clear()
|
|
||||||
// tun.readAppTraffics(this)
|
|
||||||
// val toUpdate = mutableListOf<StatsEntity>()
|
|
||||||
// val all = SagerDatabase.statsDao.all().associateBy { it.packageName }
|
|
||||||
// for (stats in appStats) {
|
|
||||||
// if (stats.nekoConnectionsJSON.isNotBlank()) continue
|
|
||||||
// val packageName = if (stats.uid >= 10000) {
|
|
||||||
// PackageCache.uidMap[stats.uid]?.iterator()?.next() ?: "android"
|
|
||||||
// } else {
|
|
||||||
// "android"
|
|
||||||
// }
|
|
||||||
// if (!all.containsKey(packageName)) {
|
|
||||||
// SagerDatabase.statsDao.create(
|
|
||||||
// StatsEntity(
|
|
||||||
// packageName = packageName,
|
|
||||||
// tcpConnections = stats.tcpConnTotal,
|
|
||||||
// udpConnections = stats.udpConnTotal,
|
|
||||||
// uplink = stats.uplinkTotal,
|
|
||||||
// downlink = stats.downlinkTotal
|
|
||||||
// )
|
|
||||||
// )
|
|
||||||
// } else {
|
|
||||||
// val entity = all[packageName]!!
|
|
||||||
// entity.tcpConnections += stats.tcpConnTotal
|
|
||||||
// entity.udpConnections += stats.udpConnTotal
|
|
||||||
// entity.uplink += stats.uplinkTotal
|
|
||||||
// entity.downlink += stats.downlinkTotal
|
|
||||||
// toUpdate.add(entity)
|
|
||||||
// }
|
|
||||||
// if (toUpdate.isNotEmpty()) {
|
|
||||||
// SagerDatabase.statsDao.update(toUpdate)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
override fun onRevoke() = stopRunner()
|
override fun onRevoke() = stopRunner()
|
||||||
|
|
||||||
|
|||||||
@ -224,9 +224,7 @@ fun Project.setupApp() {
|
|||||||
productFlavors {
|
productFlavors {
|
||||||
create("oss")
|
create("oss")
|
||||||
create("fdroid")
|
create("fdroid")
|
||||||
create("play") {
|
create("play")
|
||||||
versionCode = verCode + 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
applicationVariants.all {
|
applicationVariants.all {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user