mirror of https://github.com/M66B/FairEmail.git
Wait for installing security provider
This commit is contained in:
parent
2fc416933b
commit
ca352cd2b9
|
@ -1,4 +1,7 @@
|
|||
package eu.faircode.email;
|
||||
|
||||
public class ApplicationSecure extends ApplicationEx {
|
||||
public static boolean waitProviderInstalled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
package eu.faircode.email;
|
||||
|
||||
public class ApplicationSecure extends ApplicationEx {
|
||||
public static boolean waitProviderInstalled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1212,12 +1212,14 @@ public class EmailService implements AutoCloseable {
|
|||
|
||||
@Override
|
||||
public Socket createSocket(String host, int port) throws IOException {
|
||||
ApplicationSecure.waitProviderInstalled();
|
||||
return configure(factory.createSocket(server, port));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException {
|
||||
configureSocketOptions(s);
|
||||
ApplicationSecure.waitProviderInstalled();
|
||||
return configure(factory.createSocket(s, server, port, autoClose));
|
||||
}
|
||||
|
||||
|
@ -1229,6 +1231,7 @@ public class EmailService implements AutoCloseable {
|
|||
|
||||
@Override
|
||||
public Socket createSocket(String host, int port, InetAddress clientAddress, int clientPort) throws IOException {
|
||||
ApplicationSecure.waitProviderInstalled();
|
||||
return configure(factory.createSocket(server, port, clientAddress, clientPort));
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,12 @@ import android.content.Intent;
|
|||
|
||||
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 {
|
||||
private static final CountDownLatch lock = new CountDownLatch(1);
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
@ -15,6 +20,7 @@ public class ApplicationSecure extends ApplicationEx implements ProviderInstalle
|
|||
@Override
|
||||
public void onProviderInstalled() {
|
||||
Log.i("Security provider installed");
|
||||
lock.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -22,5 +28,18 @@ public class ApplicationSecure extends ApplicationEx implements ProviderInstalle
|
|||
Log.i("Security provider install failed" +
|
||||
" errorCode=" + errorCode +
|
||||
" 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…
Reference in New Issue