From 0657f9289a220974d24de379295eeb976ebee7f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Thu, 3 Apr 2014 16:27:13 +0200 Subject: simplify OpenPgpServiceConnection --- .../src/org/openintents/openpgp/util/OpenPgpServiceConnection.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'OpenPGP-Keychain-API/libraries/openpgp-api-library') diff --git a/OpenPGP-Keychain-API/libraries/openpgp-api-library/src/org/openintents/openpgp/util/OpenPgpServiceConnection.java b/OpenPGP-Keychain-API/libraries/openpgp-api-library/src/org/openintents/openpgp/util/OpenPgpServiceConnection.java index c80656c52..346055dcd 100644 --- a/OpenPGP-Keychain-API/libraries/openpgp-api-library/src/org/openintents/openpgp/util/OpenPgpServiceConnection.java +++ b/OpenPGP-Keychain-API/libraries/openpgp-api-library/src/org/openintents/openpgp/util/OpenPgpServiceConnection.java @@ -27,7 +27,6 @@ import android.os.IBinder; public class OpenPgpServiceConnection { private Context mApplicationContext; - private boolean mBound; private IOpenPgpService mService; private String mProviderPackageName; @@ -41,18 +40,16 @@ public class OpenPgpServiceConnection { } public boolean isBound() { - return mBound; + return (mService != null); } private ServiceConnection mServiceConnection = new ServiceConnection() { public void onServiceConnected(ComponentName name, IBinder service) { mService = IOpenPgpService.Stub.asInterface(service); - mBound = true; } public void onServiceDisconnected(ComponentName name) { mService = null; - mBound = false; } }; @@ -63,7 +60,7 @@ public class OpenPgpServiceConnection { */ public boolean bindToService() { // if not already bound... - if (mService == null && !mBound) { + if (mService == null) { try { Intent serviceIntent = new Intent(); serviceIntent.setAction(IOpenPgpService.class.getName()); -- cgit v1.2.3 From 97e0b8d0c3bba4a6a797b0d0f239e63fe4e486cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Thu, 3 Apr 2014 16:36:55 +0200 Subject: Callback for OpenPgpServiceConnection --- .../openpgp/util/OpenPgpServiceConnection.java | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'OpenPGP-Keychain-API/libraries/openpgp-api-library') diff --git a/OpenPGP-Keychain-API/libraries/openpgp-api-library/src/org/openintents/openpgp/util/OpenPgpServiceConnection.java b/OpenPGP-Keychain-API/libraries/openpgp-api-library/src/org/openintents/openpgp/util/OpenPgpServiceConnection.java index 346055dcd..0395a7bc5 100644 --- a/OpenPGP-Keychain-API/libraries/openpgp-api-library/src/org/openintents/openpgp/util/OpenPgpServiceConnection.java +++ b/OpenPGP-Keychain-API/libraries/openpgp-api-library/src/org/openintents/openpgp/util/OpenPgpServiceConnection.java @@ -25,16 +25,46 @@ import android.content.ServiceConnection; import android.os.IBinder; public class OpenPgpServiceConnection { + + // interface to create callbacks for onServiceConnected + public interface OnBound { + public void onBound(IOpenPgpService service); + } + private Context mApplicationContext; private IOpenPgpService mService; private String mProviderPackageName; + private OnBound mOnBoundListener; + + /** + * Create new OpenPgpServiceConnection + * + * @param context + * @param providerPackageName specify package name of OpenPGP provider, + * e.g., "org.sufficientlysecure.keychain" + */ public OpenPgpServiceConnection(Context context, String providerPackageName) { this.mApplicationContext = context.getApplicationContext(); this.mProviderPackageName = providerPackageName; } + /** + * Create new OpenPgpServiceConnection + * + * @param context + * @param providerPackageName specify package name of OpenPGP provider, + * e.g., "org.sufficientlysecure.keychain" + * @param onBoundListener callback, executed when connection to service has been established + */ + public OpenPgpServiceConnection(Context context, String providerPackageName, + OnBound onBoundListener) { + this.mApplicationContext = context.getApplicationContext(); + this.mProviderPackageName = providerPackageName; + this.mOnBoundListener = onBoundListener; + } + public IOpenPgpService getService() { return mService; } @@ -46,6 +76,9 @@ public class OpenPgpServiceConnection { private ServiceConnection mServiceConnection = new ServiceConnection() { public void onServiceConnected(ComponentName name, IBinder service) { mService = IOpenPgpService.Stub.asInterface(service); + if (mOnBoundListener != null) { + mOnBoundListener.onBound(mService); + } } public void onServiceDisconnected(ComponentName name) { -- cgit v1.2.3