From 494a5fa414fe5962bdee0d50e761da9dc0cc1cc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Sat, 15 Feb 2014 01:06:03 +0100 Subject: private request codes, pass params through methods and pending intents, getKeyIds method --- .../org/openintents/openpgp/IOpenPgpService.aidl | 11 +++ .../org/openintents/openpgp/util/OpenPgpApi.java | 83 ++++++++++++---------- .../openpgp/util/ParcelFileDescriptorUtil.java | 4 +- 3 files changed, 60 insertions(+), 38 deletions(-) (limited to 'OpenPGP-Keychain-API/libraries/keychain-api-library') diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpService.aidl b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpService.aidl index ced1df026..2d22f8f2d 100644 --- a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpService.aidl +++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/IOpenPgpService.aidl @@ -64,4 +64,15 @@ interface IOpenPgpService { */ Bundle decryptAndVerify(in Bundle params, in ParcelFileDescriptor input, in ParcelFileDescriptor output); + /** + * Retrieves key ids based on given user ids (=emails) + * + * params: + * String[] user_ids + * + * result: + * long[] key_ids + */ + Bundle getKeyIds(in Bundle params); + } \ No newline at end of file diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java index adb187c04..5f67ddf88 100644 --- a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java +++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java @@ -35,6 +35,7 @@ public class OpenPgpApi { private static final int OPERATION_ENCRYPT = 1; private static final int OPERATION_SIGN_ENCRYPT = 2; private static final int OPERATION_DECRYPT_VERIFY = 3; + private static final int OPERATION_GET_KEY_IDS = 4; public OpenPgpApi(IOpenPgpService service) { this.mService = service; @@ -88,6 +89,10 @@ public class OpenPgpApi { executeApiAsync(OPERATION_DECRYPT_VERIFY, params, is, os, callback); } + public Bundle getKeyIds(Bundle params) { + return executeApi(OPERATION_GET_KEY_IDS, params, null, null); + } + public interface IOpenPgpCallback { void onReturn(final Bundle result); } @@ -124,24 +129,6 @@ public class OpenPgpApi { private Bundle executeApi(int operationId, Bundle params, InputStream is, OutputStream os) { try { - // send the input and output pfds - ParcelFileDescriptor input = ParcelFileDescriptorUtil.pipeFrom(is, - new ParcelFileDescriptorUtil.IThreadListener() { - - @Override - public void onThreadFinished(Thread thread) { - Log.d(OpenPgpConstants.TAG, "Copy to service finished"); - } - }); - ParcelFileDescriptor output = ParcelFileDescriptorUtil.pipeTo(os, - new ParcelFileDescriptorUtil.IThreadListener() { - - @Override - public void onThreadFinished(Thread thread) { - Log.d(OpenPgpConstants.TAG, "Service finished writing!"); - } - }); - params.putInt(OpenPgpConstants.PARAMS_API_VERSION, OpenPgpConstants.API_VERSION); // default result is error @@ -150,25 +137,49 @@ public class OpenPgpApi { result.putParcelable(OpenPgpConstants.RESULT_ERRORS, new OpenPgpError(OpenPgpError.GENERIC_ERROR, "This should never happen!")); - // blocks until result is ready - switch (operationId) { - case OPERATION_SIGN: - result = mService.sign(params, input, output); - break; - case OPERATION_ENCRYPT: - result = mService.encrypt(params, input, output); - break; - case OPERATION_SIGN_ENCRYPT: - result = mService.signAndEncrypt(params, input, output); - break; - case OPERATION_DECRYPT_VERIFY: - result = mService.decryptAndVerify(params, input, output); - break; + if (operationId == OPERATION_GET_KEY_IDS) { + result = mService.getKeyIds(params); + return result; + } else { + // send the input and output pfds + ParcelFileDescriptor input = ParcelFileDescriptorUtil.pipeFrom(is, + new ParcelFileDescriptorUtil.IThreadListener() { + + @Override + public void onThreadFinished(Thread thread) { + Log.d(OpenPgpConstants.TAG, "Copy to service finished"); + } + }); + ParcelFileDescriptor output = ParcelFileDescriptorUtil.pipeTo(os, + new ParcelFileDescriptorUtil.IThreadListener() { + + @Override + public void onThreadFinished(Thread thread) { + Log.d(OpenPgpConstants.TAG, "Service finished writing!"); + } + }); + + + // blocks until result is ready + switch (operationId) { + case OPERATION_SIGN: + result = mService.sign(params, input, output); + break; + case OPERATION_ENCRYPT: + result = mService.encrypt(params, input, output); + break; + case OPERATION_SIGN_ENCRYPT: + result = mService.signAndEncrypt(params, input, output); + break; + case OPERATION_DECRYPT_VERIFY: + result = mService.decryptAndVerify(params, input, output); + break; + } + // close() is required to halt the TransferThread + output.close(); + + return result; } - // close() is required to halt the TransferThread - output.close(); - - return result; } catch (Exception e) { Log.e(OpenPgpConstants.TAG, "Exception", e); Bundle result = new Bundle(); diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/ParcelFileDescriptorUtil.java b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/ParcelFileDescriptorUtil.java index 20f8c36f3..75d4b8c18 100644 --- a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/ParcelFileDescriptorUtil.java +++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/ParcelFileDescriptorUtil.java @@ -87,12 +87,12 @@ public class ParcelFileDescriptorUtil { try { mIn.close(); } catch (IOException e) { - e.printStackTrace(); + Log.e(OpenPgpConstants.TAG, "TransferThread" + getId(), e); } try { mOut.close(); } catch (IOException e) { - e.printStackTrace(); + Log.e(OpenPgpConstants.TAG, "TransferThread" + getId(), e); } } if (mListener != null) { -- cgit v1.2.3