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