aboutsummaryrefslogtreecommitdiffstats
path: root/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/CryptoServiceActivity.java
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2013-09-08 22:52:38 +0200
committerDominik Schürmann <dominik@dominikschuermann.de>2013-09-08 22:52:38 +0200
commit5d7f8809fc0cb28122cadc758bcd8fb885ee1ddf (patch)
treee4c218beca237c2f852136d360515a91d70f7341 /OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/CryptoServiceActivity.java
parent8123fd69255d3dda04311aea83f4c2735edd4ec5 (diff)
downloadopen-keychain-5d7f8809fc0cb28122cadc758bcd8fb885ee1ddf.tar.gz
open-keychain-5d7f8809fc0cb28122cadc758bcd8fb885ee1ddf.tar.bz2
open-keychain-5d7f8809fc0cb28122cadc758bcd8fb885ee1ddf.zip
Use handler with messenger instead of Binder for communication between service and activity
Diffstat (limited to 'OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/CryptoServiceActivity.java')
-rw-r--r--OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/CryptoServiceActivity.java124
1 files changed, 42 insertions, 82 deletions
diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/CryptoServiceActivity.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/CryptoServiceActivity.java
index 482f79728..06e558659 100644
--- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/CryptoServiceActivity.java
+++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/CryptoServiceActivity.java
@@ -27,13 +27,9 @@ import org.sufficientlysecure.keychain.ui.SelectPublicKeyFragment;
import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment;
import org.sufficientlysecure.keychain.util.Log;
-import android.content.ComponentName;
-import android.content.Context;
import android.content.Intent;
-import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.Handler;
-import android.os.IBinder;
import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;
@@ -50,84 +46,26 @@ public class CryptoServiceActivity extends SherlockFragmentActivity {
public static final String ACTION_SELECT_PUB_KEYS = Constants.INTENT_PREFIX
+ "API_ACTIVITY_SELECT_PUB_KEYS";
+ public static final String EXTRA_MESSENGER = "messenger";
+
public static final String EXTRA_SECRET_KEY_ID = "secretKeyId";
public static final String EXTRA_PACKAGE_NAME = "packageName";
public static final String EXTRA_SELECTED_MASTER_KEY_IDS = "masterKeyIds";
- private IServiceActivityCallback mServiceCallback;
- private boolean mServiceBound;
+ private Messenger mMessenger;
// register view
- AppSettingsFragment mSettingsFragment;
+ private AppSettingsFragment mSettingsFragment;
// select pub key view
- SelectPublicKeyFragment mSelectFragment;
-
- private ServiceConnection mServiceActivityConnection = new ServiceConnection() {
- public void onServiceConnected(ComponentName name, IBinder service) {
- mServiceCallback = IServiceActivityCallback.Stub.asInterface(service);
- Log.d(Constants.TAG, "connected to ICryptoServiceActivity");
- mServiceBound = true;
- }
-
- public void onServiceDisconnected(ComponentName name) {
- mServiceCallback = null;
- Log.d(Constants.TAG, "disconnected from ICryptoServiceActivity");
- mServiceBound = false;
- }
- };
-
- /**
- * If not already bound, bind!
- *
- * @return
- */
- public boolean bindToService() {
- if (mServiceCallback == null && !mServiceBound) { // if not already connected
- try {
- Log.d(Constants.TAG, "not bound yet");
-
- Intent serviceIntent = new Intent();
- serviceIntent
- .setAction("org.sufficientlysecure.keychain.crypto_provider.IServiceActivityCallback");
- bindService(serviceIntent, mServiceActivityConnection, Context.BIND_AUTO_CREATE);
-
- return true;
- } catch (Exception e) {
- Log.d(Constants.TAG, "Exception", e);
- return false;
- }
- } else { // already connected
- Log.d(Constants.TAG, "already bound... ");
- return true;
- }
- }
-
- public void unbindFromService() {
- unbindService(mServiceActivityConnection);
- }
+ private SelectPublicKeyFragment mSelectFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- Log.d(Constants.TAG, "onCreate…");
-
- // bind to our own crypto service
- bindToService();
-
handleActions(getIntent(), savedInstanceState);
}
- @Override
- protected void onDestroy() {
- super.onDestroy();
-
- // unbind from our crypto service
- if (mServiceActivityConnection != null) {
- unbindFromService();
- }
- }
-
protected void handleActions(Intent intent, Bundle savedInstanceState) {
String action = intent.getAction();
Bundle extras = intent.getExtras();
@@ -136,6 +74,8 @@ public class CryptoServiceActivity extends SherlockFragmentActivity {
extras = new Bundle();
}
+ mMessenger = extras.getParcelable(EXTRA_MESSENGER);
+
/**
* com.android.crypto actions
*/
@@ -158,10 +98,16 @@ public class CryptoServiceActivity extends SherlockFragmentActivity {
ProviderHelper.insertApiApp(CryptoServiceActivity.this,
mSettingsFragment.getAppSettings());
+ Message msg = Message.obtain();
+ msg.arg1 = CryptoService.RegisterActivityCallback.ALLOW;
+ Bundle data = new Bundle();
+ data.putString(CryptoService.RegisterActivityCallback.PACKAGE_NAME,
+ packageName);
+ msg.setData(data);
try {
- mServiceCallback.onRegistered(true, packageName);
+ mMessenger.send(msg);
} catch (RemoteException e) {
- Log.e(Constants.TAG, "ServiceActivity", e);
+ Log.e(Constants.TAG, "CryptoServiceActivity", e);
}
finish();
}
@@ -171,10 +117,12 @@ public class CryptoServiceActivity extends SherlockFragmentActivity {
public void onClick(View v) {
// Disallow
+ Message msg = Message.obtain();
+ msg.arg1 = CryptoService.RegisterActivityCallback.DISALLOW;
try {
- mServiceCallback.onRegistered(false, packageName);
+ mMessenger.send(msg);
} catch (RemoteException e) {
- Log.e(Constants.TAG, "ServiceActivity", e);
+ Log.e(Constants.TAG, "CryptoServiceActivity", e);
}
finish();
}
@@ -201,11 +149,17 @@ public class CryptoServiceActivity extends SherlockFragmentActivity {
public void onClick(View v) {
// ok
+ Message msg = Message.obtain();
+ msg.arg1 = CryptoService.SelectPubKeysActivityCallback.OKAY;
+ Bundle data = new Bundle();
+ data.putLongArray(
+ CryptoService.SelectPubKeysActivityCallback.PUB_KEY_IDS,
+ mSelectFragment.getSelectedMasterKeyIds());
+ msg.setData(data);
try {
- mServiceCallback.onSelectedPublicKeys(mSelectFragment
- .getSelectedMasterKeyIds());
+ mMessenger.send(msg);
} catch (RemoteException e) {
- Log.e(Constants.TAG, "ServiceActivity", e);
+ Log.e(Constants.TAG, "CryptoServiceActivity", e);
}
finish();
}
@@ -214,12 +168,13 @@ public class CryptoServiceActivity extends SherlockFragmentActivity {
public void onClick(View v) {
// cancel
- // TODO: currently does the same as OK...
+ Message msg = Message.obtain();
+ msg.arg1 = CryptoService.SelectPubKeysActivityCallback.CANCEL;
+ ;
try {
- mServiceCallback.onSelectedPublicKeys(mSelectFragment
- .getSelectedMasterKeyIds());
+ mMessenger.send(msg);
} catch (RemoteException e) {
- Log.e(Constants.TAG, "ServiceActivity", e);
+ Log.e(Constants.TAG, "CryptoServiceActivity", e);
}
finish();
}
@@ -227,6 +182,7 @@ public class CryptoServiceActivity extends SherlockFragmentActivity {
setContentView(R.layout.api_app_select_pub_keys_activity);
+ /* Load select pub keys fragment */
// Check that the activity is using the layout version with
// the fragment_container FrameLayout
if (findViewById(R.id.api_select_pub_keys_fragment_container) != null) {
@@ -263,16 +219,20 @@ public class CryptoServiceActivity extends SherlockFragmentActivity {
@Override
public void handleMessage(Message message) {
if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) {
+ Message msg = Message.obtain();
+ msg.arg1 = CryptoService.PassphraseActivityCallback.SUCCESS;
try {
- mServiceCallback.onCachedPassphrase(true);
+ mMessenger.send(msg);
} catch (RemoteException e) {
- Log.e(Constants.TAG, "ServiceActivity", e);
+ Log.e(Constants.TAG, "CryptoServiceActivity", e);
}
} else {
+ Message msg = Message.obtain();
+ msg.arg1 = CryptoService.PassphraseActivityCallback.NO_SUCCESS;
try {
- mServiceCallback.onCachedPassphrase(false);
+ mMessenger.send(msg);
} catch (RemoteException e) {
- Log.e(Constants.TAG, "ServiceActivity", e);
+ Log.e(Constants.TAG, "CryptoServiceActivity", e);
}
}
finish();