-
-
Save not1337/50a9e1d2cd0091500c5848d08d5e7848 to your computer and use it in GitHub Desktop.
vpn detection and handling patch for linphone-android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- linphone-android.orig/src/org/linphone/LinphoneManager.java 2017-03-03 17:48:11.885210993 +0100 | |
+++ linphone-android/src/org/linphone/LinphoneManager.java 2017-03-03 17:48:36.764415691 +0100 | |
@@ -94,6 +94,7 @@ | |
import android.media.AudioManager; | |
import android.media.MediaPlayer; | |
import android.net.ConnectivityManager; | |
+import android.net.Network; | |
import android.net.NetworkInfo; | |
import android.net.Uri; | |
import android.os.Build; | |
@@ -142,6 +143,7 @@ | |
private boolean echoTesterIsRunning; | |
private boolean dozeModeEnabled; | |
private int mLastNetworkType=-1; | |
+ private int mLastVPNState=-1; | |
private ConnectivityManager mConnectivityManager; | |
private BroadcastReceiver mKeepAliveReceiver; | |
private BroadcastReceiver mDozeReceiver; | |
@@ -888,6 +890,39 @@ | |
return false; | |
} | |
+ private int isVPNrunning() { | |
+ int vpn = 0; | |
+ | |
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { | |
+ Network[] nw; | |
+ NetworkInfo ni; | |
+ int i; | |
+ | |
+ nw = mConnectivityManager.getAllNetworks(); | |
+ for (i=0;i<nw.length;i++) { | |
+ ni = mConnectivityManager.getNetworkInfo(nw[i]); | |
+ if(ni.isConnectedOrConnecting()) { | |
+ if (ni.getType()==ConnectivityManager.TYPE_VPN) { | |
+ vpn=1; | |
+ } | |
+ } | |
+ } | |
+ } else if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { | |
+ NetworkInfo[] nw; | |
+ int i; | |
+ | |
+ nw = mConnectivityManager.getAllNetworkInfo(); | |
+ for (i=0;i<nw.length;i++) { | |
+ if (nw[i].isConnectedOrConnecting()) { | |
+ if (nw[i].getType()==ConnectivityManager.TYPE_VPN) { | |
+ vpn=1; | |
+ } | |
+ } | |
+ } | |
+ } | |
+ return vpn; | |
+ } | |
+ | |
public void updateNetworkReachability() { | |
if (mConnectivityManager == null) return; | |
@@ -896,10 +931,23 @@ | |
if (networkInfo == null || !networkInfo.isConnected()) { | |
Log.i("No connectivity: setting network unreachable"); | |
mLc.setNetworkReachable(false); | |
+ mLastVPNState=-1; | |
} else if (dozeModeEnabled) { | |
Log.i("Doze Mode enabled: shutting down network"); | |
mLc.setNetworkReachable(false); | |
+ mLastVPNState=-1; | |
}else if (networkInfo.isConnected()){ | |
+ int curstate=isVPNrunning(); | |
+ if (curstate!=mLastVPNState) { | |
+ if (mLastVPNState!=-1) { | |
+ mLc.setNetworkReachable(false); | |
+ } | |
+ if (curstate!=0||mLastVPNState!=-1) { | |
+ setDnsServers(); | |
+ } | |
+ mLastVPNState=curstate; | |
+ } | |
+ | |
manageTunnelServer(networkInfo); | |
boolean wifiOnly = LinphonePreferences.instance().isWifiOnlyEnabled(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment