Search in sources :

Example 1 with IOpenPgpService2

use of org.openintents.openpgp.IOpenPgpService2 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 IOpenPgpService2

use of org.openintents.openpgp.IOpenPgpService2 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 IOpenPgpService2

use of org.openintents.openpgp.IOpenPgpService2 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 IOpenPgpService2

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

the class OpenPgpKeyPreference method onClick.

@Override
protected void onClick() {
    // bind to service
    mServiceConnection = new OpenPgpServiceConnection(getContext().getApplicationContext(), mOpenPgpProvider, new OpenPgpServiceConnection.OnBound() {

        @Override
        public void onBound(IOpenPgpService2 service) {
            getSignKeyId(new Intent());
        }

        @Override
        public void onError(Exception e) {
            Log.e(OpenPgpApi.TAG, "exception on binding!", e);
        }
    });
    mServiceConnection.bindToService();
}
Also used : IOpenPgpService2(org.openintents.openpgp.IOpenPgpService2) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 5 with IOpenPgpService2

use of org.openintents.openpgp.IOpenPgpService2 in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method onCreate.

@SuppressLint("TrulyRandom")
@Override
public void onCreate() {
    ExceptionHelper.init(getApplicationContext());
    PRNGFixes.apply();
    Resolver.init(this);
    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;
        }
    };
    Log.d(Config.LOGTAG, "initializing database...");
    this.databaseBackend = DatabaseBackend.getInstance(getApplicationContext());
    Log.d(Config.LOGTAG, "restoring accounts...");
    this.accounts = databaseBackend.getAccounts();
    final SharedPreferences.Editor editor = getPreferences().edit();
    if (this.accounts.size() == 0 && Arrays.asList("Sony", "Sony Ericsson").contains(Build.MANUFACTURER)) {
        editor.putBoolean(SettingsActivity.SHOW_FOREGROUND_SERVICE, true);
        Log.d(Config.LOGTAG, Build.MANUFACTURER + " is on blacklist. enabling foreground service");
    }
    editor.putBoolean(EventReceiver.SETTING_ENABLED_ACCOUNTS, hasEnabledAccounts()).apply();
    editor.apply();
    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(this, "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();
    }
    // start export log service every day at given time
    ScheduleAutomaticExport();
    // cancel scheduled exporter
    CancelAutomaticExport(false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        registerReceiver(this.mEventReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
    }
}
Also used : Account(de.pixart.messenger.entities.Account) IntentFilter(android.content.IntentFilter) IOpenPgpService2(org.openintents.openpgp.IOpenPgpService2) SharedPreferences(android.content.SharedPreferences) SecureRandom(java.security.SecureRandom) OpenPgpServiceConnection(org.openintents.openpgp.util.OpenPgpServiceConnection) PgpDecryptionService(de.pixart.messenger.crypto.PgpDecryptionService) SuppressLint(android.annotation.SuppressLint) OtrException(net.java.otr4j.OtrException) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) CertificateException(java.security.cert.CertificateException) Bitmap(android.graphics.Bitmap) SuppressLint(android.annotation.SuppressLint)

Aggregations

IOpenPgpService2 (org.openintents.openpgp.IOpenPgpService2)6 OpenPgpServiceConnection (org.openintents.openpgp.util.OpenPgpServiceConnection)5 SuppressLint (android.annotation.SuppressLint)2 Intent (android.content.Intent)2 IntentFilter (android.content.IntentFilter)2 Bitmap (android.graphics.Bitmap)2 SecureRandom (java.security.SecureRandom)2 CertificateException (java.security.cert.CertificateException)2 OtrException (net.java.otr4j.OtrException)2 OnBound (org.openintents.openpgp.util.OpenPgpServiceConnection.OnBound)2 PendingIntent (android.app.PendingIntent)1 SharedPreferences (android.content.SharedPreferences)1 ParcelFileDescriptor (android.os.ParcelFileDescriptor)1 Account (com.fsck.k9.Account)1 MessagingException (com.fsck.k9.mail.MessagingException)1 PgpDecryptionService (de.pixart.messenger.crypto.PgpDecryptionService)1 Account (de.pixart.messenger.entities.Account)1 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)1 PgpDecryptionService (eu.siacs.conversations.crypto.PgpDecryptionService)1 Account (eu.siacs.conversations.entities.Account)1