More file association hacks for AndroidManifest and key import

This commit is contained in:
Dominik Schürmann 2014-07-31 16:15:36 +02:00
parent 927b120275
commit 1d2c93ca8a
3 changed files with 221 additions and 57 deletions

View File

@ -31,7 +31,7 @@
For OI Filemanager it makes no difference, gpg files can't be associated For OI Filemanager it makes no difference, gpg files can't be associated
--> -->
<!-- Specified in buid.gradle --> <!-- Specified in build.gradle -->
<!--<uses-sdk--> <!--<uses-sdk-->
<!--android:minSdkVersion="9"--> <!--android:minSdkVersion="9"-->
<!--android:targetSdkVersion="19" />--> <!--android:targetSdkVersion="19" />-->
@ -223,28 +223,8 @@
<data android:host="*" /> <data android:host="*" />
<data android:scheme="file" /> <data android:scheme="file" />
<data android:scheme="content" /> <data android:scheme="content" />
<!-- Workaround to match files in pathes with dots in them, like /cdcard/my.folder/test.gpg -->
<data android:pathPattern=".*\\.gpg" />
<data android:pathPattern=".*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
</intent-filter>
<intent-filter android:label="@string/intent_decrypt_file">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" /> <!-- GnuPG ASCII data, mostly keys, but sometimes signatures and encrypted data -->
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="*" />
<data android:scheme="file" />
<data android:scheme="content" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.asc" /> <data android:pathPattern=".*\\.asc" />
<data android:pathPattern=".*\\..*\\.asc" /> <data android:pathPattern=".*\\..*\\.asc" />
<data android:pathPattern=".*\\..*\\..*\\.asc" /> <data android:pathPattern=".*\\..*\\..*\\.asc" />
@ -255,6 +235,101 @@
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.asc" /> <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.asc" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.asc" /> <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.asc" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.asc" /> <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.asc" />
<!-- GnuPG binary encrypted/signed data, binary format -->
<data android:pathPattern=".*\\.gpg" />
<data android:pathPattern=".*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
<!-- PGP encrypted data, binary format -->
<data android:pathPattern=".*\\.pgp" />
<data android:pathPattern=".*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.pgp" />
<!-- on some mail clients, PGP attachments show up as *.bin -->
<data android:pathPattern=".*\\.bin" />
<data android:pathPattern=".*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.bin" />
</intent-filter>
<!--
Some apps will only respect these file associations
if the mimeType is not set, and other apps will only respect them if mimeType is set
to */*. Therefore we have two whole copies of the same thing, besides setting the mimeType.
-->
<intent-filter android:label="@string/intent_decrypt_file">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="*" />
<data android:scheme="file" />
<data android:scheme="content" />
<data android:mimeType="*/*" />
<!-- GnuPG ASCII data, mostly keys, but sometimes signatures and encrypted data -->
<data android:pathPattern=".*\\.asc" />
<data android:pathPattern=".*\\..*\\.asc" />
<data android:pathPattern=".*\\..*\\..*\\.asc" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.asc" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.asc" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.asc" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.asc" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.asc" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.asc" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.asc" />
<!-- GnuPG binary encrypted/signed data, binary format -->
<data android:pathPattern=".*\\.gpg" />
<data android:pathPattern=".*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
<!-- PGP encrypted data, binary format -->
<data android:pathPattern=".*\\.pgp" />
<data android:pathPattern=".*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.pgp" />
<!-- on some mail clients, PGP attachments show up as *.bin -->
<data android:pathPattern=".*\\.bin" />
<data android:pathPattern=".*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.bin" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity <activity
@ -324,6 +399,9 @@
<!-- mime type as defined in http://tools.ietf.org/html/rfc3156 --> <!-- mime type as defined in http://tools.ietf.org/html/rfc3156 -->
<data android:mimeType="application/pgp-keys" /> <data android:mimeType="application/pgp-keys" />
<!-- also link to text/plain, AOSP mail and K-9 mail only give mimeType text/plain
when the key file has been manually attached -->
<data android:mimeType="text/plain" />
</intent-filter> </intent-filter>
<!-- NFC: Handle NFC tags detected from outside our application --> <!-- NFC: Handle NFC tags detected from outside our application -->
<intent-filter> <intent-filter>
@ -343,28 +421,8 @@
<data android:host="*" /> <data android:host="*" />
<data android:scheme="file" /> <data android:scheme="file" />
<data android:scheme="content" /> <data android:scheme="content" />
<data android:pathPattern=".*\\.gpg" />
<data android:pathPattern=".*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
</intent-filter>
<!-- VIEW with file endings: *.asc -->
<intent-filter android:label="@string/intent_import_key">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" /> <!-- GnuPG ASCII data, mostly keys, but sometimes signatures and encrypted data -->
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="*" />
<data android:scheme="file" />
<data android:scheme="content" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.asc" /> <data android:pathPattern=".*\\.asc" />
<data android:pathPattern=".*\\..*\\.asc" /> <data android:pathPattern=".*\\..*\\.asc" />
<data android:pathPattern=".*\\..*\\..*\\.asc" /> <data android:pathPattern=".*\\..*\\..*\\.asc" />
@ -375,7 +433,103 @@
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.asc" /> <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.asc" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.asc" /> <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.asc" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.asc" /> <data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.asc" />
<!-- GnuPG binary encrypted/signed data, binary format -->
<data android:pathPattern=".*\\.gpg" />
<data android:pathPattern=".*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
<!-- PGP encrypted data, binary format -->
<data android:pathPattern=".*\\.pgp" />
<data android:pathPattern=".*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.pgp" />
<!-- on some mail clients, PGP attachments show up as *.bin -->
<data android:pathPattern=".*\\.bin" />
<data android:pathPattern=".*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.bin" />
</intent-filter> </intent-filter>
<!--
Some apps will only respect these file associations
if the mimeType is not set, and other apps will only respect them if mimeType is set
to */*. Therefore we have two whole copies of the same thing, besides setting the mimeType.
-->
<intent-filter android:label="@string/intent_import_key">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="*" />
<data android:scheme="file" />
<data android:scheme="content" />
<data android:mimeType="*/*" />
<!-- GnuPG ASCII data, mostly keys, but sometimes signatures and encrypted data -->
<data android:pathPattern=".*\\.asc" />
<data android:pathPattern=".*\\..*\\.asc" />
<data android:pathPattern=".*\\..*\\..*\\.asc" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.asc" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.asc" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.asc" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.asc" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.asc" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.asc" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.asc" />
<!-- GnuPG binary encrypted/signed data, binary format -->
<data android:pathPattern=".*\\.gpg" />
<data android:pathPattern=".*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.gpg" />
<!-- PGP encrypted data, binary format -->
<data android:pathPattern=".*\\.pgp" />
<data android:pathPattern=".*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.pgp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.pgp" />
<!-- on some mail clients, PGP attachments show up as *.bin -->
<data android:pathPattern=".*\\.bin" />
<data android:pathPattern=".*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.bin" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.bin" />
</intent-filter>
<!-- Keychain's own Actions --> <!-- Keychain's own Actions -->
<!-- IMPORT_KEY with files TODO: does this work? --> <!-- IMPORT_KEY with files TODO: does this work? -->
<intent-filter android:label="@string/intent_import_key"> <intent-filter android:label="@string/intent_import_key">

View File

@ -35,7 +35,6 @@ import org.sufficientlysecure.keychain.helper.Preferences;
import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry; import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
import org.sufficientlysecure.keychain.keyimport.Keyserver; import org.sufficientlysecure.keychain.keyimport.Keyserver;
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; 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.AsyncTaskResultWrapper;
import org.sufficientlysecure.keychain.ui.adapter.ImportKeysAdapter; import org.sufficientlysecure.keychain.ui.adapter.ImportKeysAdapter;
import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListKeybaseLoader; import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListKeybaseLoader;
@ -288,13 +287,13 @@ public class ImportKeysListFragment extends ListFragment implements
if (error == null) { if (error == null) {
// No error // No error
mCachedKeyData = ((ImportKeysListLoader) loader).getParcelableRings(); 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); 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(), Notify.showNotify(getActivity(),
((ImportKeysListLoader.NonPgpPart) error).getCount() + " " + getResources(). ((ImportKeysListLoader.NonPgpPartException) error).getCount() + " " + getResources().
getQuantityString(R.plurals.error_import_non_pgp_part, getQuantityString(R.plurals.error_import_non_pgp_part,
((ImportKeysListLoader.NonPgpPart) error).getCount()), ((ImportKeysListLoader.NonPgpPartException) error).getCount()),
Notify.Style.OK Notify.Style.OK
); );
} else { } else {

View File

@ -30,20 +30,20 @@ import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.PositionAwareInputStream; import org.sufficientlysecure.keychain.util.PositionAwareInputStream;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class ImportKeysListLoader public class ImportKeysListLoader
extends AsyncTaskLoader<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> { extends AsyncTaskLoader<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> {
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; private int mCount;
public NonPgpPart(int count) { public NonPgpPartException(int count) {
this.mCount = count; this.mCount = count;
} }
@ -67,7 +67,6 @@ public class ImportKeysListLoader
@Override @Override
public AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>> loadInBackground() { public AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>> loadInBackground() {
// This has already been loaded! nvm any further, just return // This has already been loaded! nvm any further, just return
if (mEntryListWrapper != null) { if (mEntryListWrapper != null) {
return mEntryListWrapper; return mEntryListWrapper;
@ -119,7 +118,6 @@ public class ImportKeysListLoader
* @return * @return
*/ */
private void generateListOfKeyrings(InputData inputData) { private void generateListOfKeyrings(InputData inputData) {
boolean isEmpty = true; boolean isEmpty = true;
PositionAwareInputStream progressIn = new PositionAwareInputStream( PositionAwareInputStream progressIn = new PositionAwareInputStream(
@ -129,13 +127,14 @@ public class ImportKeysListLoader
// PGPObject chunks after the first one, e.g. files with several consecutive ASCII // PGPObject chunks after the first one, e.g. files with several consecutive ASCII
// armor blocks // armor blocks
BufferedInputStream bufferedInput = new BufferedInputStream(progressIn); BufferedInputStream bufferedInput = new BufferedInputStream(progressIn);
bufferedInput.mark(1024);
try { try {
// read all available blocks... (asc files can contain many blocks with BEGIN END) // read all available blocks... (asc files can contain many blocks with BEGIN END)
while (bufferedInput.available() > 0) { while (bufferedInput.available() > 0) {
// TODO: deal with non-keyring objects? // TODO: deal with non-keyring objects?
List<UncachedKeyRing> rings = UncachedKeyRing.fromStream(bufferedInput); List<UncachedKeyRing> rings = UncachedKeyRing.fromStream(bufferedInput);
for(UncachedKeyRing key : rings) { for (UncachedKeyRing key : rings) {
ImportKeysListEntry item = new ImportKeysListEntry(getContext(), key); ImportKeysListEntry item = new ImportKeysListEntry(getContext(), key);
mData.add(item); mData.add(item);
mParcelableRings.put(item.hashCode(), new ParcelableKeyRing(key.getEncoded())); mParcelableRings.put(item.hashCode(), new ParcelableKeyRing(key.getEncoded()));
@ -144,14 +143,26 @@ public class ImportKeysListLoader
} }
} catch (Exception e) { } catch (Exception e) {
Log.e(Constants.TAG, "Exception on parsing key file!", 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<ArrayList<ImportKeysListEntry>>(mData, e); mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mData, e);
} }
if (isEmpty) { 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<ArrayList<ImportKeysListEntry>> mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>
(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() : "";
}
} }