aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java
diff options
context:
space:
mode:
authorAdithya Abraham Philip <adithyaphilip@gmail.com>2015-03-19 20:31:34 +0530
committerAdithya Abraham Philip <adithyaphilip@gmail.com>2015-03-23 15:34:22 +0530
commit19775c399b106149e8906a7482a4b5a4af2ac8fa (patch)
tree6741a8820aaa29adaa05cbfc05cd8f51f0d826b1 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java
parent208434087fe9eb7bd88d491bb14db05e702d7845 (diff)
downloadopen-keychain-19775c399b106149e8906a7482a4b5a4af2ac8fa.tar.gz
open-keychain-19775c399b106149e8906a7482a4b5a4af2ac8fa.tar.bz2
open-keychain-19775c399b106149e8906a7482a4b5a4af2ac8fa.zip
introduced multi-threading
refactored oldKeys to updatedKeys added update all keys, ThreadPoolExecutor used modified CachedThreadPoolExecutor
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java88
1 files changed, 88 insertions, 0 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java
index 5f1189deb..513da7785 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java
@@ -20,6 +20,7 @@ package org.sufficientlysecure.keychain.ui;
import android.animation.ObjectAnimator;
import android.annotation.TargetApi;
+import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
@@ -58,13 +59,17 @@ import com.getbase.floatingactionbutton.FloatingActionsMenu;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
+import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
+import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
import org.sufficientlysecure.keychain.operations.results.ConsolidateResult;
import org.sufficientlysecure.keychain.operations.results.DeleteResult;
+import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
import org.sufficientlysecure.keychain.operations.results.OperationResult;
import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainDatabase;
+import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment;
@@ -78,6 +83,7 @@ import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Preferences;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.HashMap;
import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter;
@@ -477,6 +483,10 @@ public class KeyListFragment extends LoaderFragment
mExportHelper.showExportKeysDialog(null, Constants.Path.APP_DIR_FILE, true);
return true;
+ case R.id.menu_key_list_update_all_keys:
+ updateAllKeys();
+ return true;
+
case R.id.menu_key_list_debug_cons:
consolidate();
return true;
@@ -561,6 +571,84 @@ public class KeyListFragment extends LoaderFragment
startActivityForResult(intent, 0);
}
+ private void updateAllKeys() {
+ Context context = this.getActivity();
+
+ ProviderHelper providerHelper = new ProviderHelper(context);
+
+ Cursor cursor = providerHelper.getContentResolver().query(
+ KeyRings.buildUnifiedKeyRingsUri(), new String[]{
+ KeyRings.FINGERPRINT
+ }, null, null, null
+ );
+
+ ArrayList<ParcelableKeyRing> keyList = new ArrayList<>();
+
+ while (cursor.moveToNext()) {
+ byte[] blob = cursor.getBlob(0);//fingerprint column is 0
+ String fingerprint = KeyFormattingUtils.convertFingerprintToHex(blob);
+ ParcelableKeyRing keyEntry = new ParcelableKeyRing(fingerprint, null, null);
+ keyList.add(keyEntry);
+ }
+
+ KeychainIntentServiceHandler serviceHandler = new KeychainIntentServiceHandler(
+ getActivity(),
+ getString(R.string.progress_importing),
+ ProgressDialog.STYLE_HORIZONTAL,
+ true) {
+ public void handleMessage(Message message) {
+ // handle messages by standard KeychainIntentServiceHandler first
+ super.handleMessage(message);
+
+ if (message.arg1 == MessageStatus.OKAY.ordinal()) {
+ // get returned data bundle
+ Bundle returnData = message.getData();
+ if (returnData == null) {
+ return;
+ }
+ final ImportKeyResult result =
+ returnData.getParcelable(OperationResult.EXTRA_RESULT);
+ if (result == null) {
+ Log.e(Constants.TAG, "result == null");
+ return;
+ }
+
+ result.createNotify(KeyListFragment.this.getActivity()).show();
+ }
+ }
+ };
+
+ // Send all information needed to service to query keys in other thread
+ Intent intent = new Intent(getActivity(), KeychainIntentService.class);
+
+ intent.setAction(KeychainIntentService.ACTION_IMPORT_KEYRING);
+
+ // fill values for this action
+ Bundle data = new Bundle();
+
+ // search config
+ {
+ Preferences prefs = Preferences.getPreferences(getActivity());
+ Preferences.CloudSearchPrefs cloudPrefs =
+ new Preferences.CloudSearchPrefs(true, true, prefs.getPreferredKeyserver());
+ data.putString(KeychainIntentService.IMPORT_KEY_SERVER, cloudPrefs.keyserver);
+ }
+
+ data.putParcelableArrayList(KeychainIntentService.IMPORT_KEY_LIST, keyList);
+
+ intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
+
+ // Create a new Messenger for the communication back
+ Messenger messenger = new Messenger(serviceHandler);
+ intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
+
+ // show progress dialog
+ serviceHandler.showProgressDialog(getActivity());
+
+ // start service with intent
+ getActivity().startService(intent);
+ }
+
private void consolidate() {
// Message is received after importing is done in KeychainIntentService
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(