diff options
author | Dominik Schürmann <dominik@dominikschuermann.de> | 2013-09-09 19:38:13 +0200 |
---|---|---|
committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2013-09-09 19:38:13 +0200 |
commit | 8a8d7c7738f62eb66e41f7598a5e23a50b2f0821 (patch) | |
tree | 38a5686e7bf36e1606771a5f8faf5a4ec34df50f /OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/CryptoService.java | |
parent | 0a52e1ecc94d26cbc9ced522f3365ae56bbb942c (diff) | |
download | open-keychain-8a8d7c7738f62eb66e41f7598a5e23a50b2f0821.tar.gz open-keychain-8a8d7c7738f62eb66e41f7598a5e23a50b2f0821.tar.bz2 open-keychain-8a8d7c7738f62eb66e41f7598a5e23a50b2f0821.zip |
Handle dublicate or missing pub keys corresponding to user ids, handle navigating back from service activity properly
Diffstat (limited to 'OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/CryptoService.java')
-rw-r--r-- | OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/CryptoService.java | 54 |
1 files changed, 33 insertions, 21 deletions
diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/CryptoService.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/CryptoService.java index ae0e55671..8ff229af0 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/CryptoService.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/CryptoService.java @@ -66,6 +66,17 @@ public class CryptoService extends Service { final Object userInputLock = new Object(); + private class MyBaseCallback implements Handler.Callback { + public static final int OKAY = 1; + public static final int CANCEL = 0; + + @Override + public boolean handleMessage(Message msg) { + return false; + } + + } + @Override public void onCreate() { super.onCreate(); @@ -116,9 +127,7 @@ public class CryptoService extends Service { return passphrase; } - public class PassphraseActivityCallback implements Handler.Callback { - public static final int SUCCESS = 1; - public static final int NO_SUCCESS = 0; + public class PassphraseActivityCallback extends MyBaseCallback { private boolean success = false; @@ -128,7 +137,7 @@ public class CryptoService extends Service { @Override public boolean handleMessage(Message msg) { - if (msg.arg1 == SUCCESS) { + if (msg.arg1 == OKAY) { success = true; } else { success = false; @@ -151,9 +160,13 @@ public class CryptoService extends Service { */ private long[] getKeyIdsFromEmails(String[] encryptionUserIds, long ownKeyId) { // find key ids to given emails in database - boolean manySameUserIds = false; - boolean missingUserIds = false; ArrayList<Long> keyIds = new ArrayList<Long>(); + + boolean missingUserIdsCheck = false; + boolean dublicateUserIdsCheck = false; + ArrayList<String> missingUserIds = new ArrayList<String>(); + ArrayList<String> dublicateUserIds = new ArrayList<String>(); + for (String email : encryptionUserIds) { Uri uri = KeychainContract.KeyRings.buildPublicKeyRingsByEmailsUri(email); Cursor cur = getContentResolver().query(uri, null, null, null, null); @@ -161,11 +174,13 @@ public class CryptoService extends Service { long id = cur.getLong(cur.getColumnIndex(KeychainContract.KeyRings.MASTER_KEY_ID)); keyIds.add(id); } else { - missingUserIds = true; + missingUserIdsCheck = true; + missingUserIds.add(email); Log.d(Constants.TAG, "user id missing"); } if (cur.moveToNext()) { - manySameUserIds = true; + dublicateUserIdsCheck = true; + dublicateUserIds.add(email); Log.d(Constants.TAG, "more than one user id with the same email"); } } @@ -179,12 +194,16 @@ public class CryptoService extends Service { keyIdsArray[i] = keyIds.get(i); } - if (missingUserIds || manySameUserIds) { + if (missingUserIdsCheck || dublicateUserIdsCheck) { SelectPubKeysActivityCallback callback = new SelectPubKeysActivityCallback(); Messenger messenger = new Messenger(new Handler(getMainLooper(), callback)); Bundle extras = new Bundle(); extras.putLongArray(CryptoServiceActivity.EXTRA_SELECTED_MASTER_KEY_IDS, keyIdsArray); + extras.putStringArrayList(CryptoServiceActivity.EXTRA_MISSING_USER_IDS, missingUserIds); + extras.putStringArrayList(CryptoServiceActivity.EXTRA_DUBLICATE_USER_IDS, + dublicateUserIds); + pauseQueueAndStartServiceActivity(CryptoServiceActivity.ACTION_SELECT_PUB_KEYS, messenger, extras); @@ -199,9 +218,7 @@ public class CryptoService extends Service { return keyIdsArray; } - public class SelectPubKeysActivityCallback implements Handler.Callback { - public static final int OKAY = 1; - public static final int CANCEL = 0; + public class SelectPubKeysActivityCallback extends MyBaseCallback { public static final String PUB_KEY_IDS = "pub_key_ids"; private boolean newSelection = false; @@ -540,17 +557,14 @@ public class CryptoService extends Service { if (callback.isAllowed()) { mThreadPool.execute(r); + Log.d(Constants.TAG, "Enqueued runnable…"); } else { Log.d(Constants.TAG, "User disallowed app!"); } - - Log.d(Constants.TAG, "Enqueued runnable…"); } } - public class RegisterActivityCallback implements Handler.Callback { - public static final int ALLOW = 1; - public static final int DISALLOW = 0; + public class RegisterActivityCallback extends MyBaseCallback { public static final String PACKAGE_NAME = "package_name"; private boolean allowed = false; @@ -566,9 +580,7 @@ public class CryptoService extends Service { @Override public boolean handleMessage(Message msg) { - Log.d(Constants.TAG, "msg what: " + msg.what); - - if (msg.arg1 == ALLOW) { + if (msg.arg1 == OKAY) { allowed = true; packageName = msg.getData().getString(PACKAGE_NAME); @@ -591,7 +603,7 @@ public class CryptoService extends Service { } mThreadPool.resume(); } - return false; + return true; } } |