Search in sources :

Example 1 with OpenPgpServiceConnection

use of org.openintents.openpgp.util.OpenPgpServiceConnection in project Conversations by siacs.

the class XmppConnectionService method onCreate.

@SuppressLint("TrulyRandom")
@Override
public void onCreate() {
    ExceptionHelper.init(getApplicationContext());
    PRNGFixes.apply();
    this.mRandom = new SecureRandom();
    updateMemorizingTrustmanager();
    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
    final int cacheSize = maxMemory / 8;
    this.mBitmapCache = new LruCache<String, Bitmap>(cacheSize) {

        @Override
        protected int sizeOf(final String key, final Bitmap bitmap) {
            return bitmap.getByteCount() / 1024;
        }
    };
    this.databaseBackend = DatabaseBackend.getInstance(getApplicationContext());
    this.accounts = databaseBackend.getAccounts();
    if (Config.FREQUENT_RESTARTS_THRESHOLD != 0 && Config.FREQUENT_RESTARTS_DETECTION_WINDOW != 0 && !keepForegroundService() && databaseBackend.startTimeCountExceedsThreshold()) {
        getPreferences().edit().putBoolean(SettingsActivity.KEEP_FOREGROUND_SERVICE, true).commit();
        Log.d(Config.LOGTAG, "number of restarts exceeds threshold. enabling foreground service");
    }
    restoreFromDatabase();
    getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, contactObserver);
    new Thread(new Runnable() {

        @Override
        public void run() {
            fileObserver.startWatching();
        }
    }).start();
    if (Config.supportOpenPgp()) {
        this.pgpServiceConnection = new OpenPgpServiceConnection(getApplicationContext(), "org.sufficientlysecure.keychain", new OpenPgpServiceConnection.OnBound() {

            @Override
            public void onBound(IOpenPgpService2 service) {
                for (Account account : accounts) {
                    final PgpDecryptionService pgp = account.getPgpDecryptionService();
                    if (pgp != null) {
                        pgp.continueDecryption(true);
                    }
                }
            }

            @Override
            public void onError(Exception e) {
            }
        });
        this.pgpServiceConnection.bindToService();
    }
    this.pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    this.wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "XmppConnectionService");
    toggleForegroundService();
    updateUnreadCountBadge();
    toggleScreenEventReceiver();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        scheduleNextIdlePing();
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        registerReceiver(this.mEventReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) IntentFilter(android.content.IntentFilter) IOpenPgpService2(org.openintents.openpgp.IOpenPgpService2) SecureRandom(java.security.SecureRandom) OpenPgpServiceConnection(org.openintents.openpgp.util.OpenPgpServiceConnection) PgpDecryptionService(eu.siacs.conversations.crypto.PgpDecryptionService) SuppressLint(android.annotation.SuppressLint) OtrException(net.java.otr4j.OtrException) FileNotFoundException(java.io.FileNotFoundException) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) CertificateException(java.security.cert.CertificateException) Bitmap(android.graphics.Bitmap) SuppressLint(android.annotation.SuppressLint)

Example 2 with OpenPgpServiceConnection

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

the class RecipientPresenterTest method setupCryptoProvider.

private void setupCryptoProvider() throws android.os.RemoteException {
    Account account = mock(Account.class);
    OpenPgpServiceConnection openPgpServiceConnection = mock(OpenPgpServiceConnection.class);
    IOpenPgpService2 openPgpService2 = mock(IOpenPgpService2.class);
    Intent permissionPingIntent = new Intent();
    K9.setOpenPgpProvider(CRYPTO_PROVIDER);
    permissionPingIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS);
    when(account.getCryptoKey()).thenReturn(CRYPTO_KEY_ID);
    when(openPgpServiceConnection.isBound()).thenReturn(true);
    when(openPgpServiceConnection.getService()).thenReturn(openPgpService2);
    when(openPgpService2.execute(any(Intent.class), any(ParcelFileDescriptor.class), any(Integer.class))).thenReturn(permissionPingIntent);
    Robolectric.getBackgroundThreadScheduler().pause();
    recipientPresenter.setOpenPgpServiceConnection(openPgpServiceConnection, CRYPTO_PROVIDER);
    recipientPresenter.onSwitchAccount(account);
    recipientPresenter.updateCryptoStatus();
    Robolectric.getBackgroundThreadScheduler().runOneTask();
}
Also used : Account(com.fsck.k9.Account) IOpenPgpService2(org.openintents.openpgp.IOpenPgpService2) ParcelFileDescriptor(android.os.ParcelFileDescriptor) OpenPgpServiceConnection(org.openintents.openpgp.util.OpenPgpServiceConnection) Intent(android.content.Intent)

Example 3 with OpenPgpServiceConnection

use of org.openintents.openpgp.util.OpenPgpServiceConnection 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 4 with OpenPgpServiceConnection

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

the class MessageCryptoHelper method connectToCryptoProviderService.

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

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

        @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) OpenPgpApi(org.openintents.openpgp.util.OpenPgpApi) IOException(java.io.IOException) MessagingException(com.fsck.k9.mail.MessagingException)

Aggregations

IOpenPgpService2 (org.openintents.openpgp.IOpenPgpService2)4 OpenPgpServiceConnection (org.openintents.openpgp.util.OpenPgpServiceConnection)4 OnBound (org.openintents.openpgp.util.OpenPgpServiceConnection.OnBound)2 SuppressLint (android.annotation.SuppressLint)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 Bitmap (android.graphics.Bitmap)1 ParcelFileDescriptor (android.os.ParcelFileDescriptor)1 Account (com.fsck.k9.Account)1 MessagingException (com.fsck.k9.mail.MessagingException)1 PgpDecryptionService (eu.siacs.conversations.crypto.PgpDecryptionService)1 Account (eu.siacs.conversations.entities.Account)1 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 SecureRandom (java.security.SecureRandom)1 CertificateException (java.security.cert.CertificateException)1 OtrException (net.java.otr4j.OtrException)1 OpenPgpApi (org.openintents.openpgp.util.OpenPgpApi)1