Added debug option to bind sockets to active network

This commit is contained in:
M66B
2021-09-02 21:31:06 +02:00
parent 0c25724063
commit a2c3f642e0
6 changed files with 51 additions and 5 deletions

View File

@@ -24,6 +24,10 @@ import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_OAUTH;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.ParcelFileDescriptor;
import android.security.KeyChain;
import android.system.ErrnoException;
@@ -353,6 +357,19 @@ public class EmailService implements AutoCloseable {
String certificate, String fingerprint) throws MessagingException {
properties.put("fairemail.server", host);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean bind_socket = prefs.getBoolean("bind_socket", false);
if (bind_socket &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
try {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Network active = cm.getActiveNetwork();
if (active != null)
properties.put("fairemail.factory", active.getSocketFactory());
} catch (Throwable ex) {
Log.e(ex);
}
SSLSocketFactoryService factory = null;
try {
PrivateKey key = null;