aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'OpenKeychain/src/main')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ExportOperation.java22
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java33
2 files changed, 31 insertions, 24 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ExportOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ExportOperation.java
index 82b72c1fc..56ed4ef58 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ExportOperation.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ExportOperation.java
@@ -27,12 +27,14 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Proxy;
+import java.util.Collections;
import java.util.concurrent.atomic.AtomicBoolean;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.support.annotation.NonNull;
+import android.text.TextUtils;
import org.spongycastle.bcpg.ArmoredOutputStream;
import org.sufficientlysecure.keychain.Constants;
@@ -211,21 +213,21 @@ public class ExportOperation extends BaseOperation<ExportKeyringParcel> {
Cursor cursor = null;
try {
- String selection = null, ids[] = null;
+ String selection = null, selectionArgs[] = null;
if (masterKeyIds != null) {
- // generate placeholders and string selection args
- ids = new String[masterKeyIds.length];
- StringBuilder placeholders = new StringBuilder("?");
+ // convert long[] to String[]
+ selectionArgs = new String[masterKeyIds.length];
for (int i = 0; i < masterKeyIds.length; i++) {
- ids[i] = Long.toString(masterKeyIds[i]);
- if (i != 0) {
- placeholders.append(",?");
- }
+ selectionArgs[i] = Long.toString(masterKeyIds[i]);
}
+ // generates ?,?,? as placeholders for selectionArgs
+ String placeholders = TextUtils.join(",",
+ Collections.nCopies(masterKeyIds.length, "?"));
+
// put together selection string
- selection = Tables.KEY_RINGS_PUBLIC + "." + KeyRings.MASTER_KEY_ID
+ selection = Tables.KEYS + "." + KeyRings.MASTER_KEY_ID
+ " IN (" + placeholders + ")";
}
@@ -233,7 +235,7 @@ public class ExportOperation extends BaseOperation<ExportKeyringParcel> {
KeyRings.buildUnifiedKeyRingsUri(), new String[]{
KeyRings.MASTER_KEY_ID, KeyRings.PUBKEY_DATA,
KeyRings.PRIVKEY_DATA, KeyRings.HAS_ANY_SECRET
- }, selection, ids, Tables.KEYS + "." + KeyRings.MASTER_KEY_ID
+ }, selection, selectionArgs, Tables.KEYS + "." + KeyRings.MASTER_KEY_ID
);
if (cursor == null || !cursor.moveToFirst()) {
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 c5bfdbedf..bb19fe2b1 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java
@@ -118,6 +118,7 @@ public class KeyListFragment extends LoaderFragment
// This ids for multiple key export.
private ArrayList<Long> mIdsForRepeatAskPassphrase;
+ private ArrayList<Long> mIdsForExport;
// This index for remembering the number of master key.
private int mIndex;
@@ -642,6 +643,7 @@ public class KeyListFragment extends LoaderFragment
private void showMultiExportDialog(long[] masterKeyIds) {
mIdsForRepeatAskPassphrase = new ArrayList<>();
+ mIdsForExport = new ArrayList<>();
for (long id : masterKeyIds) {
try {
if (PassphraseCacheService.getCachedPassphrase(
@@ -651,6 +653,7 @@ public class KeyListFragment extends LoaderFragment
} catch (PassphraseCacheService.KeyNotFoundException e) {
// This happens when the master key is stripped
// and ignore this key.
+ mIdsForExport.add(id);
}
}
mIndex = 0;
@@ -658,13 +661,9 @@ public class KeyListFragment extends LoaderFragment
startPassphraseActivity();
return;
}
- long[] idsForMultiExport = new long[mIdsForRepeatAskPassphrase.size()];
- for (int i = 0; i < mIdsForRepeatAskPassphrase.size(); ++i) {
- idsForMultiExport[i] = mIdsForRepeatAskPassphrase.get(i);
- }
- mExportHelper.showExportKeysDialog(idsForMultiExport,
- Constants.Path.APP_DIR_FILE,
- mAdapter.isAnySecretSelected());
+
+ mIdsForExport.addAll(mIdsForRepeatAskPassphrase);
+ finishExport();
}
private void startPassphraseActivity() {
@@ -674,6 +673,16 @@ public class KeyListFragment extends LoaderFragment
startActivityForResult(intent, REQUEST_REPEAT_PASSPHRASE);
}
+ private void finishExport() {
+ long[] idsForMultiExport = new long[mIdsForExport.size()];
+ for (int i = 0; i < mIdsForExport.size(); i++) {
+ idsForMultiExport[i] = mIdsForExport.get(i);
+ }
+ mExportHelper.showExportKeysDialog(idsForMultiExport,
+ Constants.Path.APP_DIR_FILE,
+ mAdapter.isAnySecretSelected());
+ }
+
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (mImportOpHelper != null) {
@@ -692,13 +701,9 @@ public class KeyListFragment extends LoaderFragment
startPassphraseActivity();
return;
}
- long[] idsForMultiExport = new long[mIdsForRepeatAskPassphrase.size()];
- for (int i = 0; i < mIdsForRepeatAskPassphrase.size(); ++i) {
- idsForMultiExport[i] = mIdsForRepeatAskPassphrase.get(i);
- }
- mExportHelper.showExportKeysDialog(idsForMultiExport,
- Constants.Path.APP_DIR_FILE,
- mAdapter.isAnySecretSelected());
+
+ mIdsForExport.addAll(mIdsForRepeatAskPassphrase);
+ finishExport();
}
if (requestCode == REQUEST_ACTION) {