From 1d2c93ca8ae4c75e92b5da74e262b9476f22f172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Thu, 31 Jul 2014 16:15:36 +0200 Subject: [PATCH] More file association hacks for AndroidManifest and key import --- OpenKeychain/src/main/AndroidManifest.xml | 240 ++++++++++++++---- .../keychain/ui/ImportKeysListFragment.java | 9 +- .../ui/adapter/ImportKeysListLoader.java | 29 ++- 3 files changed, 221 insertions(+), 57 deletions(-) diff --git a/OpenKeychain/src/main/AndroidManifest.xml b/OpenKeychain/src/main/AndroidManifest.xml index 8d3518a81..7af9d895f 100644 --- a/OpenKeychain/src/main/AndroidManifest.xml +++ b/OpenKeychain/src/main/AndroidManifest.xml @@ -31,7 +31,7 @@ For OI Filemanager it makes no difference, gpg files can't be associated --> - + @@ -223,28 +223,8 @@ - - - - - - - - - - - - - - - - - - - - - + @@ -255,6 +235,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -343,28 +421,8 @@ - - - - - - - - - - - - - - - - - - - - - + @@ -375,7 +433,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java index 9a39b6cc3..469601a54 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java @@ -35,7 +35,6 @@ import org.sufficientlysecure.keychain.helper.Preferences; import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry; import org.sufficientlysecure.keychain.keyimport.Keyserver; import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; -import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.ui.adapter.AsyncTaskResultWrapper; import org.sufficientlysecure.keychain.ui.adapter.ImportKeysAdapter; import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListKeybaseLoader; @@ -288,13 +287,13 @@ public class ImportKeysListFragment extends ListFragment implements if (error == null) { // No error mCachedKeyData = ((ImportKeysListLoader) loader).getParcelableRings(); - } else if (error instanceof ImportKeysListLoader.FileHasNoContent) { + } else if (error instanceof ImportKeysListLoader.FileHasNoContentException) { Notify.showNotify(getActivity(), R.string.error_import_file_no_content, Notify.Style.ERROR); - } else if (error instanceof ImportKeysListLoader.NonPgpPart) { + } else if (error instanceof ImportKeysListLoader.NonPgpPartException) { Notify.showNotify(getActivity(), - ((ImportKeysListLoader.NonPgpPart) error).getCount() + " " + getResources(). + ((ImportKeysListLoader.NonPgpPartException) error).getCount() + " " + getResources(). getQuantityString(R.plurals.error_import_non_pgp_part, - ((ImportKeysListLoader.NonPgpPart) error).getCount()), + ((ImportKeysListLoader.NonPgpPartException) error).getCount()), Notify.Style.OK ); } else { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java index 99f959035..4a8eb0cb1 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java @@ -30,20 +30,20 @@ import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.PositionAwareInputStream; import java.io.BufferedInputStream; +import java.io.IOException; import java.util.ArrayList; import java.util.List; public class ImportKeysListLoader extends AsyncTaskLoader>> { - public static class FileHasNoContent extends Exception { - + public static class FileHasNoContentException extends Exception { } - public static class NonPgpPart extends Exception { + public static class NonPgpPartException extends Exception { private int mCount; - public NonPgpPart(int count) { + public NonPgpPartException(int count) { this.mCount = count; } @@ -67,7 +67,6 @@ public class ImportKeysListLoader @Override public AsyncTaskResultWrapper> loadInBackground() { - // This has already been loaded! nvm any further, just return if (mEntryListWrapper != null) { return mEntryListWrapper; @@ -119,7 +118,6 @@ public class ImportKeysListLoader * @return */ private void generateListOfKeyrings(InputData inputData) { - boolean isEmpty = true; PositionAwareInputStream progressIn = new PositionAwareInputStream( @@ -129,13 +127,14 @@ public class ImportKeysListLoader // PGPObject chunks after the first one, e.g. files with several consecutive ASCII // armor blocks BufferedInputStream bufferedInput = new BufferedInputStream(progressIn); + bufferedInput.mark(1024); try { // read all available blocks... (asc files can contain many blocks with BEGIN END) while (bufferedInput.available() > 0) { // TODO: deal with non-keyring objects? List rings = UncachedKeyRing.fromStream(bufferedInput); - for(UncachedKeyRing key : rings) { + for (UncachedKeyRing key : rings) { ImportKeysListEntry item = new ImportKeysListEntry(getContext(), key); mData.add(item); mParcelableRings.put(item.hashCode(), new ParcelableKeyRing(key.getEncoded())); @@ -144,14 +143,26 @@ public class ImportKeysListLoader } } catch (Exception e) { Log.e(Constants.TAG, "Exception on parsing key file!", e); + + try { + bufferedInput.reset(); + } catch (IOException e1) { + } + Log.d(Constants.TAG, "Last 1024 byte input data: " + convertStreamToString(bufferedInput)); mEntryListWrapper = new AsyncTaskResultWrapper>(mData, e); } if (isEmpty) { - Log.e(Constants.TAG, "File has no content!", new FileHasNoContent()); + FileHasNoContentException e = new FileHasNoContentException(); + Log.e(Constants.TAG, "File has no content!", e); mEntryListWrapper = new AsyncTaskResultWrapper> - (mData, new FileHasNoContent()); + (mData, e); } } + static String convertStreamToString(java.io.InputStream is) { + java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A"); + return s.hasNext() ? s.next() : ""; + } + }