From 3d59796337e99c0153cf173eba617d156f158d3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Sat, 15 Feb 2014 15:46:30 +0100 Subject: [PATCH] Fix problem with unparceling by setting class loader in api lib, remove unneeded aidl classes --- .../demo/OpenPgpProviderActivity.java | 11 +++++----- .../org/openintents/openpgp/OpenPgpError.aidl | 22 ------------------- .../openpgp/OpenPgpSignatureResult.aidl | 22 ------------------- .../openintents/openpgp/util/OpenPgpApi.java | 12 ++++++++-- .../org/openintents/openpgp/OpenPgpError.aidl | 22 ------------------- .../openpgp/OpenPgpSignatureResult.aidl | 22 ------------------- .../openintents/openpgp/util/OpenPgpApi.java | 12 ++++++++-- 7 files changed, 25 insertions(+), 98 deletions(-) delete mode 100644 OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpError.aidl delete mode 100644 OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpSignatureResult.aidl delete mode 100644 libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpError.aidl delete mode 100644 libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpSignatureResult.aidl diff --git a/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java b/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java index dee977657..7e71ca45f 100644 --- a/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java +++ b/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 Dominik Schürmann + * Copyright (C) 2013-2014 Dominik Schürmann * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,7 +44,6 @@ import org.openintents.openpgp.util.OpenPgpServiceConnection; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; -import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; @@ -196,7 +195,7 @@ public class OpenPgpProviderActivity extends Activity { InputStream is = getInputstream(false); final ByteArrayOutputStream os = new ByteArrayOutputStream(); - OpenPgpApi api = new OpenPgpApi(mCryptoServiceConnection.getService()); + OpenPgpApi api = new OpenPgpApi(this, mCryptoServiceConnection.getService()); api.sign(params, is, os, new MyCallback(true, os, REQUEST_CODE_SIGN)); } @@ -207,7 +206,7 @@ public class OpenPgpProviderActivity extends Activity { InputStream is = getInputstream(false); final ByteArrayOutputStream os = new ByteArrayOutputStream(); - OpenPgpApi api = new OpenPgpApi(mCryptoServiceConnection.getService()); + OpenPgpApi api = new OpenPgpApi(this, mCryptoServiceConnection.getService()); api.encrypt(params, is, os, new MyCallback(true, os, REQUEST_CODE_ENCRYPT)); } @@ -218,7 +217,7 @@ public class OpenPgpProviderActivity extends Activity { InputStream is = getInputstream(false); final ByteArrayOutputStream os = new ByteArrayOutputStream(); - OpenPgpApi api = new OpenPgpApi(mCryptoServiceConnection.getService()); + OpenPgpApi api = new OpenPgpApi(this, mCryptoServiceConnection.getService()); api.signAndEncrypt(params, is, os, new MyCallback(true, os, REQUEST_CODE_SIGN_AND_ENCRYPT)); } @@ -228,7 +227,7 @@ public class OpenPgpProviderActivity extends Activity { InputStream is = getInputstream(true); final ByteArrayOutputStream os = new ByteArrayOutputStream(); - OpenPgpApi api = new OpenPgpApi(mCryptoServiceConnection.getService()); + OpenPgpApi api = new OpenPgpApi(this, mCryptoServiceConnection.getService()); api.decryptAndVerify(params, is, os, new MyCallback(true, os, REQUEST_CODE_DECRYPT_AND_VERIFY)); } diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpError.aidl b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpError.aidl deleted file mode 100644 index 0fbea0a8c..000000000 --- a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpError.aidl +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2014 Dominik Schürmann - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openintents.openpgp; - -import org.openintents.openpgp.OpenPgpError; - -// Declare OpenPgpError so AIDL can find it and knows that it implements the parcelable protocol. -parcelable OpenPgpError; \ No newline at end of file diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpSignatureResult.aidl b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpSignatureResult.aidl deleted file mode 100644 index dfc7e0992..000000000 --- a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpSignatureResult.aidl +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2014 Dominik Schürmann - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openintents.openpgp; - -import org.openintents.openpgp.OpenPgpSignatureResult; - -// Declare OpenPgpSignatureResult so AIDL can find it and knows that it implements the parcelable protocol. -parcelable OpenPgpSignatureResult; \ 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 5c38d3304..f121c345d 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 @@ -16,6 +16,7 @@ package org.openintents.openpgp.util; +import android.content.Context; import android.os.AsyncTask; import android.os.Bundle; import android.os.ParcelFileDescriptor; @@ -30,6 +31,7 @@ import java.io.OutputStream; public class OpenPgpApi { IOpenPgpService mService; + Context mContext; private static final int OPERATION_SIGN = 0; private static final int OPERATION_ENCRYPT = 1; @@ -37,7 +39,8 @@ public class OpenPgpApi { private static final int OPERATION_DECRYPT_VERIFY = 3; private static final int OPERATION_GET_KEY_IDS = 4; - public OpenPgpApi(IOpenPgpService service) { + public OpenPgpApi(Context context, IOpenPgpService service) { + this.mContext = context; this.mService = service; } @@ -131,7 +134,7 @@ public class OpenPgpApi { try { params.putInt(OpenPgpConstants.PARAMS_API_VERSION, OpenPgpConstants.API_VERSION); - Bundle result = new Bundle(); + Bundle result = null; if (operationId == OPERATION_GET_KEY_IDS) { result = mService.getKeyIds(params); @@ -174,6 +177,11 @@ public class OpenPgpApi { // close() is required to halt the TransferThread output.close(); + // set class loader to current context to allow unparcelling + // of OpenPgpError and OpenPgpSignatureResult + // http://stackoverflow.com/a/3806769 + result.setClassLoader(mContext.getClassLoader()); + return result; } } catch (Exception e) { diff --git a/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpError.aidl b/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpError.aidl deleted file mode 100644 index 0fbea0a8c..000000000 --- a/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpError.aidl +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2014 Dominik Schürmann - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openintents.openpgp; - -import org.openintents.openpgp.OpenPgpError; - -// Declare OpenPgpError so AIDL can find it and knows that it implements the parcelable protocol. -parcelable OpenPgpError; \ No newline at end of file diff --git a/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpSignatureResult.aidl b/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpSignatureResult.aidl deleted file mode 100644 index dfc7e0992..000000000 --- a/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpSignatureResult.aidl +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2014 Dominik Schürmann - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openintents.openpgp; - -import org.openintents.openpgp.OpenPgpSignatureResult; - -// Declare OpenPgpSignatureResult so AIDL can find it and knows that it implements the parcelable protocol. -parcelable OpenPgpSignatureResult; \ No newline at end of file diff --git a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java index 5c38d3304..f121c345d 100644 --- a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java +++ b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java @@ -16,6 +16,7 @@ package org.openintents.openpgp.util; +import android.content.Context; import android.os.AsyncTask; import android.os.Bundle; import android.os.ParcelFileDescriptor; @@ -30,6 +31,7 @@ import java.io.OutputStream; public class OpenPgpApi { IOpenPgpService mService; + Context mContext; private static final int OPERATION_SIGN = 0; private static final int OPERATION_ENCRYPT = 1; @@ -37,7 +39,8 @@ public class OpenPgpApi { private static final int OPERATION_DECRYPT_VERIFY = 3; private static final int OPERATION_GET_KEY_IDS = 4; - public OpenPgpApi(IOpenPgpService service) { + public OpenPgpApi(Context context, IOpenPgpService service) { + this.mContext = context; this.mService = service; } @@ -131,7 +134,7 @@ public class OpenPgpApi { try { params.putInt(OpenPgpConstants.PARAMS_API_VERSION, OpenPgpConstants.API_VERSION); - Bundle result = new Bundle(); + Bundle result = null; if (operationId == OPERATION_GET_KEY_IDS) { result = mService.getKeyIds(params); @@ -174,6 +177,11 @@ public class OpenPgpApi { // close() is required to halt the TransferThread output.close(); + // set class loader to current context to allow unparcelling + // of OpenPgpError and OpenPgpSignatureResult + // http://stackoverflow.com/a/3806769 + result.setClassLoader(mContext.getClassLoader()); + return result; } } catch (Exception e) {