Preliminary support for stacked links

This commit is contained in:
Mygod
2020-09-11 11:05:38 +08:00
parent 8e0eb1c0bc
commit 2225e6c80e
5 changed files with 18 additions and 4 deletions

View File

@@ -190,6 +190,8 @@ Greylisted/blacklisted APIs or internal constants: (some constants are hardcoded
* (since API 24, prior to API 30) [`Landroid/net/ConnectivityManager$OnStartTetheringCallback;->onTetheringStarted()V,system-api,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/4601d91/appcompat/hiddenapi-flags.csv#144097) * (since API 24, prior to API 30) [`Landroid/net/ConnectivityManager$OnStartTetheringCallback;->onTetheringStarted()V,system-api,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/4601d91/appcompat/hiddenapi-flags.csv#144097)
* (since API 24, prior to API 30) [`Landroid/net/ConnectivityManager;->startTethering(IZLandroid/net/ConnectivityManager$OnStartTetheringCallback;Landroid/os/Handler;)V,system-api,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/4601d91/appcompat/hiddenapi-flags.csv#144406) * (since API 24, prior to API 30) [`Landroid/net/ConnectivityManager;->startTethering(IZLandroid/net/ConnectivityManager$OnStartTetheringCallback;Landroid/os/Handler;)V,system-api,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/4601d91/appcompat/hiddenapi-flags.csv#144406)
* (since API 24, prior to API 30) [`Landroid/net/ConnectivityManager;->stopTethering(I)V,system-api,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/4601d91/appcompat/hiddenapi-flags.csv#144408) * (since API 24, prior to API 30) [`Landroid/net/ConnectivityManager;->stopTethering(I)V,system-api,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/4601d91/appcompat/hiddenapi-flags.csv#144408)
* [`Landroid/net/LinkProperties;->getAllInterfaceNames()Ljava/util/List;,system-api,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/4601d91/appcompat/hiddenapi-flags.csv#146558)
* [`Landroid/net/LinkProperties;->getAllRoutes()Ljava/util/List;,system-api,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/4601d91/appcompat/hiddenapi-flags.csv#146560)
* (since API 30) [`Landroid/net/TetheringManager$StartTetheringCallback;->onTetheringFailed(I)V,system-api,test-api,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/4601d91/appcompat/hiddenapi-flags.csv#148881) * (since API 30) [`Landroid/net/TetheringManager$StartTetheringCallback;->onTetheringFailed(I)V,system-api,test-api,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/4601d91/appcompat/hiddenapi-flags.csv#148881)
* (since API 30) [`Landroid/net/TetheringManager$StartTetheringCallback;->onTetheringStarted()V,system-api,test-api,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/4601d91/appcompat/hiddenapi-flags.csv#148882) * (since API 30) [`Landroid/net/TetheringManager$StartTetheringCallback;->onTetheringStarted()V,system-api,test-api,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/4601d91/appcompat/hiddenapi-flags.csv#148882)
* (since API 30) [`Landroid/net/TetheringManager$TetheringEventCallback;->onClientsChanged(Ljava/util/Collection;)V,system-api,test-api,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/4601d91/appcompat/hiddenapi-flags.csv#148896) * (since API 30) [`Landroid/net/TetheringManager$TetheringEventCallback;->onClientsChanged(Ljava/util/Collection;)V,system-api,test-api,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/4601d91/appcompat/hiddenapi-flags.csv#148896)

View File

@@ -20,6 +20,7 @@ import be.mygod.vpnhotspot.preference.SummaryFallbackProvider
import be.mygod.vpnhotspot.root.Dump import be.mygod.vpnhotspot.root.Dump
import be.mygod.vpnhotspot.root.RootManager import be.mygod.vpnhotspot.root.RootManager
import be.mygod.vpnhotspot.util.Services import be.mygod.vpnhotspot.util.Services
import be.mygod.vpnhotspot.util.allInterfaceNames
import be.mygod.vpnhotspot.util.launchUrl import be.mygod.vpnhotspot.util.launchUrl
import be.mygod.vpnhotspot.util.showAllowingStateLoss import be.mygod.vpnhotspot.util.showAllowingStateLoss
import be.mygod.vpnhotspot.widget.SmartSnackbar import be.mygod.vpnhotspot.widget.SmartSnackbar
@@ -148,8 +149,8 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() {
UpstreamMonitor.KEY, FallbackUpstreamMonitor.KEY -> UpstreamMonitor.KEY, FallbackUpstreamMonitor.KEY ->
AlwaysAutoCompleteEditTextPreferenceDialogFragment().apply { AlwaysAutoCompleteEditTextPreferenceDialogFragment().apply {
setArguments(preference.key, Services.connectivity.allNetworks.mapNotNull { setArguments(preference.key, Services.connectivity.allNetworks.mapNotNull {
Services.connectivity.getLinkProperties(it)?.interfaceName Services.connectivity.getLinkProperties(it)?.allInterfaceNames
}.toTypedArray()) }.flatten().toTypedArray())
setTargetFragment(this@SettingsPreferenceFragment, 0) setTargetFragment(this@SettingsPreferenceFragment, 0)
}.showAllowingStateLoss(parentFragmentManager, preference.key) }.showAllowingStateLoss(parentFragmentManager, preference.key)
else -> super.onDisplayPreferenceDialog(preference) else -> super.onDisplayPreferenceDialog(preference)

View File

@@ -2,6 +2,7 @@ package be.mygod.vpnhotspot.net.monitor
import android.net.LinkProperties import android.net.LinkProperties
import be.mygod.vpnhotspot.util.Services import be.mygod.vpnhotspot.util.Services
import be.mygod.vpnhotspot.util.allInterfaceNames
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@@ -29,7 +30,7 @@ class InterfaceMonitor(val iface: String) : UpstreamMonitor() {
private set private set
override val currentLinkProperties get() = Services.connectivity.allNetworks override val currentLinkProperties get() = Services.connectivity.allNetworks
.map { Services.connectivity.getLinkProperties(it) } .map { Services.connectivity.getLinkProperties(it) }
.singleOrNull { it?.interfaceName == iface } .singleOrNull { it?.allInterfaceNames?.contains(iface) == true }
override fun registerCallbackLocked(callback: Callback) { override fun registerCallbackLocked(callback: Callback) {
if (!registered) { if (!registered) {

View File

@@ -14,6 +14,7 @@ import be.mygod.vpnhotspot.R
import be.mygod.vpnhotspot.net.monitor.FallbackUpstreamMonitor import be.mygod.vpnhotspot.net.monitor.FallbackUpstreamMonitor
import be.mygod.vpnhotspot.net.monitor.UpstreamMonitor import be.mygod.vpnhotspot.net.monitor.UpstreamMonitor
import be.mygod.vpnhotspot.util.SpanFormatter import be.mygod.vpnhotspot.util.SpanFormatter
import be.mygod.vpnhotspot.util.allRoutes
import be.mygod.vpnhotspot.util.parseNumericAddress import be.mygod.vpnhotspot.util.parseNumericAddress
import timber.log.Timber import timber.log.Timber
@@ -33,7 +34,7 @@ class UpstreamsPreference(context: Context, attrs: AttributeSet) : Preference(co
} ?: "" } ?: ""
override fun onAvailable(ifname: String, properties: LinkProperties) { override fun onAvailable(ifname: String, properties: LinkProperties) {
currentInterface = Interface(ifname, properties.routes.any { currentInterface = Interface(ifname, properties.allRoutes.any {
try { try {
it.matches(internetAddress) it.matches(internetAddress)
} catch (e: RuntimeException) { } catch (e: RuntimeException) {

View File

@@ -4,6 +4,8 @@ import android.annotation.SuppressLint
import android.annotation.TargetApi import android.annotation.TargetApi
import android.content.* import android.content.*
import android.net.InetAddresses import android.net.InetAddresses
import android.net.LinkProperties
import android.net.RouteInfo
import android.os.Build import android.os.Build
import android.os.Handler import android.os.Handler
import android.os.RemoteException import android.os.RemoteException
@@ -109,6 +111,13 @@ fun parseNumericAddress(address: String) = if (Build.VERSION.SDK_INT >= 29) {
InetAddresses.parseNumericAddress(address) InetAddresses.parseNumericAddress(address)
} else parseNumericAddress(null, address) as InetAddress } else parseNumericAddress(null, address) as InetAddress
private val getAllInterfaceNames by lazy { LinkProperties::class.java.getDeclaredMethod("getAllInterfaceNames") }
@Suppress("UNCHECKED_CAST")
val LinkProperties.allInterfaceNames get() = getAllInterfaceNames.invoke(this) as List<String>
private val getAllRoutes by lazy { LinkProperties::class.java.getDeclaredMethod("getAllRoutes") }
@Suppress("UNCHECKED_CAST")
val LinkProperties.allRoutes get() = getAllRoutes.invoke(this) as List<RouteInfo>
fun Context.launchUrl(url: String) { fun Context.launchUrl(url: String) {
if (app.hasTouch) try { if (app.hasTouch) try {
app.customTabsIntent.launchUrl(this, url.toUri()) app.customTabsIntent.launchUrl(this, url.toUri())