diff --git a/APG/src/org/thialfihar/android/apg/helper/PGPMain.java b/APG/src/org/thialfihar/android/apg/helper/PGPMain.java index 0cde19ae5..bf76901a1 100644 --- a/APG/src/org/thialfihar/android/apg/helper/PGPMain.java +++ b/APG/src/org/thialfihar/android/apg/helper/PGPMain.java @@ -114,7 +114,6 @@ import java.security.SignatureException; import java.util.ArrayList; import java.util.Date; import java.util.Iterator; -import java.util.Vector; import java.util.regex.Pattern; /** @@ -608,12 +607,12 @@ public class PGPMain { return returnData; } - public static Bundle exportKeyRings(Context context, Vector keyRingIds, + public static Bundle exportKeyRings(Context context, ArrayList keyRingRowIds, OutputStream outStream, ProgressDialogUpdater progress) throws ApgGeneralException, FileNotFoundException, PGPException, IOException { Bundle returnData = new Bundle(); - if (keyRingIds.size() == 1) { + if (keyRingRowIds.size() == 1) { updateProgress(progress, R.string.progress_exportingKey, 0, 100); } else { updateProgress(progress, R.string.progress_exportingKeys, 0, 100); @@ -626,17 +625,17 @@ public class PGPMain { out.setHeader("Version", getFullVersion(context)); int numKeys = 0; - for (int i = 0; i < keyRingIds.size(); ++i) { - updateProgress(progress, i * 100 / keyRingIds.size(), 100); + for (int i = 0; i < keyRingRowIds.size(); ++i) { + updateProgress(progress, i * 100 / keyRingRowIds.size(), 100); // try to get it as a PGPPublicKeyRing, if that fails try to get it as a SecretKeyRing - PGPPublicKeyRing publicKeyRing = ProviderHelper.getPGPPublicKeyRingByMasterKeyId( - context, keyRingIds.get(i)); + PGPPublicKeyRing publicKeyRing = ProviderHelper.getPGPPublicKeyRingByRowId(context, + keyRingRowIds.get(i)); if (publicKeyRing != null) { publicKeyRing.encode(out); } else { - PGPSecretKeyRing secretKeyRing = ProviderHelper.getPGPSecretKeyRingByMasterKeyId( - context, keyRingIds.get(i)); + PGPSecretKeyRing secretKeyRing = ProviderHelper.getPGPSecretKeyRingByRowId(context, + keyRingRowIds.get(i)); if (secretKeyRing != null) { secretKeyRing.encode(out); } else { diff --git a/APG/src/org/thialfihar/android/apg/provider/ProviderHelper.java b/APG/src/org/thialfihar/android/apg/provider/ProviderHelper.java index 915c0aea5..611b647e6 100644 --- a/APG/src/org/thialfihar/android/apg/provider/ProviderHelper.java +++ b/APG/src/org/thialfihar/android/apg/provider/ProviderHelper.java @@ -19,7 +19,6 @@ package org.thialfihar.android.apg.provider; import java.io.IOException; import java.util.ArrayList; import java.util.Date; -import java.util.Vector; import org.spongycastle.openpgp.PGPKeyRing; import org.spongycastle.openpgp.PGPPublicKey; @@ -232,7 +231,8 @@ public class ProviderHelper { } try { - context.getContentResolver().applyBatch(ApgContract.CONTENT_AUTHORITY_INTERNAL, operations); + context.getContentResolver().applyBatch(ApgContract.CONTENT_AUTHORITY_INTERNAL, + operations); } catch (RemoteException e) { Log.e(Constants.TAG, "applyBatch failed!", e); } catch (OperationApplicationException e) { @@ -288,7 +288,8 @@ public class ProviderHelper { } try { - context.getContentResolver().applyBatch(ApgContract.CONTENT_AUTHORITY_INTERNAL, operations); + context.getContentResolver().applyBatch(ApgContract.CONTENT_AUTHORITY_INTERNAL, + operations); } catch (RemoteException e) { Log.e(Constants.TAG, "applyBatch failed!", e); } catch (OperationApplicationException e) { @@ -415,16 +416,16 @@ public class ProviderHelper { * @param queryUri * @return */ - private static Vector getKeyRingsRowIds(Context context, Uri queryUri) { + private static ArrayList getKeyRingsRowIds(Context context, Uri queryUri) { Cursor cursor = context.getContentResolver().query(queryUri, new String[] { KeyRings._ID }, null, null, null); - Vector keyIds = new Vector(); + ArrayList keyIds = new ArrayList(); if (cursor != null) { int idCol = cursor.getColumnIndex(KeyRings._ID); if (cursor.moveToFirst()) { do { - keyIds.add(cursor.getInt(idCol)); + keyIds.add(cursor.getLong(idCol)); } while (cursor.moveToNext()); } } @@ -442,7 +443,7 @@ public class ProviderHelper { * @param context * @return */ - public static Vector getSecretKeyRingsRowIds(Context context) { + public static ArrayList getSecretKeyRingsRowIds(Context context) { Uri queryUri = KeyRings.buildSecretKeyRingsUri(); return getKeyRingsRowIds(context, queryUri); } @@ -453,7 +454,7 @@ public class ProviderHelper { * @param context * @return */ - public static Vector getPublicKeyRingsRowIds(Context context) { + public static ArrayList getPublicKeyRingsRowIds(Context context) { Uri queryUri = KeyRings.buildPublicKeyRingsUri(); return getKeyRingsRowIds(context, queryUri); } diff --git a/APG/src/org/thialfihar/android/apg/service/ApgIntentService.java b/APG/src/org/thialfihar/android/apg/service/ApgIntentService.java index 8a6ca6b4c..b50cb1789 100644 --- a/APG/src/org/thialfihar/android/apg/service/ApgIntentService.java +++ b/APG/src/org/thialfihar/android/apg/service/ApgIntentService.java @@ -26,7 +26,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; -import java.util.Vector; import org.spongycastle.openpgp.PGPPublicKeyRing; import org.spongycastle.openpgp.PGPSecretKey; @@ -145,7 +144,7 @@ public class ApgIntentService extends IntentService implements ProgressDialogUpd public static final String EXPORT_FILENAME = "exportFilename"; public static final String EXPORT_KEY_TYPE = "exportKeyType"; public static final String EXPORT_ALL = "exportAll"; - public static final String EXPORT_KEY_RING_ID = "exportKeyRingId"; + public static final String EXPORT_KEY_RING_ROW_ID = "exportKeyRingId"; // upload key public static final String UPLOAD_KEY_SERVER = "uploadKeyServer"; @@ -692,9 +691,9 @@ public class ApgIntentService extends IntentService implements ProgressDialogUpd String outputFile = data.getString(EXPORT_FILENAME); boolean exportAll = data.getBoolean(EXPORT_ALL); - int keyRingId = -1; + long keyRingRowId = -1; if (!exportAll) { - keyRingId = data.getInt(EXPORT_KEY_RING_ID); + keyRingRowId = data.getLong(EXPORT_KEY_RING_ROW_ID); } /* Operation */ @@ -707,19 +706,21 @@ public class ApgIntentService extends IntentService implements ProgressDialogUpd // OutputStream FileOutputStream outStream = new FileOutputStream(outputFile); - Vector keyRingIds = new Vector(); + ArrayList keyRingRowIds = new ArrayList(); if (exportAll) { + // get all key ring row ids based on export type + if (keyType == Id.type.public_key) { - keyRingIds = ProviderHelper.getPublicKeyRingsRowIds(this); + keyRingRowIds = ProviderHelper.getPublicKeyRingsRowIds(this); } else { - keyRingIds = ProviderHelper.getSecretKeyRingsRowIds(this); + keyRingRowIds = ProviderHelper.getSecretKeyRingsRowIds(this); } } else { - keyRingIds.add(keyRingId); + keyRingRowIds.add(keyRingRowId); } Bundle resultData = new Bundle(); - resultData = PGPMain.exportKeyRings(this, keyRingIds, outStream, this); + resultData = PGPMain.exportKeyRings(this, keyRingRowIds, outStream, this); sendMessageToHandler(ApgIntentServiceHandler.MESSAGE_OKAY, resultData); } catch (Exception e) { diff --git a/APG/src/org/thialfihar/android/apg/ui/KeyListActivity.java b/APG/src/org/thialfihar/android/apg/ui/KeyListActivity.java index 118a5950a..b36300769 100644 --- a/APG/src/org/thialfihar/android/apg/ui/KeyListActivity.java +++ b/APG/src/org/thialfihar/android/apg/ui/KeyListActivity.java @@ -69,22 +69,37 @@ public class KeyListActivity extends SherlockFragmentActivity { getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); - handleIntent(getIntent()); + handleActions(getIntent()); } - @Override - protected void onNewIntent(Intent intent) { - super.onNewIntent(intent); - handleIntent(intent); - } + // TODO: needed? + // @Override + // protected void onNewIntent(Intent intent) { + // super.onNewIntent(intent); + // handleActions(intent); + // } - protected void handleIntent(Intent intent) { + protected void handleActions(Intent intent) { + String action = intent.getAction(); + Bundle extras = intent.getExtras(); + + if (extras == null) { + extras = new Bundle(); + } + + /** + * Android Standard Actions + */ String searchString = null; - if (Intent.ACTION_SEARCH.equals(intent.getAction())) { - searchString = intent.getStringExtra(SearchManager.QUERY); + if (Intent.ACTION_SEARCH.equals(action)) { + searchString = extras.getString(SearchManager.QUERY); if (searchString != null && searchString.trim().length() == 0) { searchString = null; } + } else if (Intent.ACTION_VIEW.equals(action)) { + // Android's Action when opening file associated to APG (see AndroidManifest.xml) + // override action to delegate it to APGs ACTION_IMPORT + action = ACTION_IMPORT; } // if (searchString == null) { @@ -100,35 +115,19 @@ public class KeyListActivity extends SherlockFragmentActivity { // mListAdapter = new KeyListAdapter(this, searchString); // mList.setAdapter(mListAdapter); - // Get intent, action - // Intent intent = getIntent(); - String action = intent.getAction(); - - if (Intent.ACTION_VIEW.equals(action)) { - // Android's Action when opening file associated to APG (see AndroidManifest.xml) - - handleActionImport(intent); - } else if (ACTION_IMPORT.equals(action)) { - // APG's own Actions - - handleActionImport(intent); + /** + * APG's own Actions + */ + if (ACTION_IMPORT.equals(action)) { + if ("file".equals(intent.getScheme()) && intent.getDataString() != null) { + mImportFilename = intent.getData().getPath(); + } else { + mImportData = intent.getStringExtra(EXTRA_TEXT); + } + importKeys(); } } - /** - * Handles import action - * - * @param intent - */ - private void handleActionImport(Intent intent) { - if ("file".equals(intent.getScheme()) && intent.getDataString() != null) { - mImportFilename = intent.getData().getPath(); - } else { - mImportData = intent.getStringExtra(EXTRA_TEXT); - } - importKeys(); - } - @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { @@ -230,12 +229,12 @@ public class KeyListActivity extends SherlockFragmentActivity { /** * Show dialog where to export keys * - * @param keyRingId + * @param keyRingRowId * if -1 export all keys */ - public void showExportKeysDialog(final long keyRingId) { + public void showExportKeysDialog(final long keyRingRowId) { String title = null; - if (keyRingId != -1) { + if (keyRingRowId != -1) { // single key export title = getString(R.string.title_exportKey); } else { @@ -257,7 +256,7 @@ public class KeyListActivity extends SherlockFragmentActivity { Bundle data = message.getData(); mExportFilename = data.getString(FileDialogFragment.MESSAGE_DATA_FILENAME); - exportKeys(keyRingId); + exportKeys(keyRingRowId); } } }; @@ -389,10 +388,10 @@ public class KeyListActivity extends SherlockFragmentActivity { /** * Export keys * - * @param keyRingId + * @param keyRingRowId * if -1 export all keys */ - public void exportKeys(long keyRingId) { + public void exportKeys(long keyRingRowId) { Log.d(Constants.TAG, "exportKeys started"); // Send all information needed to service to export key in other thread @@ -406,10 +405,10 @@ public class KeyListActivity extends SherlockFragmentActivity { data.putString(ApgIntentService.EXPORT_FILENAME, mExportFilename); data.putInt(ApgIntentService.EXPORT_KEY_TYPE, mKeyType); - if (keyRingId == -1) { + if (keyRingRowId == -1) { data.putBoolean(ApgIntentService.EXPORT_ALL, true); } else { - data.putLong(ApgIntentService.EXPORT_KEY_RING_ID, keyRingId); + data.putLong(ApgIntentService.EXPORT_KEY_RING_ROW_ID, keyRingRowId); } intent.putExtra(ApgIntentService.EXTRA_DATA, data); diff --git a/APG/src/org/thialfihar/android/apg/ui/KeyListPublicActivity.java b/APG/src/org/thialfihar/android/apg/ui/KeyListPublicActivity.java index 73bb3790a..f8b8ccc85 100644 --- a/APG/src/org/thialfihar/android/apg/ui/KeyListPublicActivity.java +++ b/APG/src/org/thialfihar/android/apg/ui/KeyListPublicActivity.java @@ -89,7 +89,7 @@ public class KeyListPublicActivity extends KeyListActivity { intent.setAction(KeyListPublicActivity.ACTION_IMPORT); intent.putExtra(KeyListPublicActivity.EXTRA_TEXT, data.getStringExtra(KeyListActivity.EXTRA_TEXT)); - handleIntent(intent); + handleActions(intent); break; }