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));
}
}
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();
}
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);
}
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();
}
Aggregations