mirror of https://github.com/M66B/FairEmail.git
Check for VPN
This commit is contained in:
parent
2460e6c08d
commit
033efe23d3
|
@ -277,6 +277,24 @@ public class ConnectionHelper {
|
|||
return true;
|
||||
}
|
||||
|
||||
static boolean vpnActive(Context context) {
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
if (cm == null)
|
||||
return false;
|
||||
|
||||
try {
|
||||
for (Network network : cm.getAllNetworks()) {
|
||||
NetworkCapabilities caps = cm.getNetworkCapabilities(network);
|
||||
if (caps != null && caps.hasTransport(NetworkCapabilities.TRANSPORT_VPN))
|
||||
return true;
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static boolean airplaneMode(Context context) {
|
||||
return Settings.System.getInt(context.getContentResolver(),
|
||||
Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
|
||||
|
|
|
@ -14,6 +14,8 @@ import androidx.preference.PreferenceManager;
|
|||
import com.sun.mail.imap.IMAPFolder;
|
||||
import com.sun.mail.imap.IMAPStore;
|
||||
import com.sun.mail.smtp.SMTPTransport;
|
||||
import com.sun.mail.util.MailConnectException;
|
||||
import com.sun.mail.util.SocketConnectException;
|
||||
|
||||
import net.openid.appauth.AuthState;
|
||||
import net.openid.appauth.AuthorizationException;
|
||||
|
@ -329,6 +331,18 @@ public class EmailService implements AutoCloseable {
|
|||
return authState.jsonSerializeString();
|
||||
} else
|
||||
throw ex;
|
||||
} catch (MailConnectException ex) {
|
||||
if (ConnectionHelper.vpnActive(context)) {
|
||||
MailConnectException mex = new MailConnectException(new SocketConnectException(
|
||||
"The might be caused by the VPN in use",
|
||||
new Exception(),
|
||||
ex.getHost(),
|
||||
ex.getPort(),
|
||||
ex.getConnectionTimeout()));
|
||||
mex.setNextException(ex.getNextException());
|
||||
throw mex;
|
||||
} else
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -969,6 +969,8 @@ public class Log {
|
|||
NetworkCapabilities caps = cm.getNetworkCapabilities(network);
|
||||
size += write(os, (network.equals(active) ? "active=" : "network=") + network + " capabilities=" + caps + "\r\n\r\n");
|
||||
}
|
||||
|
||||
size += write(os, "VPN active=" + ConnectionHelper.vpnActive(context) + "\r\n\r\n");
|
||||
}
|
||||
|
||||
db.attachment().setDownloaded(attachment.id, size);
|
||||
|
|
Loading…
Reference in New Issue