Wait for installing security provider

pull/214/head
M66B 1 year ago
parent 2fc416933b
commit ca352cd2b9

@ -1,4 +1,7 @@
package eu.faircode.email; package eu.faircode.email;
public class ApplicationSecure extends ApplicationEx { public class ApplicationSecure extends ApplicationEx {
public static boolean waitProviderInstalled() {
return true;
}
} }

@ -1,4 +1,7 @@
package eu.faircode.email; package eu.faircode.email;
public class ApplicationSecure extends ApplicationEx { public class ApplicationSecure extends ApplicationEx {
public static boolean waitProviderInstalled() {
return true;
}
} }

@ -1212,12 +1212,14 @@ public class EmailService implements AutoCloseable {
@Override @Override
public Socket createSocket(String host, int port) throws IOException { public Socket createSocket(String host, int port) throws IOException {
ApplicationSecure.waitProviderInstalled();
return configure(factory.createSocket(server, port)); return configure(factory.createSocket(server, port));
} }
@Override @Override
public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException { public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException {
configureSocketOptions(s); configureSocketOptions(s);
ApplicationSecure.waitProviderInstalled();
return configure(factory.createSocket(s, server, port, autoClose)); return configure(factory.createSocket(s, server, port, autoClose));
} }
@ -1229,6 +1231,7 @@ public class EmailService implements AutoCloseable {
@Override @Override
public Socket createSocket(String host, int port, InetAddress clientAddress, int clientPort) throws IOException { public Socket createSocket(String host, int port, InetAddress clientAddress, int clientPort) throws IOException {
ApplicationSecure.waitProviderInstalled();
return configure(factory.createSocket(server, port, clientAddress, clientPort)); return configure(factory.createSocket(server, port, clientAddress, clientPort));
} }

@ -4,7 +4,12 @@ import android.content.Intent;
import com.google.android.gms.security.ProviderInstaller; import com.google.android.gms.security.ProviderInstaller;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
public class ApplicationSecure extends ApplicationEx implements ProviderInstaller.ProviderInstallListener { public class ApplicationSecure extends ApplicationEx implements ProviderInstaller.ProviderInstallListener {
private static final CountDownLatch lock = new CountDownLatch(1);
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
@ -15,6 +20,7 @@ public class ApplicationSecure extends ApplicationEx implements ProviderInstalle
@Override @Override
public void onProviderInstalled() { public void onProviderInstalled() {
Log.i("Security provider installed"); Log.i("Security provider installed");
lock.countDown();
} }
@Override @Override
@ -22,5 +28,18 @@ public class ApplicationSecure extends ApplicationEx implements ProviderInstalle
Log.i("Security provider install failed" + Log.i("Security provider install failed" +
" errorCode=" + errorCode + " errorCode=" + errorCode +
" recoveryIntent=" + recoveryIntent); " recoveryIntent=" + recoveryIntent);
lock.countDown();
}
public static boolean waitProviderInstalled() {
Log.i("Security provider wait");
try {
boolean succeeded = lock.await(500L, TimeUnit.MILLISECONDS);
Log.i("Security provider wait succeeded=" + succeeded);
return succeeded;
} catch (InterruptedException ex) {
Log.e(ex);
return false;
}
} }
} }

Loading…
Cancel
Save