Search in sources :

Example 1 with OnBound

use of org.openintents.openpgp.util.OpenPgpServiceConnection.OnBound in project k-9 by k9mail.

the class OpenPgpApiManager method setupCryptoProvider.

private void setupCryptoProvider() {
    if (TextUtils.isEmpty(openPgpProvider)) {
        setOpenPgpProviderState(OpenPgpProviderState.UNCONFIGURED);
        return;
    }
    boolean providerIsBound = openPgpServiceConnection != null && openPgpServiceConnection.isBound();
    if (providerIsBound) {
        refreshConnection();
        return;
    }
    if (openPgpServiceConnection != null) {
        // We'll just wait for OnBound.onBound() to be called.
        return;
    }
    setOpenPgpProviderState(OpenPgpProviderState.UNINITIALIZED);
    openPgpServiceConnection = new OpenPgpServiceConnection(context, openPgpProvider, new OnBound() {

        @Override
        public void onBound(IOpenPgpService2 service) {
            openPgpApi = new OpenPgpApi(context, service);
            refreshConnection();
        }

        @Override
        public void onError(Exception e) {
            Timber.e(e, "error connecting to crypto provider!");
            setOpenPgpProviderState(OpenPgpProviderState.ERROR);
            callbackOpenPgpProviderError(OpenPgpProviderError.ConnectionFailed);
        }
    });
    refreshConnection();
}
Also used : OnBound(org.openintents.openpgp.util.OpenPgpServiceConnection.OnBound) OpenPgpServiceConnection(org.openintents.openpgp.util.OpenPgpServiceConnection) OpenPgpApi(org.openintents.openpgp.util.OpenPgpApi)

Example 2 with OnBound

use of org.openintents.openpgp.util.OpenPgpServiceConnection.OnBound in project k-9 by k9mail.

the class RecipientPresenter method setupCryptoProvider.

private void setupCryptoProvider() {
    String openPgpProvider = K9.getOpenPgpProvider();
    if (TextUtils.isEmpty(openPgpProvider)) {
        openPgpProvider = null;
    }
    boolean providerIsBound = openPgpServiceConnection != null && openPgpServiceConnection.isBound();
    boolean isSameProvider = openPgpProvider != null && openPgpProvider.equals(this.openPgpProvider);
    if (isSameProvider && providerIsBound) {
        cryptoProviderBindOrCheckPermission();
        return;
    }
    if (providerIsBound) {
        openPgpServiceConnection.unbindFromService();
        openPgpServiceConnection = null;
    }
    this.openPgpProvider = openPgpProvider;
    if (openPgpProvider == null) {
        cryptoProviderState = CryptoProviderState.UNCONFIGURED;
        return;
    }
    cryptoProviderState = CryptoProviderState.UNINITIALIZED;
    openPgpServiceConnection = new OpenPgpServiceConnection(context, openPgpProvider, new OnBound() {

        @Override
        public void onBound(IOpenPgpService2 service) {
            cryptoProviderBindOrCheckPermission();
        }

        @Override
        public void onError(Exception e) {
            onCryptoProviderError(e);
        }
    });
    cryptoProviderBindOrCheckPermission();
    recipientMvpView.setCryptoProvider(openPgpProvider);
}
Also used : IOpenPgpService2(org.openintents.openpgp.IOpenPgpService2) OnBound(org.openintents.openpgp.util.OpenPgpServiceConnection.OnBound) OpenPgpServiceConnection(org.openintents.openpgp.util.OpenPgpServiceConnection)

Example 3 with OnBound

use of org.openintents.openpgp.util.OpenPgpServiceConnection.OnBound in project k-9 by k9mail.

the class MessageCryptoHelper method connectToCryptoProviderService.

private void connectToCryptoProviderService() {
    openPgpServiceConnection = new OpenPgpServiceConnection(context, openPgpProvider, new OnBound() {

        @Override
        public void onBound(IOpenPgpService2 service) {
            openPgpApi = openPgpApiFactory.createOpenPgpApi(context, service);
            nextStep();
        }

        @Override
        public void onError(Exception e) {
            // TODO actually handle (hand to ui, offer retry?)
            Timber.e(e, "Couldn't connect to OpenPgpService");
        }
    });
    openPgpServiceConnection.bindToService();
}
Also used : IOpenPgpService2(org.openintents.openpgp.IOpenPgpService2) OnBound(org.openintents.openpgp.util.OpenPgpServiceConnection.OnBound) OpenPgpServiceConnection(org.openintents.openpgp.util.OpenPgpServiceConnection) IOException(java.io.IOException) MessagingException(com.fsck.k9.mail.MessagingException)

Aggregations

OpenPgpServiceConnection (org.openintents.openpgp.util.OpenPgpServiceConnection)3 OnBound (org.openintents.openpgp.util.OpenPgpServiceConnection.OnBound)3 IOpenPgpService2 (org.openintents.openpgp.IOpenPgpService2)2 MessagingException (com.fsck.k9.mail.MessagingException)1 IOException (java.io.IOException)1 OpenPgpApi (org.openintents.openpgp.util.OpenPgpApi)1