Add support for multiple input/output URIs to KeychainIntentService

This commit is contained in:
mar-v-in 2014-07-03 00:34:41 +02:00
parent 93eae114ea
commit 51a4b0466b

View File

@ -109,6 +109,9 @@ public class KeychainIntentService extends IntentService
public static final int IO_BYTES = 1; public static final int IO_BYTES = 1;
public static final int IO_FILE = 2; // This was misleadingly TARGET_URI before! public static final int IO_FILE = 2; // This was misleadingly TARGET_URI before!
public static final int IO_URI = 3; public static final int IO_URI = 3;
public static final int IO_URIS = 4;
public static final String SELECTED_URI = "selected_uri";
// encrypt // encrypt
public static final String ENCRYPT_SIGNATURE_KEY_ID = "secret_key_id"; public static final String ENCRYPT_SIGNATURE_KEY_ID = "secret_key_id";
@ -118,8 +121,10 @@ public class KeychainIntentService extends IntentService
public static final String ENCRYPT_MESSAGE_BYTES = "message_bytes"; public static final String ENCRYPT_MESSAGE_BYTES = "message_bytes";
public static final String ENCRYPT_INPUT_FILE = "input_file"; public static final String ENCRYPT_INPUT_FILE = "input_file";
public static final String ENCRYPT_INPUT_URI = "input_uri"; public static final String ENCRYPT_INPUT_URI = "input_uri";
public static final String ENCRYPT_INPUT_URIS = "input_uris";
public static final String ENCRYPT_OUTPUT_FILE = "output_file"; public static final String ENCRYPT_OUTPUT_FILE = "output_file";
public static final String ENCRYPT_OUTPUT_URI = "output_uri"; public static final String ENCRYPT_OUTPUT_URI = "output_uri";
public static final String ENCRYPT_OUTPUT_URIS = "output_uris";
public static final String ENCRYPT_SYMMETRIC_PASSPHRASE = "passphrase"; public static final String ENCRYPT_SYMMETRIC_PASSPHRASE = "passphrase";
// decrypt/verify // decrypt/verify
@ -220,6 +225,7 @@ public class KeychainIntentService extends IntentService
try { try {
/* Input */ /* Input */
int source = data.get(SOURCE) != null ? data.getInt(SOURCE) : data.getInt(TARGET); int source = data.get(SOURCE) != null ? data.getInt(SOURCE) : data.getInt(TARGET);
Bundle resultData = new Bundle();
long signatureKeyId = data.getLong(ENCRYPT_SIGNATURE_KEY_ID); long signatureKeyId = data.getLong(ENCRYPT_SIGNATURE_KEY_ID);
String symmetricPassphrase = data.getString(ENCRYPT_SYMMETRIC_PASSPHRASE); String symmetricPassphrase = data.getString(ENCRYPT_SYMMETRIC_PASSPHRASE);
@ -227,6 +233,9 @@ public class KeychainIntentService extends IntentService
boolean useAsciiArmor = data.getBoolean(ENCRYPT_USE_ASCII_ARMOR); boolean useAsciiArmor = data.getBoolean(ENCRYPT_USE_ASCII_ARMOR);
long encryptionKeyIds[] = data.getLongArray(ENCRYPT_ENCRYPTION_KEYS_IDS); long encryptionKeyIds[] = data.getLongArray(ENCRYPT_ENCRYPTION_KEYS_IDS);
int compressionId = data.getInt(ENCRYPT_COMPRESSION_ID); int compressionId = data.getInt(ENCRYPT_COMPRESSION_ID);
int urisCount = data.containsKey(ENCRYPT_INPUT_URIS) ? data.getParcelableArrayList(ENCRYPT_INPUT_URIS).size() : 1;
for (int i = 0; i < urisCount; i++) {
data.putInt(SELECTED_URI, i);
InputData inputData = createEncryptInputData(data); InputData inputData = createEncryptInputData(data);
OutputStream outStream = createCryptOutputStream(data); OutputStream outStream = createCryptOutputStream(data);
@ -263,9 +272,10 @@ public class KeychainIntentService extends IntentService
/* Output */ /* Output */
Bundle resultData = new Bundle();
finalizeEncryptOutputStream(data, resultData, outStream); finalizeEncryptOutputStream(data, resultData, outStream);
}
OtherHelper.logDebugBundle(resultData, "resultData"); OtherHelper.logDebugBundle(resultData, "resultData");
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, resultData); sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, resultData);
@ -688,8 +698,13 @@ public class KeychainIntentService extends IntentService
Uri providerUri = data.getParcelable(ENCRYPT_INPUT_URI); Uri providerUri = data.getParcelable(ENCRYPT_INPUT_URI);
// InputStream // InputStream
InputStream in = getContentResolver().openInputStream(providerUri); return new InputData(getContentResolver().openInputStream(providerUri), 0);
return new InputData(in, 0);
case IO_URIS:
providerUri = data.<Uri>getParcelableArrayList(ENCRYPT_INPUT_URIS).get(data.getInt(SELECTED_URI));
// InputStream
return new InputData(getContentResolver().openInputStream(providerUri), 0);
default: default:
throw new PgpGeneralException("No target choosen!"); throw new PgpGeneralException("No target choosen!");
@ -719,6 +734,11 @@ public class KeychainIntentService extends IntentService
return getContentResolver().openOutputStream(providerUri); return getContentResolver().openOutputStream(providerUri);
case IO_URIS:
providerUri = data.<Uri>getParcelableArrayList(ENCRYPT_OUTPUT_URIS).get(data.getInt(SELECTED_URI));
return getContentResolver().openOutputStream(providerUri);
default: default:
throw new PgpGeneralException("No target choosen!"); throw new PgpGeneralException("No target choosen!");
} }
@ -744,6 +764,7 @@ public class KeychainIntentService extends IntentService
break; break;
case IO_URI: case IO_URI:
case IO_URIS:
// nothing, output was written, just send okay and verification bundle // nothing, output was written, just send okay and verification bundle
break; break;