Search in sources :

Example 1 with PgpDecryptionService

use of eu.siacs.conversations.crypto.PgpDecryptionService in project Conversations by siacs.

the class Account method initAccountServices.

public void initAccountServices(final XmppConnectionService context) {
    this.axolotlService = new AxolotlService(this, context);
    this.pgpDecryptionService = new PgpDecryptionService(context);
    if (xmppConnection != null) {
        xmppConnection.addOnAdvancedStreamFeaturesAvailableListener(axolotlService);
    }
}
Also used : AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService) PgpDecryptionService(eu.siacs.conversations.crypto.PgpDecryptionService)

Example 2 with PgpDecryptionService

use of eu.siacs.conversations.crypto.PgpDecryptionService in project Conversations by siacs.

the class Conversation method markAsChanged.

public boolean markAsChanged(final List<DatabaseBackend.FilePathInfo> files) {
    boolean changed = false;
    final PgpDecryptionService pgpDecryptionService = account.getPgpDecryptionService();
    synchronized (this.messages) {
        for (Message message : this.messages) {
            for (final DatabaseBackend.FilePathInfo file : files) if (file.uuid.toString().equals(message.getUuid())) {
                message.setDeleted(file.deleted);
                changed = true;
                if (file.deleted && message.getEncryption() == Message.ENCRYPTION_PGP && pgpDecryptionService != null) {
                    pgpDecryptionService.discard(message);
                }
            }
        }
    }
    return changed;
}
Also used : DatabaseBackend(eu.siacs.conversations.persistance.DatabaseBackend) PgpDecryptionService(eu.siacs.conversations.crypto.PgpDecryptionService)

Example 3 with PgpDecryptionService

use of eu.siacs.conversations.crypto.PgpDecryptionService in project Conversations by siacs.

the class Conversation method markAsDeleted.

public boolean markAsDeleted(final List<String> uuids) {
    boolean deleted = false;
    final PgpDecryptionService pgpDecryptionService = account.getPgpDecryptionService();
    synchronized (this.messages) {
        for (Message message : this.messages) {
            if (uuids.contains(message.getUuid())) {
                message.setDeleted(true);
                deleted = true;
                if (message.getEncryption() == Message.ENCRYPTION_PGP && pgpDecryptionService != null) {
                    pgpDecryptionService.discard(message);
                }
            }
        }
    }
    return deleted;
}
Also used : PgpDecryptionService(eu.siacs.conversations.crypto.PgpDecryptionService)

Example 4 with PgpDecryptionService

use of eu.siacs.conversations.crypto.PgpDecryptionService in project Conversations by siacs.

the class XmppConnectionService method onCreate.

@SuppressLint("TrulyRandom")
@Override
public void onCreate() {
    if (Compatibility.runsTwentySix()) {
        mNotificationService.initializeChannels();
    }
    mChannelDiscoveryService.initializeMuclumbusService();
    mForceDuringOnCreate.set(Compatibility.runsAndTargetsTwentySix(this));
    toggleForegroundService();
    this.destroyed = false;
    OmemoSetting.load(this);
    ExceptionHelper.init(getApplicationContext());
    try {
        Security.insertProviderAt(Conscrypt.newProvider(), 1);
    } catch (Throwable throwable) {
        Log.e(Config.LOGTAG, "unable to initialize security provider", throwable);
    }
    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;
        }
    };
    if (mLastActivity == 0) {
        mLastActivity = getPreferences().getLong(SETTING_LAST_ACTIVITY_TS, System.currentTimeMillis());
    }
    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.KEEP_FOREGROUND_SERVICE, true);
        Log.d(Config.LOGTAG, Build.MANUFACTURER + " is on blacklist. enabling foreground service");
    }
    final boolean hasEnabledAccounts = hasEnabledAccounts();
    editor.putBoolean(EventReceiver.SETTING_ENABLED_ACCOUNTS, hasEnabledAccounts).apply();
    editor.apply();
    toggleSetProfilePictureActivity(hasEnabledAccounts);
    restoreFromDatabase();
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
        startContactObserver();
    }
    FILE_OBSERVER_EXECUTOR.execute(fileBackend::deleteHistoricAvatarPath);
    if (Compatibility.hasStoragePermission(this)) {
        Log.d(Config.LOGTAG, "starting file observer");
        FILE_OBSERVER_EXECUTOR.execute(this.fileObserver::startWatching);
        FILE_OBSERVER_EXECUTOR.execute(this::checkForDeletedFiles);
    }
    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();
    }
    final PowerManager pm = ContextCompat.getSystemService(this, PowerManager.class);
    this.wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Conversations:Service");
    toggleForegroundService();
    updateUnreadCountBadge();
    toggleScreenEventReceiver();
    final IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(TorServiceUtils.ACTION_STATUS);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        scheduleNextIdlePing();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
        }
        intentFilter.addAction(NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED);
    }
    registerReceiver(this.mInternalEventReceiver, intentFilter);
    mForceDuringOnCreate.set(false);
    toggleForegroundService();
    setupPhoneStateListener();
}
Also used : Account(eu.siacs.conversations.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(eu.siacs.conversations.crypto.PgpDecryptionService) SuppressLint(android.annotation.SuppressLint) CertificateException(java.security.cert.CertificateException) PowerManager(android.os.PowerManager) Bitmap(android.graphics.Bitmap) SuppressLint(android.annotation.SuppressLint)

Example 5 with PgpDecryptionService

use of eu.siacs.conversations.crypto.PgpDecryptionService in project Conversations by siacs.

the class Conversation method trim.

public void trim() {
    synchronized (this.messages) {
        final int size = messages.size();
        final int maxsize = Config.PAGE_SIZE * Config.MAX_NUM_PAGES;
        if (size > maxsize) {
            List<Message> discards = this.messages.subList(0, size - maxsize);
            final PgpDecryptionService pgpDecryptionService = account.getPgpDecryptionService();
            if (pgpDecryptionService != null) {
                pgpDecryptionService.discard(discards);
            }
            discards.clear();
            untieMessages();
        }
    }
}
Also used : PgpDecryptionService(eu.siacs.conversations.crypto.PgpDecryptionService)

Aggregations

PgpDecryptionService (eu.siacs.conversations.crypto.PgpDecryptionService)5 SuppressLint (android.annotation.SuppressLint)1 IntentFilter (android.content.IntentFilter)1 SharedPreferences (android.content.SharedPreferences)1 Bitmap (android.graphics.Bitmap)1 PowerManager (android.os.PowerManager)1 AxolotlService (eu.siacs.conversations.crypto.axolotl.AxolotlService)1 Account (eu.siacs.conversations.entities.Account)1 DatabaseBackend (eu.siacs.conversations.persistance.DatabaseBackend)1 SecureRandom (java.security.SecureRandom)1 CertificateException (java.security.cert.CertificateException)1 IOpenPgpService2 (org.openintents.openpgp.IOpenPgpService2)1 OpenPgpServiceConnection (org.openintents.openpgp.util.OpenPgpServiceConnection)1