From e0847cafaf53eac9b364343c1f5e74554b51053d Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 12 Jan 2015 19:27:46 +0100 Subject: even more intermediate result --- .../java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java index 810190fee..5e953ec1e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java @@ -21,6 +21,8 @@ package org.sufficientlysecure.keychain.service; import android.os.Parcel; import android.os.Parcelable; +import org.sufficientlysecure.keychain.pgp.affirmation.Affi; + import java.io.Serializable; import java.util.ArrayList; -- cgit v1.2.3 From 9fe701c866673d80cabc418ac675718447f76145 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 12 Jan 2015 20:04:15 +0100 Subject: work on affirmations (begin rename to LinkedIdentity --- .../org/sufficientlysecure/keychain/service/SaveKeyringParcel.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java index 5e953ec1e..b914f4619 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java @@ -21,7 +21,7 @@ package org.sufficientlysecure.keychain.service; import android.os.Parcel; import android.os.Parcelable; -import org.sufficientlysecure.keychain.pgp.affirmation.Affi; +import org.sufficientlysecure.keychain.pgp.affirmation.LinkedIdentity; import java.io.Serializable; import java.util.ArrayList; @@ -51,6 +51,7 @@ public class SaveKeyringParcel implements Parcelable { public ChangeUnlockParcel mNewUnlock; public ArrayList mAddUserIds; + public ArrayList mAddLinkedIdentity; public ArrayList mAddSubKeys; public ArrayList mChangeSubKeys; @@ -73,6 +74,7 @@ public class SaveKeyringParcel implements Parcelable { public void reset() { mNewUnlock = null; mAddUserIds = new ArrayList(); + mAddLinkedIdentity = new ArrayList(); mAddSubKeys = new ArrayList(); mChangePrimaryUserId = null; mChangeSubKeys = new ArrayList(); @@ -164,6 +166,7 @@ public class SaveKeyringParcel implements Parcelable { mNewUnlock = source.readParcelable(getClass().getClassLoader()); mAddUserIds = source.createStringArrayList(); + mAddLinkedIdentity = (ArrayList) source.readSerializable(); mAddSubKeys = (ArrayList) source.readSerializable(); mChangeSubKeys = (ArrayList) source.readSerializable(); @@ -186,6 +189,7 @@ public class SaveKeyringParcel implements Parcelable { destination.writeParcelable(mNewUnlock, 0); destination.writeStringList(mAddUserIds); + destination.writeSerializable(mAddLinkedIdentity); destination.writeSerializable(mAddSubKeys); destination.writeSerializable(mChangeSubKeys); @@ -216,6 +220,7 @@ public class SaveKeyringParcel implements Parcelable { String out = "mMasterKeyId: " + mMasterKeyId + "\n"; out += "mNewUnlock: " + mNewUnlock + "\n"; out += "mAddUserIds: " + mAddUserIds + "\n"; + out += "mAddLinkedIdentity: " + mAddLinkedIdentity + "\n"; out += "mAddSubKeys: " + mAddSubKeys + "\n"; out += "mChangeSubKeys: " + mChangeSubKeys + "\n"; out += "mChangePrimaryUserId: " + mChangePrimaryUserId + "\n"; -- cgit v1.2.3 From ea72b29f2dbdef8104701d7eee6b35112078716e Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 12 Jan 2015 20:59:37 +0100 Subject: support addition of user attributes --- .../keychain/service/SaveKeyringParcel.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java index b914f4619..d9de274ee 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java @@ -21,6 +21,7 @@ package org.sufficientlysecure.keychain.service; import android.os.Parcel; import android.os.Parcelable; +import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute; import org.sufficientlysecure.keychain.pgp.affirmation.LinkedIdentity; import java.io.Serializable; @@ -51,7 +52,7 @@ public class SaveKeyringParcel implements Parcelable { public ChangeUnlockParcel mNewUnlock; public ArrayList mAddUserIds; - public ArrayList mAddLinkedIdentity; + public ArrayList mAddUserAttribute; public ArrayList mAddSubKeys; public ArrayList mChangeSubKeys; @@ -74,7 +75,7 @@ public class SaveKeyringParcel implements Parcelable { public void reset() { mNewUnlock = null; mAddUserIds = new ArrayList(); - mAddLinkedIdentity = new ArrayList(); + mAddUserAttribute = new ArrayList(); mAddSubKeys = new ArrayList(); mChangePrimaryUserId = null; mChangeSubKeys = new ArrayList(); @@ -166,7 +167,7 @@ public class SaveKeyringParcel implements Parcelable { mNewUnlock = source.readParcelable(getClass().getClassLoader()); mAddUserIds = source.createStringArrayList(); - mAddLinkedIdentity = (ArrayList) source.readSerializable(); + mAddUserAttribute = (ArrayList) source.readSerializable(); mAddSubKeys = (ArrayList) source.readSerializable(); mChangeSubKeys = (ArrayList) source.readSerializable(); @@ -189,7 +190,7 @@ public class SaveKeyringParcel implements Parcelable { destination.writeParcelable(mNewUnlock, 0); destination.writeStringList(mAddUserIds); - destination.writeSerializable(mAddLinkedIdentity); + destination.writeSerializable(mAddUserAttribute); destination.writeSerializable(mAddSubKeys); destination.writeSerializable(mChangeSubKeys); @@ -220,7 +221,7 @@ public class SaveKeyringParcel implements Parcelable { String out = "mMasterKeyId: " + mMasterKeyId + "\n"; out += "mNewUnlock: " + mNewUnlock + "\n"; out += "mAddUserIds: " + mAddUserIds + "\n"; - out += "mAddLinkedIdentity: " + mAddLinkedIdentity + "\n"; + out += "mAddUserAttribute: " + mAddUserAttribute + "\n"; out += "mAddSubKeys: " + mAddSubKeys + "\n"; out += "mChangeSubKeys: " + mChangeSubKeys + "\n"; out += "mChangePrimaryUserId: " + mChangePrimaryUserId + "\n"; -- cgit v1.2.3 From 92b8d874ed0d7e8f835dbd8ce4205e74841d7162 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Thu, 15 Jan 2015 16:59:11 +0100 Subject: affirmation -> linked identity --- .../org/sufficientlysecure/keychain/service/KeychainIntentService.java | 1 - .../java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java | 1 - 2 files changed, 2 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java index 479810203..3626076b7 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -33,7 +33,6 @@ import org.sufficientlysecure.keychain.operations.EditKeyOperation; import org.sufficientlysecure.keychain.operations.results.DeleteResult; import org.sufficientlysecure.keychain.operations.results.EditKeyResult; import org.sufficientlysecure.keychain.operations.results.ExportResult; -import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.operations.results.CertifyResult; import org.sufficientlysecure.keychain.util.FileHelper; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java index d9de274ee..2f2224b24 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/SaveKeyringParcel.java @@ -22,7 +22,6 @@ import android.os.Parcel; import android.os.Parcelable; import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute; -import org.sufficientlysecure.keychain.pgp.affirmation.LinkedIdentity; import java.io.Serializable; import java.util.ArrayList; -- cgit v1.2.3 From ea7068acdfdcbe78412a42f88a731a81753808ed Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sun, 8 Mar 2015 03:12:26 +0100 Subject: minor changes, add convertFingerprintToKeyId method --- .../keychain/service/CertifyActionsParcel.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java index f4b941109..9730cd74d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java @@ -23,6 +23,7 @@ import android.os.Parcelable; import java.io.Serializable; import java.util.ArrayList; +import java.util.List; import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute; @@ -81,17 +82,11 @@ public class CertifyActionsParcel implements Parcelable { final public ArrayList mUserIds; final public ArrayList mUserAttributes; - public CertifyAction(long masterKeyId, ArrayList userIds) { + public CertifyAction(long masterKeyId, List userIds, + List attributes) { mMasterKeyId = masterKeyId; - mUserIds = userIds; - mUserAttributes = null; - } - - public CertifyAction(long masterKeyId, ArrayList userIds, - ArrayList attributes) { - mMasterKeyId = masterKeyId; - mUserIds = userIds; - mUserAttributes = attributes; + mUserIds = new ArrayList<>(userIds); + mUserAttributes = new ArrayList<>(attributes); } } -- cgit v1.2.3 From b57bcefe080a0070a65efb6e88d76af1eface52d Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sun, 8 Mar 2015 04:41:41 +0100 Subject: return key ids from PassphraseDialogActivity, accept null userids --- .../org/sufficientlysecure/keychain/service/CertifyActionsParcel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java index 9730cd74d..57a11de21 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java @@ -85,8 +85,8 @@ public class CertifyActionsParcel implements Parcelable { public CertifyAction(long masterKeyId, List userIds, List attributes) { mMasterKeyId = masterKeyId; - mUserIds = new ArrayList<>(userIds); - mUserAttributes = new ArrayList<>(attributes); + mUserIds = userIds == null ? null : new ArrayList<>(userIds); + mUserAttributes = attributes == null ? null : new ArrayList<>(attributes); } } -- cgit v1.2.3 From 1ef6f883e34a08dc916ad7dfabd7f892964aff54 Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Mon, 27 Jul 2015 14:10:26 +0530 Subject: introduced keyserver sync adapter --- .../service/KeyserverSyncAdapterService.java | 234 +++++++++++++++++++++ .../keychain/service/PassphraseCacheService.java | 4 +- 2 files changed, 235 insertions(+), 3 deletions(-) create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java new file mode 100644 index 000000000..4a7e2942e --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java @@ -0,0 +1,234 @@ +package org.sufficientlysecure.keychain.service; + +import android.accounts.Account; +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.app.Service; +import android.content.AbstractThreadedSyncAdapter; +import android.content.ContentProviderClient; +import android.content.Context; +import android.content.Intent; +import android.content.SyncResult; +import android.database.Cursor; +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.drawable.Drawable; +import android.os.Build; +import android.os.Bundle; +import android.os.IBinder; +import android.support.v4.app.NotificationCompat; + +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; +import org.sufficientlysecure.keychain.operations.ImportOperation; +import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; +import org.sufficientlysecure.keychain.provider.KeychainContract; +import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; +import org.sufficientlysecure.keychain.ui.MainActivity; +import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; +import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.util.ParcelableProxy; +import org.sufficientlysecure.keychain.util.Preferences; + +import java.util.ArrayList; +import java.util.GregorianCalendar; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; + +public class KeyserverSyncAdapterService extends Service { + + private static final String ACTION_IGNORE_TOR = "ignore_tor"; + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + Log.e("PHILIP", "Sync adapter service starting"); + switch (intent.getAction()) { + case ACTION_IGNORE_TOR: { + updateKeysFromKeyserver(this, + new CryptoInputParcel(ParcelableProxy.getForNoProxy())); + break; + } + } + // TODO: correct flag? + return START_NOT_STICKY; + } + + private static AtomicBoolean sCancelled = new AtomicBoolean(false); + + private class KeyserverSyncAdapter extends AbstractThreadedSyncAdapter { + + public KeyserverSyncAdapter() { + super(KeyserverSyncAdapterService.this, true); + } + + @Override + public void onPerformSync(Account account, Bundle extras, String authority, + ContentProviderClient provider, SyncResult syncResult) { + Log.d(Constants.TAG, "Performing a keyserver sync!"); + + updateKeysFromKeyserver(KeyserverSyncAdapterService.this, new CryptoInputParcel()); + } + } + + @Override + public IBinder onBind(Intent intent) { + return new KeyserverSyncAdapter().getSyncAdapterBinder(); + } + + public static void updateKeysFromKeyserver(Context context, + CryptoInputParcel cryptoInputParcel) { + /** + * 1. Get keys which have been updated recently and therefore do not need to + * be updated now + * 2. Get list of all keys and filter out ones that don't need to be updated + * 3. Update the remaining keys. + * At any time, if the operation is to be cancelled, the sCancelled AtomicBoolean may be set + */ + + // 1. Get keys which have been updated recently and don't need to updated now + final int INDEX_UPDATED_KEYS_MASTER_KEY_ID = 0; + final int INDEX_LAST_UPDATED = 1; + + final long TIME_DAY = TimeUnit.DAYS.toSeconds(1); + final long CURRENT_TIME = GregorianCalendar.getInstance().get(GregorianCalendar.SECOND); + Log.e("PHILIP", "day: " + TIME_DAY); + Cursor updatedKeysCursor = context.getContentResolver().query( + KeychainContract.UpdatedKeys.CONTENT_URI, + new String[]{ + KeychainContract.UpdatedKeys.MASTER_KEY_ID, + KeychainContract.UpdatedKeys.LAST_UPDATED + }, + "? - " + KeychainContract.UpdatedKeys.LAST_UPDATED + " < " + TIME_DAY, + new String[]{"" + CURRENT_TIME}, + null + ); + + ArrayList ignoreMasterKeyIds = new ArrayList<>(); + while (updatedKeysCursor.moveToNext()) { + long masterKeyId = updatedKeysCursor.getLong(INDEX_UPDATED_KEYS_MASTER_KEY_ID); + Log.d(Constants.TAG, "Keyserver sync: {" + masterKeyId + "} last updated at {" + + updatedKeysCursor.getLong(INDEX_LAST_UPDATED) + "}s"); + ignoreMasterKeyIds.add(masterKeyId); + } + updatedKeysCursor.close(); + + // 2. Make a list of public keys which should be updated + final int INDEX_MASTER_KEY_ID = 0; + final int INDEX_FINGERPRINT = 1; + Cursor keyCursor = context.getContentResolver().query( + KeychainContract.KeyRings.buildUnifiedKeyRingsUri(), + new String[]{ + KeychainContract.KeyRings.MASTER_KEY_ID, + KeychainContract.KeyRings.FINGERPRINT + }, + null, + null, + null + ); + + if (keyCursor == null) { + return; + } + + ArrayList keyList = new ArrayList<>(); + while (keyCursor.moveToNext()) { + long keyId = keyCursor.getLong(INDEX_MASTER_KEY_ID); + if (ignoreMasterKeyIds.contains(keyId)) { + continue; + } + String fingerprint = KeyFormattingUtils + .convertFingerprintToHex(keyCursor.getBlob(INDEX_FINGERPRINT)); + String hexKeyId = KeyFormattingUtils + .convertKeyIdToHex(keyId); + // we aren't updating from keybase as of now + keyList.add(new ParcelableKeyRing(fingerprint, hexKeyId, null)); + } + keyCursor.close(); + + if (sCancelled.get()) { + // if we've already been cancelled + return; + } + + // 3. Actually update the keys + Log.e("PHILIP", keyList.toString()); + ImportOperation importOp = new ImportOperation(context, new ProviderHelper(context), null); + ImportKeyResult result = importOp.execute( + new ImportKeyringParcel(keyList, + Preferences.getPreferences(context).getPreferredKeyserver()), + cryptoInputParcel + ); + if (result.isPending()) { + NotificationManager manager = + (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE); + manager.notify(Constants.Notification.KEYSERVER_SYNC_FAIL_ORBOT, + getOrbotNoification(context)); + + Log.d(Constants.TAG, "Keyserver sync failed due to pending result " + + result.getRequiredInputParcel().mType); + } else { + Log.d(Constants.TAG, "Background keyserver sync completed: new " + result.mNewKeys + + " updated " + result.mUpdatedKeys + " bad " + result.mBadKeys); + } + } + + public static void preventAndCancelUpdates() { + // TODO: PHILIP uncomment! + // sCancelled.set(true); + } + + public static void allowUpdates() { + sCancelled.set(false); + } + + private static Notification getOrbotNoification(Context context) { + // TODO: PHILIP work in progress + NotificationCompat.Builder builder = new NotificationCompat.Builder(context); + builder.setSmallIcon(R.drawable.ic_stat_notify_24dp) + .setLargeIcon(getBitmap(R.drawable.ic_launcher, context)) + .setContentTitle(context.getString(R.string.keyserver_sync_orbot_notif_title)) + .setContentText(context.getString(R.string.keyserver_sync_orbot_notif_msg)); + + // In case the user decides to not use tor + Intent ignoreTorIntent = new Intent(context, KeyserverSyncAdapterService.class); + ignoreTorIntent.setAction(ACTION_IGNORE_TOR); + PendingIntent ignoreTorPi = PendingIntent.getService( + context, + Constants.Notification.KEYSERVER_SYNC_FAIL_ORBOT, + ignoreTorIntent, + PendingIntent.FLAG_CANCEL_CURRENT + ); + + builder.addAction(R.drawable.abc_ic_clear_mtrl_alpha, + context.getString(R.string.keyserver_sync_orbot_notif_ignore), + ignoreTorPi); + + return builder.build(); + } + + // from de.azapps.mirakel.helper.Helpers from https://github.com/MirakelX/mirakel-android + private static Bitmap getBitmap(int resId, Context context) { + int mLargeIconWidth = (int) context.getResources().getDimension( + android.R.dimen.notification_large_icon_width); + int mLargeIconHeight = (int) context.getResources().getDimension( + android.R.dimen.notification_large_icon_height); + Drawable d; + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + // noinspection deprecation (can't help it at this api level) + d = context.getResources().getDrawable(resId); + } else { + d = context.getDrawable(resId); + } + if (d == null) { + return null; + } + Bitmap b = Bitmap.createBitmap(mLargeIconWidth, mLargeIconHeight, Bitmap.Config.ARGB_8888); + Canvas c = new Canvas(b); + d.setBounds(0, 0, mLargeIconWidth, mLargeIconHeight); + d.draw(c); + return b; + } +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java index 2a258b7e3..be269c66d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java @@ -101,8 +101,6 @@ public class PassphraseCacheService extends Service { private static final long DEFAULT_TTL = 15; - private static final int NOTIFICATION_ID = 1; - private static final int MSG_PASSPHRASE_CACHE_GET_OKAY = 1; private static final int MSG_PASSPHRASE_CACHE_GET_KEY_NOT_FOUND = 2; @@ -477,7 +475,7 @@ public class PassphraseCacheService extends Service { private void updateService() { if (mPassphraseCache.size() > 0) { - startForeground(NOTIFICATION_ID, getNotification()); + startForeground(Constants.Notification.PASSPHRASE_CACHE, getNotification()); } else { // stop whole service if no cached passphrases remaining Log.d(Constants.TAG, "PassphraseCacheService: No passphrases remaining in memory, stopping service!"); -- cgit v1.2.3 From 448657602ce5baa5b2a99e26ab2eb2fb8061778f Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Thu, 30 Jul 2015 04:39:38 +0530 Subject: improved orbot notify, added periodic sync --- .../service/KeyserverSyncAdapterService.java | 88 ++++++++++++++++++++-- 1 file changed, 80 insertions(+), 8 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java index 4a7e2942e..a08797e6d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java @@ -16,6 +16,7 @@ import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; +import android.os.Handler; import android.os.IBinder; import android.support.v4.app.NotificationCompat; @@ -27,7 +28,7 @@ import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; -import org.sufficientlysecure.keychain.ui.MainActivity; +import org.sufficientlysecure.keychain.ui.OrbotRequiredDialogActivity; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ParcelableProxy; @@ -41,19 +42,49 @@ import java.util.concurrent.atomic.AtomicBoolean; public class KeyserverSyncAdapterService extends Service { private static final String ACTION_IGNORE_TOR = "ignore_tor"; + private static final String ACTION_DISMISS_NOTIFICATION = "cancel_sync"; + private static final String ACTION_START_ORBOT = "start_orbot"; @Override - public int onStartCommand(Intent intent, int flags, int startId) { + public int onStartCommand(Intent intent, int flags, final int startId) { Log.e("PHILIP", "Sync adapter service starting"); + NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); switch (intent.getAction()) { case ACTION_IGNORE_TOR: { updateKeysFromKeyserver(this, new CryptoInputParcel(ParcelableProxy.getForNoProxy())); + manager.cancel(Constants.Notification.KEYSERVER_SYNC_FAIL_ORBOT); + stopSelf(startId); + break; + } + case ACTION_START_ORBOT: { + Intent startOrbot = new Intent(this, OrbotRequiredDialogActivity.class); + startOrbot.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startOrbot.setAction(OrbotRequiredDialogActivity.ACTION_START_ORBOT); + startActivity(startOrbot); + new Handler().postDelayed( + new Runnable() { + @Override + public void run() { + updateKeysFromKeyserver(KeyserverSyncAdapterService.this, + new CryptoInputParcel()); + stopSelf(startId); + } + }, + 30000 // shouldn't take longer for orbot to start + ); + + manager.cancel(Constants.Notification.KEYSERVER_SYNC_FAIL_ORBOT); + break; + } + case ACTION_DISMISS_NOTIFICATION: { + manager.cancel(Constants.Notification.KEYSERVER_SYNC_FAIL_ORBOT); + stopSelf(startId); break; } } // TODO: correct flag? - return START_NOT_STICKY; + return START_REDELIVER_INTENT; } private static AtomicBoolean sCancelled = new AtomicBoolean(false); @@ -92,16 +123,16 @@ public class KeyserverSyncAdapterService extends Service { final int INDEX_UPDATED_KEYS_MASTER_KEY_ID = 0; final int INDEX_LAST_UPDATED = 1; - final long TIME_DAY = TimeUnit.DAYS.toSeconds(1); + final long TIME_MAX = TimeUnit.DAYS.toSeconds(7); final long CURRENT_TIME = GregorianCalendar.getInstance().get(GregorianCalendar.SECOND); - Log.e("PHILIP", "day: " + TIME_DAY); + Log.e("PHILIP", "week: " + TIME_MAX); Cursor updatedKeysCursor = context.getContentResolver().query( KeychainContract.UpdatedKeys.CONTENT_URI, new String[]{ KeychainContract.UpdatedKeys.MASTER_KEY_ID, KeychainContract.UpdatedKeys.LAST_UPDATED }, - "? - " + KeychainContract.UpdatedKeys.LAST_UPDATED + " < " + TIME_DAY, + "? - " + KeychainContract.UpdatedKeys.LAST_UPDATED + " < " + TIME_MAX, new String[]{"" + CURRENT_TIME}, null ); @@ -110,7 +141,7 @@ public class KeyserverSyncAdapterService extends Service { while (updatedKeysCursor.moveToNext()) { long masterKeyId = updatedKeysCursor.getLong(INDEX_UPDATED_KEYS_MASTER_KEY_ID); Log.d(Constants.TAG, "Keyserver sync: {" + masterKeyId + "} last updated at {" - + updatedKeysCursor.getLong(INDEX_LAST_UPDATED) + "}s"); + + updatedKeysCursor.getLong(INDEX_LAST_UPDATED) + "}s"); ignoreMasterKeyIds.add(masterKeyId); } updatedKeysCursor.close(); @@ -197,7 +228,7 @@ public class KeyserverSyncAdapterService extends Service { ignoreTorIntent.setAction(ACTION_IGNORE_TOR); PendingIntent ignoreTorPi = PendingIntent.getService( context, - Constants.Notification.KEYSERVER_SYNC_FAIL_ORBOT, + 0, // security not issue since we're giving this pending intent to Notification Manager ignoreTorIntent, PendingIntent.FLAG_CANCEL_CURRENT ); @@ -206,9 +237,50 @@ public class KeyserverSyncAdapterService extends Service { context.getString(R.string.keyserver_sync_orbot_notif_ignore), ignoreTorPi); + // not enough space to show it + Intent dismissIntent = new Intent(context, KeyserverSyncAdapterService.class); + dismissIntent.setAction(ACTION_DISMISS_NOTIFICATION); + PendingIntent dismissPi = PendingIntent.getService( + context, + 0, // security not issue since we're giving this pending intent to Notification Manager + dismissIntent, + PendingIntent.FLAG_CANCEL_CURRENT + ); + + /*builder.addAction(R.drawable.abc_ic_clear_mtrl_alpha, + context.getString(android.R.string.cancel), + dismissPi + );*/ + + Intent startOrbotIntent = new Intent(context, KeyserverSyncAdapterService.class); + startOrbotIntent.setAction(ACTION_START_ORBOT); + PendingIntent startOrbotPi = PendingIntent.getService( + context, + 0, // security not issue since we're giving this pending intent to Notification Manager + startOrbotIntent, + PendingIntent.FLAG_CANCEL_CURRENT + ); + + builder.addAction(R.drawable.abc_ic_clear_mtrl_alpha, + context.getString(R.string.keyserver_sync_orbot_notif_start), + startOrbotPi + ); + builder.setContentIntent(startOrbotPi); + return builder.build(); } + /** + * will perform a staggered update of user's keys using delays to ensure new Tor circuits, as + * performed by parcimonie + * + * @return result of the sync + */ + private static ImportKeyResult staggeredSync() { + // TODO: WIP + return null; + } + // from de.azapps.mirakel.helper.Helpers from https://github.com/MirakelX/mirakel-android private static Bitmap getBitmap(int resId, Context context) { int mLargeIconWidth = (int) context.getResources().getDimension( -- cgit v1.2.3 From 65a993446c8905ca5e77fefe4b7f1c4d0aee74d8 Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Mon, 10 Aug 2015 06:17:29 +0530 Subject: reworked keyserversyncadapterservice flow --- .../service/KeyserverSyncAdapterService.java | 368 +++++++++++++++------ 1 file changed, 272 insertions(+), 96 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java index a08797e6d..11d543f49 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java @@ -1,12 +1,14 @@ package org.sufficientlysecure.keychain.service; import android.accounts.Account; +import android.app.AlarmManager; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; import android.content.AbstractThreadedSyncAdapter; import android.content.ContentProviderClient; +import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.SyncResult; @@ -18,6 +20,10 @@ import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; +import android.os.Message; +import android.os.Messenger; +import android.os.PowerManager; +import android.os.SystemClock; import android.support.v4.app.NotificationCompat; import org.sufficientlysecure.keychain.Constants; @@ -25,6 +31,7 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; import org.sufficientlysecure.keychain.operations.ImportOperation; import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; +import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -33,62 +40,100 @@ import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; +import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; import java.util.ArrayList; import java.util.GregorianCalendar; +import java.util.Random; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; public class KeyserverSyncAdapterService extends Service { private static final String ACTION_IGNORE_TOR = "ignore_tor"; + private static final String ACTION_UPDATE_ALL = "update_all"; + private static final String ACTION_SYNC_NOW = "sync_now"; private static final String ACTION_DISMISS_NOTIFICATION = "cancel_sync"; private static final String ACTION_START_ORBOT = "start_orbot"; + private static final String ACTION_CANCEL = "cancel"; + + private AtomicBoolean mCancelled = new AtomicBoolean(false); @Override - public int onStartCommand(Intent intent, int flags, final int startId) { - Log.e("PHILIP", "Sync adapter service starting"); + public int onStartCommand(final Intent intent, int flags, final int startId) { + Log.e("PHILIP", "Sync adapter service starting" + intent.getAction()); + NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + manager.cancel(Constants.Notification.KEYSERVER_SYNC_FAIL_ORBOT); switch (intent.getAction()) { + case ACTION_CANCEL: { + mCancelled.set(true); + break; + } + // the reason for the separation betweyeen SYNC_NOW and UPDATE_ALL is so that starting + // the sync directly from the notification is possible while the screen is on with + // UPDATE_ALL, but a postponed sync is only started if screen is off + case ACTION_SYNC_NOW: { + // this checks for screen on/off before sync, and postpones the sync if on + ContentResolver.requestSync( + new Account(Constants.ACCOUNT_NAME, Constants.ACCOUNT_TYPE), + Constants.PROVIDER_AUTHORITY, + new Bundle() + ); + break; + } + case ACTION_UPDATE_ALL: { + // does not check for screen on/off + asyncKeyUpdate(this, new CryptoInputParcel()); + break; + } case ACTION_IGNORE_TOR: { - updateKeysFromKeyserver(this, - new CryptoInputParcel(ParcelableProxy.getForNoProxy())); - manager.cancel(Constants.Notification.KEYSERVER_SYNC_FAIL_ORBOT); - stopSelf(startId); + asyncKeyUpdate(this, new CryptoInputParcel(ParcelableProxy.getForNoProxy())); break; } case ACTION_START_ORBOT: { Intent startOrbot = new Intent(this, OrbotRequiredDialogActivity.class); startOrbot.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - startOrbot.setAction(OrbotRequiredDialogActivity.ACTION_START_ORBOT); - startActivity(startOrbot); - new Handler().postDelayed( - new Runnable() { + startOrbot.putExtra(OrbotRequiredDialogActivity.EXTRA_START_ORBOT, true); + Messenger messenger = new Messenger( + new Handler() { @Override - public void run() { - updateKeysFromKeyserver(KeyserverSyncAdapterService.this, - new CryptoInputParcel()); - stopSelf(startId); + public void handleMessage(Message msg) { + switch (msg.what) { + case OrbotRequiredDialogActivity.MESSAGE_ORBOT_STARTED: { + Log.e("PHILIP", "orbot activity returned"); + asyncKeyUpdate(KeyserverSyncAdapterService.this, + new CryptoInputParcel()); + break; + } + case OrbotRequiredDialogActivity.MESSAGE_ORBOT_IGNORE: { + asyncKeyUpdate(KeyserverSyncAdapterService.this, + new CryptoInputParcel( + ParcelableProxy.getForNoProxy())); + break; + } + case OrbotRequiredDialogActivity.MESSAGE_DIALOG_CANCEL: { + // just stop service + stopSelf(); + break; + } + } } - }, - 30000 // shouldn't take longer for orbot to start + } ); - - manager.cancel(Constants.Notification.KEYSERVER_SYNC_FAIL_ORBOT); + startOrbot.putExtra(OrbotRequiredDialogActivity.EXTRA_MESSENGER, messenger); + startActivity(startOrbot); break; } case ACTION_DISMISS_NOTIFICATION: { - manager.cancel(Constants.Notification.KEYSERVER_SYNC_FAIL_ORBOT); + // notification is dismissed at the beginning stopSelf(startId); break; } } - // TODO: correct flag? - return START_REDELIVER_INTENT; + return START_NOT_STICKY; } - private static AtomicBoolean sCancelled = new AtomicBoolean(false); - private class KeyserverSyncAdapter extends AbstractThreadedSyncAdapter { public KeyserverSyncAdapter() { @@ -100,7 +145,19 @@ public class KeyserverSyncAdapterService extends Service { ContentProviderClient provider, SyncResult syncResult) { Log.d(Constants.TAG, "Performing a keyserver sync!"); - updateKeysFromKeyserver(KeyserverSyncAdapterService.this, new CryptoInputParcel()); + PowerManager pm = (PowerManager) KeyserverSyncAdapterService.this + .getSystemService(Context.POWER_SERVICE); + @SuppressWarnings("deprecation") // our min is API 15, deprecated only in 20 + boolean isScreenOn = pm.isScreenOn(); + + if (!isScreenOn) { + Intent serviceIntent = new Intent(KeyserverSyncAdapterService.this, + KeyserverSyncAdapterService.class); + serviceIntent.setAction(ACTION_UPDATE_ALL); + startService(serviceIntent); + } else { + postponeSync(); + } } } @@ -109,23 +166,178 @@ public class KeyserverSyncAdapterService extends Service { return new KeyserverSyncAdapter().getSyncAdapterBinder(); } - public static void updateKeysFromKeyserver(Context context, - CryptoInputParcel cryptoInputParcel) { - /** - * 1. Get keys which have been updated recently and therefore do not need to - * be updated now - * 2. Get list of all keys and filter out ones that don't need to be updated - * 3. Update the remaining keys. - * At any time, if the operation is to be cancelled, the sCancelled AtomicBoolean may be set - */ + private void handleUpdateResult(ImportKeyResult result) { + if (result.isPending()) { + Log.e(Constants.TAG, "Keyserver sync pending result: " + + result.getRequiredInputParcel().mType); + // result is pending due to Orbot not being started + // try to start it silently, if disabled show notificationaa + new OrbotHelper.SilentStartManager() { + @Override + protected void onOrbotStarted() { + // retry the update + asyncKeyUpdate(KeyserverSyncAdapterService.this, + new CryptoInputParcel()); + } + + @Override + protected void onSilentStartDisabled() { + // show notification + NotificationManager manager = + (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + manager.notify(Constants.Notification.KEYSERVER_SYNC_FAIL_ORBOT, + getOrbotNoification(KeyserverSyncAdapterService.this)); + } + }.startOrbotAndListen(this, false); + } else if (isUpdateCancelled()) { + Log.d(Constants.TAG, "Keyserver sync cancelled"); + postponeSync(); + } else { + Log.d(Constants.TAG, "Keyserver sync completed: Updated: " + result.mUpdatedKeys + + " Failed: " + result.mBadKeys); + stopSelf(); + } + } + + private void postponeSync() { + AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); + Intent serviceIntent = new Intent(this, KeyserverSyncAdapterService.class); + serviceIntent.setAction(ACTION_SYNC_NOW); + PendingIntent pi = PendingIntent.getService(this, 0, serviceIntent, + PendingIntent.FLAG_UPDATE_CURRENT); + alarmManager.set( + AlarmManager.ELAPSED_REALTIME_WAKEUP, + SystemClock.elapsedRealtime() + 30 * 1000, + pi + ); + } + + private void asyncKeyUpdate(final Context context, + final CryptoInputParcel cryptoInputParcel) { + Log.e("PHILIP", "async key update starting"); + new Thread(new Runnable() { + @Override + public void run() { + ImportKeyResult result = updateKeysFromKeyserver(context, cryptoInputParcel); + handleUpdateResult(result); + } + }).start(); + } + + private synchronized ImportKeyResult updateKeysFromKeyserver(final Context context, + final CryptoInputParcel cryptoInputParcel) { + mCancelled.set(false); + + ArrayList keyList = getKeysToUpdate(context); + + if (isUpdateCancelled()) { // if we've already been cancelled + return new ImportKeyResult(OperationResult.RESULT_CANCELLED, + new OperationResult.OperationLog()); + } + + if (cryptoInputParcel.getParcelableProxy() == null) { + // no explicit proxy, retrieve from preferences. Check if we should do a staggered sync + if (Preferences.getPreferences(context).getProxyPrefs().torEnabled) { + return staggeredUpdate(context, keyList, cryptoInputParcel); + } else { + return directUpdate(context, keyList, cryptoInputParcel); + } + } else { + return directUpdate(context, keyList, cryptoInputParcel); + } + } + + private ImportKeyResult directUpdate(Context context, ArrayList keyList, + CryptoInputParcel cryptoInputParcel) { + Log.d(Constants.TAG, "Starting normal update"); + ImportOperation importOp = new ImportOperation(context, new ProviderHelper(context), null); + return importOp.execute( + new ImportKeyringParcel(keyList, + Preferences.getPreferences(context).getPreferredKeyserver()), + cryptoInputParcel + ); + } + + + /** + * will perform a staggered update of user's keys using delays to ensure new Tor circuits, as + * performed by parcimonie. Relevant issue and method at: + * https://github.com/open-keychain/open-keychain/issues/1337 + * + * @return result of the sync + */ + private ImportKeyResult staggeredUpdate(Context context, ArrayList keyList, + CryptoInputParcel cryptoInputParcel) { + Log.d(Constants.TAG, "Starting staggered update"); + // assuming maxCircuitDirtiness is 10min in Tor + // final int MAX_CIRCUIT_DIRTINESS = (int) TimeUnit.MINUTES.toSeconds(10); + // TODO: PHILIP remove after testing + final int MAX_CIRCUIT_DIRTINESS = (int) TimeUnit.MINUTES.toSeconds(1); + // final int WEEK_IN_SECONDS = (int) TimeUnit.DAYS.toSeconds(7); + final int WEEK_IN_SECONDS = 0; + ImportOperation.KeyImportAccumulator accumulator + = new ImportOperation.KeyImportAccumulator(keyList.size(), null); + for (ParcelableKeyRing keyRing : keyList) { + int waitTime; + int staggeredTime = new Random().nextInt(1 + 2 * (WEEK_IN_SECONDS / keyList.size())); + if (staggeredTime >= MAX_CIRCUIT_DIRTINESS) { + waitTime = staggeredTime; + } else { + waitTime = MAX_CIRCUIT_DIRTINESS + new Random().nextInt(MAX_CIRCUIT_DIRTINESS); + } + Log.d(Constants.TAG, "Updating key with fingerprint " + keyRing.mExpectedFingerprint + + " with a wait time of " + waitTime + "s"); + try { + Thread.sleep(waitTime * 1000); + } catch (InterruptedException e) { + Log.e(Constants.TAG, "Exception during sleep between key updates", e); + // skip this one + continue; + } + ArrayList keyWrapper = new ArrayList<>(); + keyWrapper.add(keyRing); + if (isUpdateCancelled()) { + return new ImportKeyResult(ImportKeyResult.RESULT_CANCELLED, + new OperationResult.OperationLog()); + } + ImportKeyResult result = + new ImportOperation(context, new ProviderHelper(context), null, mCancelled) + .execute( + new ImportKeyringParcel( + keyWrapper, + Preferences.getPreferences(context) + .getPreferredKeyserver() + ), + cryptoInputParcel + ); + if (result.isPending()) { + return result; + } + accumulator.accumulateKeyImport(result); + } + return accumulator.getConsolidatedResult(); + } + + /** + * 1. Get keys which have been updated recently and therefore do not need to + * be updated now + * 2. Get list of all keys and filter out ones that don't need to be updated + * 3. Return keys to be updated + * + * @return list of keys that require update + */ + private ArrayList getKeysToUpdate(Context context) { // 1. Get keys which have been updated recently and don't need to updated now final int INDEX_UPDATED_KEYS_MASTER_KEY_ID = 0; final int INDEX_LAST_UPDATED = 1; - final long TIME_MAX = TimeUnit.DAYS.toSeconds(7); - final long CURRENT_TIME = GregorianCalendar.getInstance().get(GregorianCalendar.SECOND); - Log.e("PHILIP", "week: " + TIME_MAX); + // all time in seconds not milliseconds + // TODO: PHILIP correct TIME_MAX after testing + // final long TIME_MAX = TimeUnit.DAYS.toSeconds(7); + final long TIME_MAX = 1; + final long CURRENT_TIME = GregorianCalendar.getInstance().getTimeInMillis() / 1000; + Log.e("PHILIP", "week: " + TIME_MAX + " current: " + CURRENT_TIME); Cursor updatedKeysCursor = context.getContentResolver().query( KeychainContract.UpdatedKeys.CONTENT_URI, new String[]{ @@ -161,7 +373,7 @@ public class KeyserverSyncAdapterService extends Service { ); if (keyCursor == null) { - return; + return new ArrayList<>(); } ArrayList keyList = new ArrayList<>(); @@ -179,49 +391,39 @@ public class KeyserverSyncAdapterService extends Service { } keyCursor.close(); - if (sCancelled.get()) { - // if we've already been cancelled - return; - } - - // 3. Actually update the keys - Log.e("PHILIP", keyList.toString()); - ImportOperation importOp = new ImportOperation(context, new ProviderHelper(context), null); - ImportKeyResult result = importOp.execute( - new ImportKeyringParcel(keyList, - Preferences.getPreferences(context).getPreferredKeyserver()), - cryptoInputParcel - ); - if (result.isPending()) { - NotificationManager manager = - (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE); - manager.notify(Constants.Notification.KEYSERVER_SYNC_FAIL_ORBOT, - getOrbotNoification(context)); + return keyList; + } - Log.d(Constants.TAG, "Keyserver sync failed due to pending result " + - result.getRequiredInputParcel().mType); - } else { - Log.d(Constants.TAG, "Background keyserver sync completed: new " + result.mNewKeys - + " updated " + result.mUpdatedKeys + " bad " + result.mBadKeys); - } + private boolean isUpdateCancelled() { + return mCancelled.get(); } - public static void preventAndCancelUpdates() { - // TODO: PHILIP uncomment! - // sCancelled.set(true); + /** + * will cancel an update already in progress + * + * @param context used to send an Intent to the service requesting cancellation. + */ + public static void cancelUpdates(Context context) { + Intent intent = new Intent(context, KeyserverSyncAdapterService.class); + intent.setAction(ACTION_CANCEL); + context.startService(intent); } - public static void allowUpdates() { - sCancelled.set(false); + // TODO: PHILIP remove! + @Override + public void onDestroy() { + Log.e("PHILIP", "onDestroy"); + super.onDestroy(); } - private static Notification getOrbotNoification(Context context) { + private Notification getOrbotNoification(Context context) { // TODO: PHILIP work in progress NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(R.drawable.ic_stat_notify_24dp) .setLargeIcon(getBitmap(R.drawable.ic_launcher, context)) .setContentTitle(context.getString(R.string.keyserver_sync_orbot_notif_title)) - .setContentText(context.getString(R.string.keyserver_sync_orbot_notif_msg)); + .setContentText(context.getString(R.string.keyserver_sync_orbot_notif_msg)) + .setAutoCancel(true); // In case the user decides to not use tor Intent ignoreTorIntent = new Intent(context, KeyserverSyncAdapterService.class); @@ -237,21 +439,6 @@ public class KeyserverSyncAdapterService extends Service { context.getString(R.string.keyserver_sync_orbot_notif_ignore), ignoreTorPi); - // not enough space to show it - Intent dismissIntent = new Intent(context, KeyserverSyncAdapterService.class); - dismissIntent.setAction(ACTION_DISMISS_NOTIFICATION); - PendingIntent dismissPi = PendingIntent.getService( - context, - 0, // security not issue since we're giving this pending intent to Notification Manager - dismissIntent, - PendingIntent.FLAG_CANCEL_CURRENT - ); - - /*builder.addAction(R.drawable.abc_ic_clear_mtrl_alpha, - context.getString(android.R.string.cancel), - dismissPi - );*/ - Intent startOrbotIntent = new Intent(context, KeyserverSyncAdapterService.class); startOrbotIntent.setAction(ACTION_START_ORBOT); PendingIntent startOrbotPi = PendingIntent.getService( @@ -261,7 +448,7 @@ public class KeyserverSyncAdapterService extends Service { PendingIntent.FLAG_CANCEL_CURRENT ); - builder.addAction(R.drawable.abc_ic_clear_mtrl_alpha, + builder.addAction(R.drawable.abc_ic_commit_search_api_mtrl_alpha, context.getString(R.string.keyserver_sync_orbot_notif_start), startOrbotPi ); @@ -270,19 +457,8 @@ public class KeyserverSyncAdapterService extends Service { return builder.build(); } - /** - * will perform a staggered update of user's keys using delays to ensure new Tor circuits, as - * performed by parcimonie - * - * @return result of the sync - */ - private static ImportKeyResult staggeredSync() { - // TODO: WIP - return null; - } - // from de.azapps.mirakel.helper.Helpers from https://github.com/MirakelX/mirakel-android - private static Bitmap getBitmap(int resId, Context context) { + private Bitmap getBitmap(int resId, Context context) { int mLargeIconWidth = (int) context.getResources().getDimension( android.R.dimen.notification_large_icon_width); int mLargeIconHeight = (int) context.getResources().getDimension( -- cgit v1.2.3 From 93d66d39f7b985b33538a9f5531e47571693b901 Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Sun, 16 Aug 2015 19:47:38 +0530 Subject: changed orbot notification icons --- .../keychain/service/KeyserverSyncAdapterService.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java index 11d543f49..c50f6a6e9 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java @@ -63,8 +63,6 @@ public class KeyserverSyncAdapterService extends Service { public int onStartCommand(final Intent intent, int flags, final int startId) { Log.e("PHILIP", "Sync adapter service starting" + intent.getAction()); - NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - manager.cancel(Constants.Notification.KEYSERVER_SYNC_FAIL_ORBOT); switch (intent.getAction()) { case ACTION_CANCEL: { mCancelled.set(true); @@ -88,10 +86,14 @@ public class KeyserverSyncAdapterService extends Service { break; } case ACTION_IGNORE_TOR: { + NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + manager.cancel(Constants.Notification.KEYSERVER_SYNC_FAIL_ORBOT); asyncKeyUpdate(this, new CryptoInputParcel(ParcelableProxy.getForNoProxy())); break; } case ACTION_START_ORBOT: { + NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + manager.cancel(Constants.Notification.KEYSERVER_SYNC_FAIL_ORBOT); Intent startOrbot = new Intent(this, OrbotRequiredDialogActivity.class); startOrbot.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startOrbot.putExtra(OrbotRequiredDialogActivity.EXTRA_START_ORBOT, true); @@ -126,7 +128,8 @@ public class KeyserverSyncAdapterService extends Service { break; } case ACTION_DISMISS_NOTIFICATION: { - // notification is dismissed at the beginning + NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + manager.cancel(Constants.Notification.KEYSERVER_SYNC_FAIL_ORBOT); stopSelf(startId); break; } @@ -417,7 +420,6 @@ public class KeyserverSyncAdapterService extends Service { } private Notification getOrbotNoification(Context context) { - // TODO: PHILIP work in progress NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(R.drawable.ic_stat_notify_24dp) .setLargeIcon(getBitmap(R.drawable.ic_launcher, context)) @@ -435,7 +437,7 @@ public class KeyserverSyncAdapterService extends Service { PendingIntent.FLAG_CANCEL_CURRENT ); - builder.addAction(R.drawable.abc_ic_clear_mtrl_alpha, + builder.addAction(R.drawable.ic_stat_tor_off, context.getString(R.string.keyserver_sync_orbot_notif_ignore), ignoreTorPi); @@ -448,7 +450,7 @@ public class KeyserverSyncAdapterService extends Service { PendingIntent.FLAG_CANCEL_CURRENT ); - builder.addAction(R.drawable.abc_ic_commit_search_api_mtrl_alpha, + builder.addAction(R.drawable.ic_stat_tor, context.getString(R.string.keyserver_sync_orbot_notif_start), startOrbotPi ); -- cgit v1.2.3 From 3f8f70b0a99554aae52fd80d31c29f32a34df5d2 Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Mon, 17 Aug 2015 03:08:42 +0530 Subject: added sync preferences --- .../keychain/service/KeyserverSyncAdapterService.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java index c50f6a6e9..baf649701 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java @@ -162,6 +162,12 @@ public class KeyserverSyncAdapterService extends Service { postponeSync(); } } + + @Override + public void onSyncCanceled() { + super.onSyncCanceled(); + cancelUpdates(KeyserverSyncAdapterService.this); + } } @Override @@ -402,7 +408,9 @@ public class KeyserverSyncAdapterService extends Service { } /** - * will cancel an update already in progress + * will cancel an update already in progress. We send an Intent to cancel it instead of simply + * modifying a static variable sync the service is running in a process that is different from + * the default application process where the UI code runs. * * @param context used to send an Intent to the service requesting cancellation. */ -- cgit v1.2.3 From 0251f0e41695d3961dde553ba9ab76fa46583abb Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Wed, 19 Aug 2015 01:13:12 +0530 Subject: introduced constants for keyserver sync, fixed sync issue --- .../service/ContactSyncAdapterService.java | 2 +- .../service/KeyserverSyncAdapterService.java | 82 ++++++++++++++-------- 2 files changed, 54 insertions(+), 30 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/ContactSyncAdapterService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/ContactSyncAdapterService.java index 7688b9252..b36d23775 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/ContactSyncAdapterService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/ContactSyncAdapterService.java @@ -45,7 +45,7 @@ public class ContactSyncAdapterService extends Service { @Override public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, final SyncResult syncResult) { - Log.d(Constants.TAG, "Performing a sync!"); + Log.d(Constants.TAG, "Performing a contact sync!"); // TODO: Import is currently disabled for 2.8, until we implement proper origin management // importDone.set(false); // KeychainApplication.setupAccountAsNeeded(ContactSyncAdapterService.this); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java index baf649701..3243df1a8 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java @@ -1,6 +1,7 @@ package org.sufficientlysecure.keychain.service; import android.accounts.Account; +import android.accounts.AccountManager; import android.app.AlarmManager; import android.app.Notification; import android.app.NotificationManager; @@ -25,6 +26,7 @@ import android.os.Messenger; import android.os.PowerManager; import android.os.SystemClock; import android.support.v4.app.NotificationCompat; +import android.widget.Toast; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; @@ -50,6 +52,20 @@ import java.util.concurrent.atomic.AtomicBoolean; public class KeyserverSyncAdapterService extends Service { + // how often a sync should be initiated, in s + public static final long SYNC_INTERVAL = + Constants.DEBUG_KEYSERVER_SYNC + ? TimeUnit.MINUTES.toSeconds(2) : TimeUnit.DAYS.toSeconds(3); + // time since last update after which a key should be updated again, in s + public static final long KEY_UPDATE_LIMIT = + Constants.DEBUG_KEYSERVER_SYNC ? 1 : TimeUnit.DAYS.toSeconds(7); + // time by which a sync is postponed in case of a + public static final long SYNC_POSTPONE_TIME = + Constants.DEBUG_KEYSERVER_SYNC ? 30 * 1000 : TimeUnit.MINUTES.toMillis(5); + // Time taken by Orbot before a new circuit is created + public static final int ORBOT_CIRCUIT_TIMEOUT = (int) TimeUnit.MINUTES.toMillis(10); + + private static final String ACTION_IGNORE_TOR = "ignore_tor"; private static final String ACTION_UPDATE_ALL = "update_all"; private static final String ACTION_SYNC_NOW = "sync_now"; @@ -61,8 +77,6 @@ public class KeyserverSyncAdapterService extends Service { @Override public int onStartCommand(final Intent intent, int flags, final int startId) { - Log.e("PHILIP", "Sync adapter service starting" + intent.getAction()); - switch (intent.getAction()) { case ACTION_CANCEL: { mCancelled.set(true); @@ -103,7 +117,6 @@ public class KeyserverSyncAdapterService extends Service { public void handleMessage(Message msg) { switch (msg.what) { case OrbotRequiredDialogActivity.MESSAGE_ORBOT_STARTED: { - Log.e("PHILIP", "orbot activity returned"); asyncKeyUpdate(KeyserverSyncAdapterService.this, new CryptoInputParcel()); break; @@ -177,10 +190,8 @@ public class KeyserverSyncAdapterService extends Service { private void handleUpdateResult(ImportKeyResult result) { if (result.isPending()) { - Log.e(Constants.TAG, "Keyserver sync pending result: " - + result.getRequiredInputParcel().mType); // result is pending due to Orbot not being started - // try to start it silently, if disabled show notificationaa + // try to start it silently, if disabled show notifications new OrbotHelper.SilentStartManager() { @Override protected void onOrbotStarted() { @@ -199,7 +210,8 @@ public class KeyserverSyncAdapterService extends Service { } }.startOrbotAndListen(this, false); } else if (isUpdateCancelled()) { - Log.d(Constants.TAG, "Keyserver sync cancelled"); + Log.d(Constants.TAG, "Keyserver sync cancelled, postponing by" + SYNC_POSTPONE_TIME + + "ms"); postponeSync(); } else { Log.d(Constants.TAG, "Keyserver sync completed: Updated: " + result.mUpdatedKeys @@ -216,14 +228,13 @@ public class KeyserverSyncAdapterService extends Service { PendingIntent.FLAG_UPDATE_CURRENT); alarmManager.set( AlarmManager.ELAPSED_REALTIME_WAKEUP, - SystemClock.elapsedRealtime() + 30 * 1000, + SystemClock.elapsedRealtime() + SYNC_POSTPONE_TIME, pi ); } private void asyncKeyUpdate(final Context context, final CryptoInputParcel cryptoInputParcel) { - Log.e("PHILIP", "async key update starting"); new Thread(new Runnable() { @Override public void run() { @@ -234,7 +245,7 @@ public class KeyserverSyncAdapterService extends Service { } private synchronized ImportKeyResult updateKeysFromKeyserver(final Context context, - final CryptoInputParcel cryptoInputParcel) { + final CryptoInputParcel cryptoInputParcel) { mCancelled.set(false); ArrayList keyList = getKeysToUpdate(context); @@ -278,10 +289,6 @@ public class KeyserverSyncAdapterService extends Service { private ImportKeyResult staggeredUpdate(Context context, ArrayList keyList, CryptoInputParcel cryptoInputParcel) { Log.d(Constants.TAG, "Starting staggered update"); - // assuming maxCircuitDirtiness is 10min in Tor - // final int MAX_CIRCUIT_DIRTINESS = (int) TimeUnit.MINUTES.toSeconds(10); - // TODO: PHILIP remove after testing - final int MAX_CIRCUIT_DIRTINESS = (int) TimeUnit.MINUTES.toSeconds(1); // final int WEEK_IN_SECONDS = (int) TimeUnit.DAYS.toSeconds(7); final int WEEK_IN_SECONDS = 0; ImportOperation.KeyImportAccumulator accumulator @@ -289,10 +296,10 @@ public class KeyserverSyncAdapterService extends Service { for (ParcelableKeyRing keyRing : keyList) { int waitTime; int staggeredTime = new Random().nextInt(1 + 2 * (WEEK_IN_SECONDS / keyList.size())); - if (staggeredTime >= MAX_CIRCUIT_DIRTINESS) { + if (staggeredTime >= ORBOT_CIRCUIT_TIMEOUT) { waitTime = staggeredTime; } else { - waitTime = MAX_CIRCUIT_DIRTINESS + new Random().nextInt(MAX_CIRCUIT_DIRTINESS); + waitTime = ORBOT_CIRCUIT_TIMEOUT + new Random().nextInt(ORBOT_CIRCUIT_TIMEOUT); } Log.d(Constants.TAG, "Updating key with fingerprint " + keyRing.mExpectedFingerprint + " with a wait time of " + waitTime + "s"); @@ -342,18 +349,14 @@ public class KeyserverSyncAdapterService extends Service { final int INDEX_LAST_UPDATED = 1; // all time in seconds not milliseconds - // TODO: PHILIP correct TIME_MAX after testing - // final long TIME_MAX = TimeUnit.DAYS.toSeconds(7); - final long TIME_MAX = 1; final long CURRENT_TIME = GregorianCalendar.getInstance().getTimeInMillis() / 1000; - Log.e("PHILIP", "week: " + TIME_MAX + " current: " + CURRENT_TIME); Cursor updatedKeysCursor = context.getContentResolver().query( KeychainContract.UpdatedKeys.CONTENT_URI, new String[]{ KeychainContract.UpdatedKeys.MASTER_KEY_ID, KeychainContract.UpdatedKeys.LAST_UPDATED }, - "? - " + KeychainContract.UpdatedKeys.LAST_UPDATED + " < " + TIME_MAX, + "? - " + KeychainContract.UpdatedKeys.LAST_UPDATED + " < " + KEY_UPDATE_LIMIT, new String[]{"" + CURRENT_TIME}, null ); @@ -361,7 +364,7 @@ public class KeyserverSyncAdapterService extends Service { ArrayList ignoreMasterKeyIds = new ArrayList<>(); while (updatedKeysCursor.moveToNext()) { long masterKeyId = updatedKeysCursor.getLong(INDEX_UPDATED_KEYS_MASTER_KEY_ID); - Log.d(Constants.TAG, "Keyserver sync: {" + masterKeyId + "} last updated at {" + Log.d(Constants.TAG, "Keyserver sync: Ignoring {" + masterKeyId + "} last updated at {" + updatedKeysCursor.getLong(INDEX_LAST_UPDATED) + "}s"); ignoreMasterKeyIds.add(masterKeyId); } @@ -391,6 +394,7 @@ public class KeyserverSyncAdapterService extends Service { if (ignoreMasterKeyIds.contains(keyId)) { continue; } + Log.d(Constants.TAG, "Keyserver sync: Updating {" + keyId + "}"); String fingerprint = KeyFormattingUtils .convertFingerprintToHex(keyCursor.getBlob(INDEX_FINGERPRINT)); String hexKeyId = KeyFormattingUtils @@ -420,13 +424,6 @@ public class KeyserverSyncAdapterService extends Service { context.startService(intent); } - // TODO: PHILIP remove! - @Override - public void onDestroy() { - Log.e("PHILIP", "onDestroy"); - super.onDestroy(); - } - private Notification getOrbotNoification(Context context) { NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(R.drawable.ic_stat_notify_24dp) @@ -467,6 +464,33 @@ public class KeyserverSyncAdapterService extends Service { return builder.build(); } + public static void enableKeyserverSync(Context context) { + try { + AccountManager manager = AccountManager.get(context); + Account[] accounts = manager.getAccountsByType(Constants.ACCOUNT_TYPE); + + Account account = new Account(Constants.ACCOUNT_NAME, Constants.ACCOUNT_TYPE); + if (accounts.length == 0) { + if (!manager.addAccountExplicitly(account, null, null)) { + Log.e(Constants.TAG, "Adding account failed!"); + } + } + // for keyserver sync + ContentResolver.setIsSyncable(account, Constants.PROVIDER_AUTHORITY, 1); + ContentResolver.setSyncAutomatically(account, Constants.PROVIDER_AUTHORITY, + true); + ContentResolver.addPeriodicSync( + account, + Constants.PROVIDER_AUTHORITY, + new Bundle(), + SYNC_INTERVAL + ); + } catch (SecurityException e) { + Log.e(Constants.TAG, "SecurityException when adding the account", e); + Toast.makeText(context, R.string.reinstall_openkeychain, Toast.LENGTH_LONG).show(); + } + } + // from de.azapps.mirakel.helper.Helpers from https://github.com/MirakelX/mirakel-android private Bitmap getBitmap(int resId, Context context) { int mLargeIconWidth = (int) context.getResources().getDimension( -- cgit v1.2.3 From 7a98ffc90a34a381a68c5b485183373ed307320a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Thu, 27 Aug 2015 12:34:54 +0200 Subject: Remove dead code --- .../java/org/sufficientlysecure/keychain/service/KeychainService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java index dca2a08c2..eff27f112 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java @@ -40,7 +40,7 @@ import org.sufficientlysecure.keychain.operations.PromoteKeyOperation; import org.sufficientlysecure.keychain.operations.RevokeOperation; import org.sufficientlysecure.keychain.operations.SignEncryptOperation; import org.sufficientlysecure.keychain.operations.results.OperationResult; -import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify; +import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.SignEncryptParcel; @@ -111,7 +111,7 @@ public class KeychainService extends Service implements Progressable { op = new SignEncryptOperation(outerThis, new ProviderHelper(outerThis), outerThis, mActionCanceled); } else if (inputParcel instanceof PgpDecryptVerifyInputParcel) { - op = new PgpDecryptVerify(outerThis, new ProviderHelper(outerThis), outerThis); + op = new PgpDecryptVerifyOperation(outerThis, new ProviderHelper(outerThis), outerThis); } else if (inputParcel instanceof SaveKeyringParcel) { op = new EditKeyOperation(outerThis, new ProviderHelper(outerThis), outerThis, mActionCanceled); -- cgit v1.2.3 From dd850e5c72db1601aef54f9f35e1a2b11ae719c5 Mon Sep 17 00:00:00 2001 From: Kaladin Light <0.kaladin@gmail.com> Date: Thu, 3 Sep 2015 13:25:09 -0400 Subject: Fixes open-keychain/open-keychain#1515 Move launcher icons to mipmap --- .../keychain/service/KeyserverSyncAdapterService.java | 2 +- .../sufficientlysecure/keychain/service/PassphraseCacheService.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java index 3243df1a8..8aebae7aa 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java @@ -427,7 +427,7 @@ public class KeyserverSyncAdapterService extends Service { private Notification getOrbotNoification(Context context) { NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(R.drawable.ic_stat_notify_24dp) - .setLargeIcon(getBitmap(R.drawable.ic_launcher, context)) + .setLargeIcon(getBitmap(R.mipmap.ic_launcher, context)) .setContentTitle(context.getString(R.string.keyserver_sync_orbot_notif_title)) .setContentText(context.getString(R.string.keyserver_sync_orbot_notif_msg)) .setAutoCancel(true); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java index be269c66d..5d04317b3 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java @@ -509,7 +509,7 @@ public class PassphraseCacheService extends Service { private Notification getNotification() { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.drawable.ic_stat_notify_24dp) - .setLargeIcon(getBitmap(R.drawable.ic_launcher, getBaseContext())) + .setLargeIcon(getBitmap(R.mipmap.ic_launcher, getBaseContext())) .setContentTitle(getResources().getQuantityString(R.plurals.passp_cache_notif_n_keys, mPassphraseCache.size(), mPassphraseCache.size())) .setContentText(getString(R.string.passp_cache_notif_click_to_clear)); @@ -601,4 +601,4 @@ public class PassphraseCacheService extends Service { this.passphrase = passphrase; } } -} \ No newline at end of file +} -- cgit v1.2.3