From 9a5707c41526f5fbcb45f72ec50c6f2efdd83056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Tue, 10 Sep 2013 23:19:34 +0200 Subject: rename api to openpgp api --- .../src/org/openintents/crypto/CryptoError.aidl | 20 -- .../src/org/openintents/crypto/CryptoError.java | 76 ------ .../crypto/CryptoServiceConnection.java | 91 ------- .../openintents/crypto/CryptoSignatureResult.aidl | 20 -- .../openintents/crypto/CryptoSignatureResult.java | 86 ------- .../org/openintents/crypto/ICryptoCallback.aidl | 32 --- .../src/org/openintents/crypto/ICryptoService.aidl | 80 ------ .../org/openintents/openpgp/IOpenPgpCallback.aidl | 31 +++ .../org/openintents/openpgp/IOpenPgpService.aidl | 80 ++++++ .../src/org/openintents/openpgp/OpenPgpError.aidl | 20 ++ .../src/org/openintents/openpgp/OpenPgpError.java | 79 ++++++ .../openpgp/OpenPgpServiceConnection.java | 91 +++++++ .../openpgp/OpenPgpSignatureResult.aidl | 20 ++ .../openpgp/OpenPgpSignatureResult.java | 86 +++++++ .../keychain/demo/BaseActivity.java | 2 +- .../keychain/demo/CryptoProviderDemoActivity.java | 279 --------------------- .../keychain/demo/OpenPGPProviderActivity.java | 279 +++++++++++++++++++++ 17 files changed, 687 insertions(+), 685 deletions(-) delete mode 100644 OpenPGP-Keychain-API-Demo/src/org/openintents/crypto/CryptoError.aidl delete mode 100644 OpenPGP-Keychain-API-Demo/src/org/openintents/crypto/CryptoError.java delete mode 100644 OpenPGP-Keychain-API-Demo/src/org/openintents/crypto/CryptoServiceConnection.java delete mode 100644 OpenPGP-Keychain-API-Demo/src/org/openintents/crypto/CryptoSignatureResult.aidl delete mode 100644 OpenPGP-Keychain-API-Demo/src/org/openintents/crypto/CryptoSignatureResult.java delete mode 100644 OpenPGP-Keychain-API-Demo/src/org/openintents/crypto/ICryptoCallback.aidl delete mode 100644 OpenPGP-Keychain-API-Demo/src/org/openintents/crypto/ICryptoService.aidl create mode 100644 OpenPGP-Keychain-API-Demo/src/org/openintents/openpgp/IOpenPgpCallback.aidl create mode 100644 OpenPGP-Keychain-API-Demo/src/org/openintents/openpgp/IOpenPgpService.aidl create mode 100644 OpenPGP-Keychain-API-Demo/src/org/openintents/openpgp/OpenPgpError.aidl create mode 100644 OpenPGP-Keychain-API-Demo/src/org/openintents/openpgp/OpenPgpError.java create mode 100644 OpenPGP-Keychain-API-Demo/src/org/openintents/openpgp/OpenPgpServiceConnection.java create mode 100644 OpenPGP-Keychain-API-Demo/src/org/openintents/openpgp/OpenPgpSignatureResult.aidl create mode 100644 OpenPGP-Keychain-API-Demo/src/org/openintents/openpgp/OpenPgpSignatureResult.java delete mode 100644 OpenPGP-Keychain-API-Demo/src/org/sufficientlysecure/keychain/demo/CryptoProviderDemoActivity.java create mode 100644 OpenPGP-Keychain-API-Demo/src/org/sufficientlysecure/keychain/demo/OpenPGPProviderActivity.java (limited to 'OpenPGP-Keychain-API-Demo/src') diff --git a/OpenPGP-Keychain-API-Demo/src/org/openintents/crypto/CryptoError.aidl b/OpenPGP-Keychain-API-Demo/src/org/openintents/crypto/CryptoError.aidl deleted file mode 100644 index 7b67c8995..000000000 --- a/OpenPGP-Keychain-API-Demo/src/org/openintents/crypto/CryptoError.aidl +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (C) 2013 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.crypto; - -// Declare CryptoError so AIDL can find it and knows that it implements the parcelable protocol. -parcelable CryptoError; \ No newline at end of file diff --git a/OpenPGP-Keychain-API-Demo/src/org/openintents/crypto/CryptoError.java b/OpenPGP-Keychain-API-Demo/src/org/openintents/crypto/CryptoError.java deleted file mode 100644 index 265fe2633..000000000 --- a/OpenPGP-Keychain-API-Demo/src/org/openintents/crypto/CryptoError.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2013 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.crypto; - -import android.os.Parcel; -import android.os.Parcelable; - -public class CryptoError implements Parcelable { - int errorId; - String message; - - public CryptoError() { - } - - public CryptoError(int errorId, String message) { - this.errorId = errorId; - this.message = message; - } - - public CryptoError(CryptoError b) { - this.errorId = b.errorId; - this.message = b.message; - } - - public int getErrorId() { - return errorId; - } - - public void setErrorId(int errorId) { - this.errorId = errorId; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public int describeContents() { - return 0; - } - - public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(errorId); - dest.writeString(message); - } - - public static final Creator CREATOR = new Creator() { - public CryptoError createFromParcel(final Parcel source) { - CryptoError error = new CryptoError(); - error.errorId = source.readInt(); - error.message = source.readString(); - return error; - } - - public CryptoError[] newArray(final int size) { - return new CryptoError[size]; - } - }; -} diff --git a/OpenPGP-Keychain-API-Demo/src/org/openintents/crypto/CryptoServiceConnection.java b/OpenPGP-Keychain-API-Demo/src/org/openintents/crypto/CryptoServiceConnection.java deleted file mode 100644 index d9e91f772..000000000 --- a/OpenPGP-Keychain-API-Demo/src/org/openintents/crypto/CryptoServiceConnection.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2013 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.crypto; - -import org.openintents.crypto.ICryptoService; - -import android.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.content.ServiceConnection; -import android.os.IBinder; -import android.util.Log; - -public class CryptoServiceConnection { - private Context mApplicationContext; - - private ICryptoService mService; - private boolean bound; - private String cryptoProviderPackageName; - - private static final String TAG = "CryptoConnection"; - - public CryptoServiceConnection(Context context, String cryptoProviderPackageName) { - mApplicationContext = context.getApplicationContext(); - this.cryptoProviderPackageName = cryptoProviderPackageName; - } - - public ICryptoService getService() { - return mService; - } - - private ServiceConnection mCryptoServiceConnection = new ServiceConnection() { - public void onServiceConnected(ComponentName name, IBinder service) { - mService = ICryptoService.Stub.asInterface(service); - Log.d(TAG, "connected to service"); - bound = true; - } - - public void onServiceDisconnected(ComponentName name) { - mService = null; - Log.d(TAG, "disconnected from service"); - bound = false; - } - }; - - /** - * If not already bound, bind! - * - * @return - */ - public boolean bindToService() { - if (mService == null && !bound) { // if not already connected - try { - Log.d(TAG, "not bound yet"); - - Intent serviceIntent = new Intent(); - serviceIntent.setAction("org.openintents.crypto.ICryptoService"); - serviceIntent.setPackage(cryptoProviderPackageName); - mApplicationContext.bindService(serviceIntent, mCryptoServiceConnection, - Context.BIND_AUTO_CREATE); - - return true; - } catch (Exception e) { - Log.d(TAG, "Exception", e); - return false; - } - } else { // already connected - Log.d(TAG, "already bound... "); - return true; - } - } - - public void unbindFromService() { - mApplicationContext.unbindService(mCryptoServiceConnection); - } - -} diff --git a/OpenPGP-Keychain-API-Demo/src/org/openintents/crypto/CryptoSignatureResult.aidl b/OpenPGP-Keychain-API-Demo/src/org/openintents/crypto/CryptoSignatureResult.aidl deleted file mode 100644 index 1d39bac70..000000000 --- a/OpenPGP-Keychain-API-Demo/src/org/openintents/crypto/CryptoSignatureResult.aidl +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (C) 2013 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.crypto; - -// Declare CryptoSignatureResult so AIDL can find it and knows that it implements the parcelable protocol. -parcelable CryptoSignatureResult; \ No newline at end of file diff --git a/OpenPGP-Keychain-API-Demo/src/org/openintents/crypto/CryptoSignatureResult.java b/OpenPGP-Keychain-API-Demo/src/org/openintents/crypto/CryptoSignatureResult.java deleted file mode 100644 index d3aaa52d9..000000000 --- a/OpenPGP-Keychain-API-Demo/src/org/openintents/crypto/CryptoSignatureResult.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2013 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.crypto; - -import android.os.Parcel; -import android.os.Parcelable; - -public class CryptoSignatureResult implements Parcelable { - String signatureUserId; - - boolean signature; - boolean signatureSuccess; - boolean signatureUnknown; - - public CryptoSignatureResult() { - - } - - public CryptoSignatureResult(String signatureUserId, boolean signature, - boolean signatureSuccess, boolean signatureUnknown) { - this.signatureUserId = signatureUserId; - - this.signature = signature; - this.signatureSuccess = signatureSuccess; - this.signatureUnknown = signatureUnknown; - } - - public CryptoSignatureResult(CryptoSignatureResult b) { - this.signatureUserId = b.signatureUserId; - - this.signature = b.signature; - this.signatureSuccess = b.signatureSuccess; - this.signatureUnknown = b.signatureUnknown; - } - - public int describeContents() { - return 0; - } - - public void writeToParcel(Parcel dest, int flags) { - dest.writeString(signatureUserId); - - dest.writeByte((byte) (signature ? 1 : 0)); - dest.writeByte((byte) (signatureSuccess ? 1 : 0)); - dest.writeByte((byte) (signatureUnknown ? 1 : 0)); - } - - public static final Creator CREATOR = new Creator() { - public CryptoSignatureResult createFromParcel(final Parcel source) { - CryptoSignatureResult vr = new CryptoSignatureResult(); - vr.signatureUserId = source.readString(); - vr.signature = source.readByte() == 1; - vr.signatureSuccess = source.readByte() == 1; - vr.signatureUnknown = source.readByte() == 1; - return vr; - } - - public CryptoSignatureResult[] newArray(final int size) { - return new CryptoSignatureResult[size]; - } - }; - - @Override - public String toString() { - String out = new String(); - out += "signature: " + signature; - out += "\nsignatureSuccess: " + signatureSuccess; - out += "\nsignatureUnknown: " + signatureUnknown; - return out; - } - -} diff --git a/OpenPGP-Keychain-API-Demo/src/org/openintents/crypto/ICryptoCallback.aidl b/OpenPGP-Keychain-API-Demo/src/org/openintents/crypto/ICryptoCallback.aidl deleted file mode 100644 index 1f910d4c6..000000000 --- a/OpenPGP-Keychain-API-Demo/src/org/openintents/crypto/ICryptoCallback.aidl +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2013 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.crypto; - -import org.openintents.crypto.CryptoSignatureResult; -import org.openintents.crypto.CryptoError; - -interface ICryptoCallback { - - /** - * CryptoSignatureResult is only returned if the Callback was used from decryptAndVerify - * - */ - oneway void onSuccess(in byte[] outputBytes, in CryptoSignatureResult signatureResult); - - - oneway void onError(in CryptoError error); -} \ No newline at end of file diff --git a/OpenPGP-Keychain-API-Demo/src/org/openintents/crypto/ICryptoService.aidl b/OpenPGP-Keychain-API-Demo/src/org/openintents/crypto/ICryptoService.aidl deleted file mode 100644 index 854ca0b05..000000000 --- a/OpenPGP-Keychain-API-Demo/src/org/openintents/crypto/ICryptoService.aidl +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2013 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.crypto; - -import org.openintents.crypto.ICryptoCallback; - -/** - * All methods are oneway, which means they are asynchronous and non-blocking. - * Results are returned to the callback, which has to be implemented on client side. - */ -interface ICryptoService { - - /** - * Encrypt - * - * @param inputBytes - * Byte array you want to encrypt - * @param encryptionUserIds - * User Ids (emails) of recipients - * @param asciiArmor - * Encode for ASCII (Radix-64, 33 percent overhead compared to binary) - * @param callback - * Callback where to return results - */ - oneway void encrypt(in byte[] inputBytes, in String[] encryptionUserIds, in boolean asciiArmor, in ICryptoCallback callback); - - /** - * Sign - * - * @param inputBytes - * Byte array you want to encrypt - * @param asciiArmor - * Encode for ASCII (Radix-64, 33 percent overhead compared to binary) - * @param callback - * Callback where to return results - */ - oneway void sign(in byte[] inputBytes, in boolean asciiArmor, in ICryptoCallback callback); - - /** - * Encrypt and sign - * - * @param inputBytes - * Byte array you want to encrypt - * @param encryptionUserIds - * User Ids (emails) of recipients - * @param signatureUserId - * User Ids (email) of sender - * @param asciiArmor - * Encode for ASCII (Radix-64, 33 percent overhead compared to binary) - * @param callback - * Callback where to return results - */ - oneway void encryptAndSign(in byte[] inputBytes, in String[] encryptionUserIds, in boolean asciiArmor, in ICryptoCallback callback); - - /** - * Decrypts and verifies given input bytes. If no signature is present this method - * will only decrypt. - * - * @param inputBytes - * Byte array you want to decrypt and verify - * @param callback - * Callback where to return results - */ - oneway void decryptAndVerify(in byte[] inputBytes, in ICryptoCallback callback); - -} \ No newline at end of file diff --git a/OpenPGP-Keychain-API-Demo/src/org/openintents/openpgp/IOpenPgpCallback.aidl b/OpenPGP-Keychain-API-Demo/src/org/openintents/openpgp/IOpenPgpCallback.aidl new file mode 100644 index 000000000..e0ac43d22 --- /dev/null +++ b/OpenPGP-Keychain-API-Demo/src/org/openintents/openpgp/IOpenPgpCallback.aidl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2013 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; +import org.openintents.openpgp.OpenPgpError; + +interface IOpenPgpCallback { + + /** + * CryptoSignatureResult is only returned if the Callback was used from decryptAndVerify + * + */ + oneway void onSuccess(in byte[] outputBytes, in OpenPgpSignatureResult signatureResult); + + oneway void onError(in OpenPgpError error); +} \ No newline at end of file diff --git a/OpenPGP-Keychain-API-Demo/src/org/openintents/openpgp/IOpenPgpService.aidl b/OpenPGP-Keychain-API-Demo/src/org/openintents/openpgp/IOpenPgpService.aidl new file mode 100644 index 000000000..1d54ac77f --- /dev/null +++ b/OpenPGP-Keychain-API-Demo/src/org/openintents/openpgp/IOpenPgpService.aidl @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2013 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.IOpenPgpCallback; + +/** + * All methods are oneway, which means they are asynchronous and non-blocking. + * Results are returned to the callback, which has to be implemented on client side. + */ +interface IOpenPgpService { + + /** + * Encrypt + * + * @param inputBytes + * Byte array you want to encrypt + * @param encryptionUserIds + * User Ids (emails) of recipients + * @param asciiArmor + * Encode for ASCII (Radix-64, 33 percent overhead compared to binary) + * @param callback + * Callback where to return results + */ + oneway void encrypt(in byte[] inputBytes, in String[] encryptionUserIds, in boolean asciiArmor, in IOpenPgpCallback callback); + + /** + * Sign + * + * @param inputBytes + * Byte array you want to encrypt + * @param asciiArmor + * Encode for ASCII (Radix-64, 33 percent overhead compared to binary) + * @param callback + * Callback where to return results + */ + oneway void sign(in byte[] inputBytes, in boolean asciiArmor, in IOpenPgpCallback callback); + + /** + * Encrypt and sign + * + * @param inputBytes + * Byte array you want to encrypt + * @param encryptionUserIds + * User Ids (emails) of recipients + * @param signatureUserId + * User Ids (email) of sender + * @param asciiArmor + * Encode for ASCII (Radix-64, 33 percent overhead compared to binary) + * @param callback + * Callback where to return results + */ + oneway void encryptAndSign(in byte[] inputBytes, in String[] encryptionUserIds, in boolean asciiArmor, in IOpenPgpCallback callback); + + /** + * Decrypts and verifies given input bytes. If no signature is present this method + * will only decrypt. + * + * @param inputBytes + * Byte array you want to decrypt and verify + * @param callback + * Callback where to return results + */ + oneway void decryptAndVerify(in byte[] inputBytes, in IOpenPgpCallback callback); + +} \ No newline at end of file diff --git a/OpenPGP-Keychain-API-Demo/src/org/openintents/openpgp/OpenPgpError.aidl b/OpenPGP-Keychain-API-Demo/src/org/openintents/openpgp/OpenPgpError.aidl new file mode 100644 index 000000000..7a6bed1e6 --- /dev/null +++ b/OpenPGP-Keychain-API-Demo/src/org/openintents/openpgp/OpenPgpError.aidl @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2013 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; + +// 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-Demo/src/org/openintents/openpgp/OpenPgpError.java b/OpenPGP-Keychain-API-Demo/src/org/openintents/openpgp/OpenPgpError.java new file mode 100644 index 000000000..66f168d89 --- /dev/null +++ b/OpenPGP-Keychain-API-Demo/src/org/openintents/openpgp/OpenPgpError.java @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2013 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 android.os.Parcel; +import android.os.Parcelable; + +public class OpenPgpError implements Parcelable { + public static final int ID_NO_OR_WRONG_PASSPHRASE = 1; + public static final int ID_NO_USER_IDS = 2; + + int errorId; + String message; + + public OpenPgpError() { + } + + public OpenPgpError(int errorId, String message) { + this.errorId = errorId; + this.message = message; + } + + public OpenPgpError(OpenPgpError b) { + this.errorId = b.errorId; + this.message = b.message; + } + + public int getErrorId() { + return errorId; + } + + public void setErrorId(int errorId) { + this.errorId = errorId; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public int describeContents() { + return 0; + } + + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(errorId); + dest.writeString(message); + } + + public static final Creator CREATOR = new Creator() { + public OpenPgpError createFromParcel(final Parcel source) { + OpenPgpError error = new OpenPgpError(); + error.errorId = source.readInt(); + error.message = source.readString(); + return error; + } + + public OpenPgpError[] newArray(final int size) { + return new OpenPgpError[size]; + } + }; +} diff --git a/OpenPGP-Keychain-API-Demo/src/org/openintents/openpgp/OpenPgpServiceConnection.java b/OpenPGP-Keychain-API-Demo/src/org/openintents/openpgp/OpenPgpServiceConnection.java new file mode 100644 index 000000000..9f4fec470 --- /dev/null +++ b/OpenPGP-Keychain-API-Demo/src/org/openintents/openpgp/OpenPgpServiceConnection.java @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2013 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.IOpenPgpService; + +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.ServiceConnection; +import android.os.IBinder; +import android.util.Log; + +public class OpenPgpServiceConnection { + private Context mApplicationContext; + + private IOpenPgpService mService; + private boolean bound; + private String cryptoProviderPackageName; + + private static final String TAG = "OpenPgpServiceConnection"; + + public OpenPgpServiceConnection(Context context, String cryptoProviderPackageName) { + mApplicationContext = context.getApplicationContext(); + this.cryptoProviderPackageName = cryptoProviderPackageName; + } + + public IOpenPgpService getService() { + return mService; + } + + private ServiceConnection mCryptoServiceConnection = new ServiceConnection() { + public void onServiceConnected(ComponentName name, IBinder service) { + mService = IOpenPgpService.Stub.asInterface(service); + Log.d(TAG, "connected to service"); + bound = true; + } + + public void onServiceDisconnected(ComponentName name) { + mService = null; + Log.d(TAG, "disconnected from service"); + bound = false; + } + }; + + /** + * If not already bound, bind! + * + * @return + */ + public boolean bindToService() { + if (mService == null && !bound) { // if not already connected + try { + Log.d(TAG, "not bound yet"); + + Intent serviceIntent = new Intent(); + serviceIntent.setAction(IOpenPgpService.class.getName()); + serviceIntent.setPackage(cryptoProviderPackageName); + mApplicationContext.bindService(serviceIntent, mCryptoServiceConnection, + Context.BIND_AUTO_CREATE); + + return true; + } catch (Exception e) { + Log.d(TAG, "Exception", e); + return false; + } + } else { // already connected + Log.d(TAG, "already bound... "); + return true; + } + } + + public void unbindFromService() { + mApplicationContext.unbindService(mCryptoServiceConnection); + } + +} diff --git a/OpenPGP-Keychain-API-Demo/src/org/openintents/openpgp/OpenPgpSignatureResult.aidl b/OpenPGP-Keychain-API-Demo/src/org/openintents/openpgp/OpenPgpSignatureResult.aidl new file mode 100644 index 000000000..e246792d0 --- /dev/null +++ b/OpenPGP-Keychain-API-Demo/src/org/openintents/openpgp/OpenPgpSignatureResult.aidl @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2013 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; + +// 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-Demo/src/org/openintents/openpgp/OpenPgpSignatureResult.java b/OpenPGP-Keychain-API-Demo/src/org/openintents/openpgp/OpenPgpSignatureResult.java new file mode 100644 index 000000000..d8642664f --- /dev/null +++ b/OpenPGP-Keychain-API-Demo/src/org/openintents/openpgp/OpenPgpSignatureResult.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2013 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 android.os.Parcel; +import android.os.Parcelable; + +public class OpenPgpSignatureResult implements Parcelable { + String signatureUserId; + + boolean signature; + boolean signatureSuccess; + boolean signatureUnknown; + + public OpenPgpSignatureResult() { + + } + + public OpenPgpSignatureResult(String signatureUserId, boolean signature, + boolean signatureSuccess, boolean signatureUnknown) { + this.signatureUserId = signatureUserId; + + this.signature = signature; + this.signatureSuccess = signatureSuccess; + this.signatureUnknown = signatureUnknown; + } + + public OpenPgpSignatureResult(OpenPgpSignatureResult b) { + this.signatureUserId = b.signatureUserId; + + this.signature = b.signature; + this.signatureSuccess = b.signatureSuccess; + this.signatureUnknown = b.signatureUnknown; + } + + public int describeContents() { + return 0; + } + + public void writeToParcel(Parcel dest, int flags) { + dest.writeString(signatureUserId); + + dest.writeByte((byte) (signature ? 1 : 0)); + dest.writeByte((byte) (signatureSuccess ? 1 : 0)); + dest.writeByte((byte) (signatureUnknown ? 1 : 0)); + } + + public static final Creator CREATOR = new Creator() { + public OpenPgpSignatureResult createFromParcel(final Parcel source) { + OpenPgpSignatureResult vr = new OpenPgpSignatureResult(); + vr.signatureUserId = source.readString(); + vr.signature = source.readByte() == 1; + vr.signatureSuccess = source.readByte() == 1; + vr.signatureUnknown = source.readByte() == 1; + return vr; + } + + public OpenPgpSignatureResult[] newArray(final int size) { + return new OpenPgpSignatureResult[size]; + } + }; + + @Override + public String toString() { + String out = new String(); + out += "signature: " + signature; + out += "\nsignatureSuccess: " + signatureSuccess; + out += "\nsignatureUnknown: " + signatureUnknown; + return out; + } + +} diff --git a/OpenPGP-Keychain-API-Demo/src/org/sufficientlysecure/keychain/demo/BaseActivity.java b/OpenPGP-Keychain-API-Demo/src/org/sufficientlysecure/keychain/demo/BaseActivity.java index 06483727c..84e65c6d8 100644 --- a/OpenPGP-Keychain-API-Demo/src/org/sufficientlysecure/keychain/demo/BaseActivity.java +++ b/OpenPGP-Keychain-API-Demo/src/org/sufficientlysecure/keychain/demo/BaseActivity.java @@ -67,7 +67,7 @@ public class BaseActivity extends PreferenceActivity { mCryptoProvider.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { - startActivity(new Intent(mActivity, CryptoProviderDemoActivity.class)); + startActivity(new Intent(mActivity, OpenPGPProviderActivity.class)); return false; } diff --git a/OpenPGP-Keychain-API-Demo/src/org/sufficientlysecure/keychain/demo/CryptoProviderDemoActivity.java b/OpenPGP-Keychain-API-Demo/src/org/sufficientlysecure/keychain/demo/CryptoProviderDemoActivity.java deleted file mode 100644 index 7bfd72540..000000000 --- a/OpenPGP-Keychain-API-Demo/src/org/sufficientlysecure/keychain/demo/CryptoProviderDemoActivity.java +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Copyright (C) 2013 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.sufficientlysecure.keychain.demo; - -import java.util.ArrayList; -import java.util.List; - -import org.openintents.crypto.CryptoError; -import org.openintents.crypto.CryptoServiceConnection; -import org.openintents.crypto.CryptoSignatureResult; -import org.openintents.crypto.ICryptoCallback; -import org.openintents.crypto.ICryptoService; - -import android.app.Activity; -import android.app.AlertDialog; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.pm.ResolveInfo; -import android.graphics.drawable.Drawable; -import android.os.Bundle; -import android.os.RemoteException; -import android.util.Log; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.EditText; -import android.widget.ListAdapter; -import android.widget.TextView; -import android.widget.Toast; - -public class CryptoProviderDemoActivity extends Activity { - Activity mActivity; - - EditText mMessage; - EditText mCiphertext; - EditText mEncryptUserIds; - - private CryptoServiceConnection mCryptoServiceConnection; - - @Override - public void onCreate(Bundle icicle) { - super.onCreate(icicle); - setContentView(R.layout.crypto_provider_demo); - - mActivity = this; - - mMessage = (EditText) findViewById(R.id.crypto_provider_demo_message); - mCiphertext = (EditText) findViewById(R.id.crypto_provider_demo_ciphertext); - mEncryptUserIds = (EditText) findViewById(R.id.crypto_provider_demo_encrypt_user_id); - - selectCryptoProvider(); - } - - /** - * Callback from remote crypto service - */ - final ICryptoCallback.Stub encryptCallback = new ICryptoCallback.Stub() { - - @Override - public void onSuccess(final byte[] outputBytes, CryptoSignatureResult signatureResult) - throws RemoteException { - Log.d(Constants.TAG, "encryptCallback"); - - runOnUiThread(new Runnable() { - - @Override - public void run() { - mCiphertext.setText(new String(outputBytes)); - } - }); - } - - @Override - public void onError(CryptoError error) throws RemoteException { - handleError(error); - } - - }; - - final ICryptoCallback.Stub decryptAndVerifyCallback = new ICryptoCallback.Stub() { - - @Override - public void onSuccess(final byte[] outputBytes, final CryptoSignatureResult signatureResult) - throws RemoteException { - Log.d(Constants.TAG, "decryptAndVerifyCallback"); - - runOnUiThread(new Runnable() { - - @Override - public void run() { - mMessage.setText(new String(outputBytes)); - if (signatureResult != null) { - Toast.makeText(CryptoProviderDemoActivity.this, - "signature result:\n" + signatureResult.toString(), - Toast.LENGTH_LONG).show(); - } - } - }); - - } - - @Override - public void onError(CryptoError error) throws RemoteException { - handleError(error); - } - - }; - - private void handleError(final CryptoError error) { - mActivity.runOnUiThread(new Runnable() { - - @Override - public void run() { - Toast.makeText(mActivity, - "onError id:" + error.getErrorId() + "\n\n" + error.getMessage(), - Toast.LENGTH_LONG).show(); - Log.e(Constants.TAG, "onError getErrorId:" + error.getErrorId()); - Log.e(Constants.TAG, "onError getMessage:" + error.getMessage()); - } - }); - } - - public void encryptOnClick(View view) { - byte[] inputBytes = mMessage.getText().toString().getBytes(); - - try { - mCryptoServiceConnection.getService().encrypt(inputBytes, - mEncryptUserIds.getText().toString().split(","), true, encryptCallback); - } catch (RemoteException e) { - Log.e(Constants.TAG, "CryptoProviderDemo", e); - } - } - - public void signOnClick(View view) { - byte[] inputBytes = mMessage.getText().toString().getBytes(); - - try { - mCryptoServiceConnection.getService().sign(inputBytes, true, encryptCallback); - } catch (RemoteException e) { - Log.e(Constants.TAG, "CryptoProviderDemo", e); - } - } - - public void encryptAndSignOnClick(View view) { - byte[] inputBytes = mMessage.getText().toString().getBytes(); - - try { - mCryptoServiceConnection.getService().encryptAndSign(inputBytes, - mEncryptUserIds.getText().toString().split(","), true, encryptCallback); - } catch (RemoteException e) { - Log.e(Constants.TAG, "CryptoProviderDemo", e); - } - } - - public void decryptAndVerifyOnClick(View view) { - byte[] inputBytes = mCiphertext.getText().toString().getBytes(); - - try { - mCryptoServiceConnection.getService().decryptAndVerify(inputBytes, - decryptAndVerifyCallback); - } catch (RemoteException e) { - Log.e(Constants.TAG, "CryptoProviderDemo", e); - } - } - - @Override - public void onDestroy() { - super.onDestroy(); - - if (mCryptoServiceConnection != null) { - mCryptoServiceConnection.unbindFromService(); - } - } - - private static class CryptoProviderElement { - private String packageName; - private String simpleName; - private Drawable icon; - - public CryptoProviderElement(String packageName, String simpleName, Drawable icon) { - this.packageName = packageName; - this.simpleName = simpleName; - this.icon = icon; - } - - @Override - public String toString() { - return simpleName; - } - } - - private void selectCryptoProvider() { - Intent intent = new Intent(ICryptoService.class.getName()); - - final ArrayList providerList = new ArrayList(); - - List resInfo = getPackageManager().queryIntentServices(intent, 0); - if (!resInfo.isEmpty()) { - for (ResolveInfo resolveInfo : resInfo) { - if (resolveInfo.serviceInfo == null) - continue; - - String packageName = resolveInfo.serviceInfo.packageName; - String simpleName = String.valueOf(resolveInfo.serviceInfo - .loadLabel(getPackageManager())); - Drawable icon = resolveInfo.serviceInfo.loadIcon(getPackageManager()); - providerList.add(new CryptoProviderElement(packageName, simpleName, icon)); - } - - AlertDialog.Builder alert = new AlertDialog.Builder(this); - alert.setTitle("Select Crypto Provider!"); - alert.setCancelable(false); - - if (!providerList.isEmpty()) { - - // Init ArrayAdapter with Crypto Providers - ListAdapter adapter = new ArrayAdapter(this, - android.R.layout.select_dialog_item, android.R.id.text1, providerList) { - public View getView(int position, View convertView, ViewGroup parent) { - // User super class to create the View - View v = super.getView(position, convertView, parent); - TextView tv = (TextView) v.findViewById(android.R.id.text1); - - // Put the image on the TextView - tv.setCompoundDrawablesWithIntrinsicBounds(providerList.get(position).icon, - null, null, null); - - // Add margin between image and text (support various screen densities) - int dp5 = (int) (5 * getResources().getDisplayMetrics().density + 0.5f); - tv.setCompoundDrawablePadding(dp5); - - return v; - } - }; - - alert.setSingleChoiceItems(adapter, -1, new DialogInterface.OnClickListener() { - - public void onClick(DialogInterface dialog, int position) { - String packageName = providerList.get(position).packageName; - - // bind to service - mCryptoServiceConnection = new CryptoServiceConnection( - CryptoProviderDemoActivity.this, packageName); - mCryptoServiceConnection.bindToService(); - - dialog.dismiss(); - } - }); - } else { - alert.setMessage("No Crypto Provider installed!"); - } - - alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { - - public void onClick(DialogInterface dialog, int id) { - dialog.cancel(); - finish(); - } - }); - - AlertDialog ad = alert.create(); - ad.show(); - } - } -} diff --git a/OpenPGP-Keychain-API-Demo/src/org/sufficientlysecure/keychain/demo/OpenPGPProviderActivity.java b/OpenPGP-Keychain-API-Demo/src/org/sufficientlysecure/keychain/demo/OpenPGPProviderActivity.java new file mode 100644 index 000000000..b0181eab2 --- /dev/null +++ b/OpenPGP-Keychain-API-Demo/src/org/sufficientlysecure/keychain/demo/OpenPGPProviderActivity.java @@ -0,0 +1,279 @@ +/* + * Copyright (C) 2013 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.sufficientlysecure.keychain.demo; + +import java.util.ArrayList; +import java.util.List; + +import org.openintents.openpgp.OpenPgpError; +import org.openintents.openpgp.OpenPgpServiceConnection; +import org.openintents.openpgp.OpenPgpSignatureResult; +import org.openintents.openpgp.IOpenPgpCallback; +import org.openintents.openpgp.IOpenPgpService; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.pm.ResolveInfo; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.os.RemoteException; +import android.util.Log; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.EditText; +import android.widget.ListAdapter; +import android.widget.TextView; +import android.widget.Toast; + +public class OpenPGPProviderActivity extends Activity { + Activity mActivity; + + EditText mMessage; + EditText mCiphertext; + EditText mEncryptUserIds; + + private OpenPgpServiceConnection mCryptoServiceConnection; + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + setContentView(R.layout.crypto_provider_demo); + + mActivity = this; + + mMessage = (EditText) findViewById(R.id.crypto_provider_demo_message); + mCiphertext = (EditText) findViewById(R.id.crypto_provider_demo_ciphertext); + mEncryptUserIds = (EditText) findViewById(R.id.crypto_provider_demo_encrypt_user_id); + + selectCryptoProvider(); + } + + /** + * Callback from remote crypto service + */ + final IOpenPgpCallback.Stub encryptCallback = new IOpenPgpCallback.Stub() { + + @Override + public void onSuccess(final byte[] outputBytes, OpenPgpSignatureResult signatureResult) + throws RemoteException { + Log.d(Constants.TAG, "encryptCallback"); + + runOnUiThread(new Runnable() { + + @Override + public void run() { + mCiphertext.setText(new String(outputBytes)); + } + }); + } + + @Override + public void onError(OpenPgpError error) throws RemoteException { + handleError(error); + } + + }; + + final IOpenPgpCallback.Stub decryptAndVerifyCallback = new IOpenPgpCallback.Stub() { + + @Override + public void onSuccess(final byte[] outputBytes, final OpenPgpSignatureResult signatureResult) + throws RemoteException { + Log.d(Constants.TAG, "decryptAndVerifyCallback"); + + runOnUiThread(new Runnable() { + + @Override + public void run() { + mMessage.setText(new String(outputBytes)); + if (signatureResult != null) { + Toast.makeText(OpenPGPProviderActivity.this, + "signature result:\n" + signatureResult.toString(), + Toast.LENGTH_LONG).show(); + } + } + }); + + } + + @Override + public void onError(OpenPgpError error) throws RemoteException { + handleError(error); + } + + }; + + private void handleError(final OpenPgpError error) { + mActivity.runOnUiThread(new Runnable() { + + @Override + public void run() { + Toast.makeText(mActivity, + "onError id:" + error.getErrorId() + "\n\n" + error.getMessage(), + Toast.LENGTH_LONG).show(); + Log.e(Constants.TAG, "onError getErrorId:" + error.getErrorId()); + Log.e(Constants.TAG, "onError getMessage:" + error.getMessage()); + } + }); + } + + public void encryptOnClick(View view) { + byte[] inputBytes = mMessage.getText().toString().getBytes(); + + try { + mCryptoServiceConnection.getService().encrypt(inputBytes, + mEncryptUserIds.getText().toString().split(","), true, encryptCallback); + } catch (RemoteException e) { + Log.e(Constants.TAG, "CryptoProviderDemo", e); + } + } + + public void signOnClick(View view) { + byte[] inputBytes = mMessage.getText().toString().getBytes(); + + try { + mCryptoServiceConnection.getService().sign(inputBytes, true, encryptCallback); + } catch (RemoteException e) { + Log.e(Constants.TAG, "CryptoProviderDemo", e); + } + } + + public void encryptAndSignOnClick(View view) { + byte[] inputBytes = mMessage.getText().toString().getBytes(); + + try { + mCryptoServiceConnection.getService().encryptAndSign(inputBytes, + mEncryptUserIds.getText().toString().split(","), true, encryptCallback); + } catch (RemoteException e) { + Log.e(Constants.TAG, "CryptoProviderDemo", e); + } + } + + public void decryptAndVerifyOnClick(View view) { + byte[] inputBytes = mCiphertext.getText().toString().getBytes(); + + try { + mCryptoServiceConnection.getService().decryptAndVerify(inputBytes, + decryptAndVerifyCallback); + } catch (RemoteException e) { + Log.e(Constants.TAG, "CryptoProviderDemo", e); + } + } + + @Override + public void onDestroy() { + super.onDestroy(); + + if (mCryptoServiceConnection != null) { + mCryptoServiceConnection.unbindFromService(); + } + } + + private static class OpenPGPProviderElement { + private String packageName; + private String simpleName; + private Drawable icon; + + public OpenPGPProviderElement(String packageName, String simpleName, Drawable icon) { + this.packageName = packageName; + this.simpleName = simpleName; + this.icon = icon; + } + + @Override + public String toString() { + return simpleName; + } + } + + private void selectCryptoProvider() { + Intent intent = new Intent(IOpenPgpService.class.getName()); + + final ArrayList providerList = new ArrayList(); + + List resInfo = getPackageManager().queryIntentServices(intent, 0); + if (!resInfo.isEmpty()) { + for (ResolveInfo resolveInfo : resInfo) { + if (resolveInfo.serviceInfo == null) + continue; + + String packageName = resolveInfo.serviceInfo.packageName; + String simpleName = String.valueOf(resolveInfo.serviceInfo + .loadLabel(getPackageManager())); + Drawable icon = resolveInfo.serviceInfo.loadIcon(getPackageManager()); + providerList.add(new OpenPGPProviderElement(packageName, simpleName, icon)); + } + + AlertDialog.Builder alert = new AlertDialog.Builder(this); + alert.setTitle("Select OpenPGP Provider!"); + alert.setCancelable(false); + + if (!providerList.isEmpty()) { + + // Init ArrayAdapter with Crypto Providers + ListAdapter adapter = new ArrayAdapter(this, + android.R.layout.select_dialog_item, android.R.id.text1, providerList) { + public View getView(int position, View convertView, ViewGroup parent) { + // User super class to create the View + View v = super.getView(position, convertView, parent); + TextView tv = (TextView) v.findViewById(android.R.id.text1); + + // Put the image on the TextView + tv.setCompoundDrawablesWithIntrinsicBounds(providerList.get(position).icon, + null, null, null); + + // Add margin between image and text (support various screen densities) + int dp5 = (int) (5 * getResources().getDisplayMetrics().density + 0.5f); + tv.setCompoundDrawablePadding(dp5); + + return v; + } + }; + + alert.setSingleChoiceItems(adapter, -1, new DialogInterface.OnClickListener() { + + public void onClick(DialogInterface dialog, int position) { + String packageName = providerList.get(position).packageName; + + // bind to service + mCryptoServiceConnection = new OpenPgpServiceConnection( + OpenPGPProviderActivity.this, packageName); + mCryptoServiceConnection.bindToService(); + + dialog.dismiss(); + } + }); + } else { + alert.setMessage("No OpenPGP Provider installed!"); + } + + alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { + + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + finish(); + } + }); + + AlertDialog ad = alert.create(); + ad.show(); + } + } +} -- cgit v1.2.3