feat: Add Back Disable Proxy When Vpn Enabled
This commit is contained in:
parent
cf31615891
commit
cb5621bc6d
@ -35,6 +35,7 @@ import android.location.Location;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.location.LocationManager;
|
||||
import android.media.AudioManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
@ -192,7 +193,9 @@ import tw.nekomimi.nekogram.proxy.SubInfo;
|
||||
import tw.nekomimi.nekogram.proxy.SubManager;
|
||||
import tw.nekomimi.nekogram.utils.AlertUtil;
|
||||
import tw.nekomimi.nekogram.utils.MonetHelper;
|
||||
import tw.nekomimi.nekogram.utils.ProxyUtil;
|
||||
import tw.nekomimi.nekogram.utils.UIUtil;
|
||||
import xyz.nextalone.nagram.NaConfig;
|
||||
|
||||
public class LaunchActivity extends BasePermissionsActivity implements ActionBarLayout.ActionBarLayoutDelegate, NotificationCenter.NotificationCenterDelegate, DialogsActivity.DialogsActivityDelegate {
|
||||
public final static Pattern PREFIX_T_ME_PATTERN = Pattern.compile("^(?:http(?:s|)://|)([A-z0-9-]+?)\\.t\\.me");
|
||||
@ -5161,6 +5164,16 @@ public class LaunchActivity extends BasePermissionsActivity implements ActionBar
|
||||
passcodeView.onResume();
|
||||
}
|
||||
|
||||
if (NaConfig.INSTANCE.getDisableProxyWhenVpnEnabled().Bool()) {
|
||||
if (SharedConfig.proxyEnabled && ProxyUtil.isVPNEnabled()) {
|
||||
SharedConfig.setProxyEnable(false);
|
||||
} else if (!ProxyUtil.isVPNEnabled()) {
|
||||
SharedConfig.setProxyEnable(true);
|
||||
}
|
||||
ProxyUtil.registerNetworkCallback();
|
||||
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.proxySettingsChanged);
|
||||
}
|
||||
|
||||
ConnectionsManager.getInstance(currentAccount).setAppPaused(false, false);
|
||||
updateCurrentConnectionState(currentAccount);
|
||||
|
||||
|
@ -120,6 +120,7 @@ public class NekoGeneralSettingsActivity extends BaseFragment {
|
||||
private final AbstractConfigCell hideProxyByDefaultRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.hideProxyByDefault));
|
||||
private final AbstractConfigCell autoUpdateSubInfoRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.autoUpdateSubInfo));
|
||||
private final AbstractConfigCell useSystemDNSRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.useSystemDNS));
|
||||
private final AbstractConfigCell disableProxyWhenVpnEnabledRow = cellGroup.appendCell(new ConfigCellTextCheck(NaConfig.INSTANCE.getDisableProxyWhenVpnEnabled()));
|
||||
private final AbstractConfigCell customDoHRow = cellGroup.appendCell(new ConfigCellTextInput(null, NekoConfig.customDoH, "https://1.0.0.1/dns-query", null));
|
||||
private final AbstractConfigCell customPublicProxyIPRow = cellGroup.appendCell(new ConfigCellTextDetail(NekoConfig.customPublicProxyIP, (view, position) -> {
|
||||
customDialog_BottomInputString(position, NekoConfig.customPublicProxyIP, LocaleController.getString("customPublicProxyIPNotice"), "IP");
|
||||
|
@ -13,6 +13,10 @@ import android.content.pm.PackageManager
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.net.ConnectivityManager
|
||||
import android.net.Network
|
||||
import android.net.NetworkCapabilities
|
||||
import android.net.NetworkRequest
|
||||
import android.os.Build
|
||||
import android.os.Environment
|
||||
import android.util.Base64
|
||||
@ -43,35 +47,64 @@ import org.json.JSONException
|
||||
import org.telegram.messenger.*
|
||||
import org.telegram.messenger.browser.Browser
|
||||
import org.yaml.snakeyaml.Yaml
|
||||
import tw.nekomimi.nekogram.ui.BottomBuilder
|
||||
import tw.nekomimi.nekogram.proxy.ShadowsocksLoader
|
||||
import tw.nekomimi.nekogram.proxy.ShadowsocksRLoader
|
||||
import tw.nekomimi.nekogram.ui.BottomBuilder
|
||||
import tw.nekomimi.nekogram.utils.AlertUtil.showToast
|
||||
import java.io.File
|
||||
import java.net.NetworkInterface
|
||||
import java.util.*
|
||||
import kotlin.collections.HashMap
|
||||
|
||||
|
||||
object ProxyUtil {
|
||||
|
||||
@JvmStatic
|
||||
fun isVPNEnabled(): Boolean {
|
||||
|
||||
val networkList = mutableListOf<String>()
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||
return false
|
||||
}
|
||||
runCatching {
|
||||
val connectivityManager = ApplicationLoader.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||
val network = connectivityManager.activeNetwork
|
||||
val networkCapabilities = connectivityManager.getNetworkCapabilities(network)
|
||||
return networkCapabilities!!.hasTransport(NetworkCapabilities.TRANSPORT_VPN)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Collections.list(NetworkInterface.getNetworkInterfaces()).forEach {
|
||||
|
||||
if (it.isUp) networkList.add(it.name)
|
||||
|
||||
@JvmStatic
|
||||
fun registerNetworkCallback() {
|
||||
val connectivityManager = ApplicationLoader.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||
val networkCallback: ConnectivityManager.NetworkCallback =
|
||||
object : ConnectivityManager.NetworkCallback() {
|
||||
override fun onAvailable(network: Network) {
|
||||
val networkCapabilities = connectivityManager.getNetworkCapabilities(network)
|
||||
val vpn = networkCapabilities!!.hasTransport(NetworkCapabilities.TRANSPORT_VPN)
|
||||
if (!vpn) {
|
||||
if (SharedConfig.currentProxy == null) {
|
||||
if (!SharedConfig.proxyList.isEmpty()) {
|
||||
SharedConfig.setCurrentProxy(SharedConfig.proxyList[0])
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((SharedConfig.proxyEnabled && vpn) || (!SharedConfig.proxyEnabled && !vpn)) {
|
||||
SharedConfig.setProxyEnable(!vpn)
|
||||
UIUtil.runOnUIThread(Runnable {
|
||||
NotificationCenter.getGlobalInstance()
|
||||
.postNotificationName(NotificationCenter.proxySettingsChanged)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
connectivityManager.registerDefaultNetworkCallback(networkCallback)
|
||||
} else {
|
||||
val request: NetworkRequest = NetworkRequest.Builder()
|
||||
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET).build()
|
||||
connectivityManager.registerNetworkCallback(request, networkCallback)
|
||||
}
|
||||
|
||||
return networkList.contains("tun0")
|
||||
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
@ -328,6 +328,12 @@ object NaConfig {
|
||||
ConfigItem.configTypeBool,
|
||||
false
|
||||
)
|
||||
val disableProxyWhenVpnEnabled =
|
||||
addConfig(
|
||||
"DisableProxyWhenVpnEnabled",
|
||||
ConfigItem.configTypeBool,
|
||||
false
|
||||
)
|
||||
|
||||
private fun addConfig(
|
||||
k: String,
|
||||
|
Loading…
Reference in New Issue
Block a user