aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2015-06-06 23:17:42 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2015-06-06 23:17:42 +0200
commit074b6633b015aba84f8f60a05878a93d4b8ec9b2 (patch)
treeb7d11a8df2bc0ff93b245fbc67d7c7ba6bf9dd18 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service
parent7cfc0d80d0b4318ce1ae027536d70c2cda4c8605 (diff)
downloadopen-keychain-074b6633b015aba84f8f60a05878a93d4b8ec9b2.tar.gz
open-keychain-074b6633b015aba84f8f60a05878a93d4b8ec9b2.tar.bz2
open-keychain-074b6633b015aba84f8f60a05878a93d4b8ec9b2.zip
eventbus: initial attempt, replace messenger hack with eventbus communication
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java2
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainNewService.java150
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java89
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/ProgressEvent.java16
4 files changed, 169 insertions, 88 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java
index 8721f4c0c..a11f81658 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java
@@ -43,6 +43,8 @@ public class CertifyActionsParcel implements Parcelable {
public ArrayList<CertifyAction> mCertifyActions = new ArrayList<>();
+ public String keyServerUri;
+
public CertifyActionsParcel(long masterKeyId) {
mMasterKeyId = masterKeyId;
mLevel = CertifyLevel.DEFAULT;
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainNewService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainNewService.java
new file mode 100644
index 000000000..5ef475029
--- /dev/null
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainNewService.java
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2012-2014 Dominik Schürmann <dominik@dominikschuermann.de>
+ * Copyright (C) 2014 Vincent Breitmoser <v.breitmoser@mugenguild.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package org.sufficientlysecure.keychain.service;
+
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import android.app.Service;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.os.Parcelable;
+
+import de.greenrobot.event.EventBus;
+import org.sufficientlysecure.keychain.Constants;
+import org.sufficientlysecure.keychain.operations.BaseOperation;
+import org.sufficientlysecure.keychain.operations.CertifyOperation;
+import org.sufficientlysecure.keychain.operations.EditKeyOperation;
+import org.sufficientlysecure.keychain.operations.SignEncryptOperation;
+import org.sufficientlysecure.keychain.operations.results.OperationResult;
+import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify;
+import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel;
+import org.sufficientlysecure.keychain.pgp.Progressable;
+import org.sufficientlysecure.keychain.pgp.SignEncryptParcel;
+import org.sufficientlysecure.keychain.provider.ProviderHelper;
+import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
+import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
+import org.sufficientlysecure.keychain.util.Log;
+
+/**
+ * This Service contains all important long lasting operations for OpenKeychain. It receives Intents with
+ * data from the activities or other apps, executes them, and stops itself after doing them.
+ */
+public class KeychainNewService extends Service implements Progressable {
+
+ /* extras that can be given by intent */
+ public static final String EXTRA_OPERATION_INPUT = "op_input";
+ public static final String EXTRA_CRYPTO_INPUT = "crypto_input";
+
+ // this attribute can possibly merged with the one above? not sure...
+ private AtomicBoolean mActionCanceled = new AtomicBoolean(false);
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return null;
+ }
+
+ /**
+ * This is run on the main thread, we need to spawn a runnable which runs on another thread for the actual operation
+ */
+ @Override
+ public int onStartCommand(final Intent intent, int flags, int startId) {
+ EventBus bus = EventBus.getDefault();
+ if (!bus.isRegistered(this)) {
+ bus.register(this);
+ }
+
+ Bundle extras = intent.getExtras();
+ if (extras != null) {
+ bus.post(extras);
+ } else {
+ Log.e(Constants.TAG, "Extras bundle is null!");
+ }
+
+ return START_NOT_STICKY;
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ EventBus.getDefault().unregister(this);
+ }
+
+ public void onEventAsync(Bundle bundle) {
+
+ // Input
+ Parcelable inputParcel = bundle.getParcelable(EXTRA_OPERATION_INPUT);
+ CryptoInputParcel cryptoInput = bundle.getParcelable(EXTRA_CRYPTO_INPUT);
+
+ // Operation
+ BaseOperation op;
+
+ if (inputParcel instanceof SignEncryptParcel) {
+ op = new SignEncryptOperation(this, new ProviderHelper(this), this, mActionCanceled);
+ } else if (inputParcel instanceof PgpDecryptVerifyInputParcel) {
+ op = new PgpDecryptVerify(this, new ProviderHelper(this), this);
+ } else if (inputParcel instanceof SaveKeyringParcel) {
+ op = new EditKeyOperation(this, new ProviderHelper(this), this, mActionCanceled);
+ } else if (inputParcel instanceof CertifyAction) {
+ op = new CertifyOperation(this, new ProviderHelper(this), this, mActionCanceled);
+ } else {
+ return;
+ }
+
+ @SuppressWarnings("unchecked") // this is unchecked, we make sure it's the correct op above!
+ OperationResult result = op.execute(inputParcel, cryptoInput);
+
+ // Result
+ EventBus.getDefault().post(result);
+
+ stopSelf();
+
+ }
+
+ /**
+ * Set progress of ProgressDialog by sending message to handler on UI thread
+ */
+ @Override
+ public void setProgress(String message, int progress, int max) {
+ Log.d(Constants.TAG, "Send message by setProgress with progress=" + progress + ", max="
+ + max);
+
+ ProgressEvent event = new ProgressEvent(message, progress, max);
+ EventBus.getDefault().post(event);
+
+ }
+
+ @Override
+ public void setProgress(int resourceId, int progress, int max) {
+ setProgress(getString(resourceId), progress, max);
+ }
+
+ @Override
+ public void setProgress(int progress, int max) {
+ setProgress(null, progress, max);
+ }
+
+ @Override
+ public void setPreventCancel() {
+ // sendMessageToHandler(MessageStatus.PREVENT_CANCEL);
+ }
+
+
+}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java
index b8cb9de27..e4bfd7dee 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java
@@ -30,6 +30,7 @@ import android.os.RemoteException;
import com.textuality.keybase.lib.Proof;
import com.textuality.keybase.lib.prover.Prover;
+import de.greenrobot.event.EventBus;
import org.json.JSONObject;
import org.spongycastle.openpgp.PGPUtil;
import org.sufficientlysecure.keychain.Constants;
@@ -96,14 +97,9 @@ public class KeychainService extends Service implements Progressable {
public static final String EXTRA_DATA = "data";
/* possible actions */
- public static final String ACTION_SIGN_ENCRYPT = Constants.INTENT_PREFIX + "SIGN_ENCRYPT";
-
- public static final String ACTION_DECRYPT_VERIFY = Constants.INTENT_PREFIX + "DECRYPT_VERIFY";
public static final String ACTION_VERIFY_KEYBASE_PROOF = Constants.INTENT_PREFIX + "VERIFY_KEYBASE_PROOF";
- public static final String ACTION_DECRYPT_METADATA = Constants.INTENT_PREFIX + "DECRYPT_METADATA";
-
public static final String ACTION_EDIT_KEYRING = Constants.INTENT_PREFIX + "EDIT_KEYRING";
public static final String ACTION_PROMOTE_KEYRING = Constants.INTENT_PREFIX + "PROMOTE_KEYRING";
@@ -113,8 +109,6 @@ public class KeychainService extends Service implements Progressable {
public static final String ACTION_UPLOAD_KEYRING = Constants.INTENT_PREFIX + "UPLOAD_KEYRING";
- public static final String ACTION_CERTIFY_KEYRING = Constants.INTENT_PREFIX + "SIGN_KEYRING";
-
public static final String ACTION_DELETE = Constants.INTENT_PREFIX + "DELETE";
public static final String ACTION_CONSOLIDATE = Constants.INTENT_PREFIX + "CONSOLIDATE";
@@ -123,14 +117,6 @@ public class KeychainService extends Service implements Progressable {
/* keys for data bundle */
- // encrypt
- public static final String ENCRYPT_DECRYPT_INPUT_URI = "input_uri";
- public static final String ENCRYPT_DECRYPT_OUTPUT_URI = "output_uri";
- public static final String SIGN_ENCRYPT_PARCEL = "sign_encrypt_parcel";
-
- // decrypt/verify
- public static final String DECRYPT_VERIFY_PARCEL = "decrypt_verify_parcel";
-
// keybase proof
public static final String KEYBASE_REQUIRED_FINGERPRINT = "keybase_required_fingerprint";
public static final String KEYBASE_PROOF = "keybase_proof";
@@ -158,9 +144,6 @@ public class KeychainService extends Service implements Progressable {
// upload key
public static final String UPLOAD_KEY_SERVER = "upload_key_server";
- // certify key
- public static final String CERTIFY_PARCEL = "certify_parcel";
-
// promote key
public static final String PROMOTE_MASTER_KEY_ID = "promote_master_key_id";
public static final String PROMOTE_CARD_AID = "promote_card_aid";
@@ -232,23 +215,6 @@ public class KeychainService extends Service implements Progressable {
// executeServiceMethod action from extra bundle
switch (action) {
- case ACTION_CERTIFY_KEYRING: {
-
- // Input
- CertifyActionsParcel parcel = data.getParcelable(CERTIFY_PARCEL);
- CryptoInputParcel cryptoInput = data.getParcelable(EXTRA_CRYPTO_INPUT);
- String keyServerUri = data.getString(UPLOAD_KEY_SERVER);
-
- // Operation
- CertifyOperation op = new CertifyOperation(mKeychainService, providerHelper, mKeychainService,
- mActionCanceled);
- CertifyResult result = op.certify(parcel, cryptoInput, keyServerUri);
-
- // Result
- sendMessageToHandler(MessageStatus.OKAY, result);
-
- break;
- }
case ACTION_CONSOLIDATE: {
// Operation
@@ -264,24 +230,6 @@ public class KeychainService extends Service implements Progressable {
break;
}
- case ACTION_DECRYPT_METADATA: {
-
- // Input
- CryptoInputParcel cryptoInput = data.getParcelable(EXTRA_CRYPTO_INPUT);
- PgpDecryptVerifyInputParcel input = data.getParcelable(DECRYPT_VERIFY_PARCEL);
-
- // this action is here for compatibility only
- input.setDecryptMetadataOnly(true);
-
- // Operation
- PgpDecryptVerify op = new PgpDecryptVerify(mKeychainService, providerHelper, mKeychainService);
- DecryptVerifyResult decryptVerifyResult = op.execute(input, cryptoInput);
-
- // Result
- sendMessageToHandler(MessageStatus.OKAY, decryptVerifyResult);
-
- break;
- }
case ACTION_VERIFY_KEYBASE_PROOF: {
try {
@@ -376,25 +324,6 @@ public class KeychainService extends Service implements Progressable {
break;
}
- case ACTION_DECRYPT_VERIFY: {
-
- // Input
- CryptoInputParcel cryptoInput = data.getParcelable(EXTRA_CRYPTO_INPUT);
- PgpDecryptVerifyInputParcel input = data.getParcelable(DECRYPT_VERIFY_PARCEL);
-
- // for compatibility
- // TODO merge with ACTION_DECRYPT_METADATA
- input.setDecryptMetadataOnly(false);
-
- // Operation
- PgpDecryptVerify op = new PgpDecryptVerify(mKeychainService, providerHelper, mKeychainService);
- DecryptVerifyResult decryptVerifyResult = op.execute(input, cryptoInput);
-
- // Output
- sendMessageToHandler(MessageStatus.OKAY, decryptVerifyResult);
-
- break;
- }
case ACTION_DELETE: {
// Input
@@ -495,22 +424,6 @@ public class KeychainService extends Service implements Progressable {
break;
}
- case ACTION_SIGN_ENCRYPT: {
-
- // Input
- SignEncryptParcel inputParcel = data.getParcelable(SIGN_ENCRYPT_PARCEL);
- CryptoInputParcel cryptoInput = data.getParcelable(EXTRA_CRYPTO_INPUT);
-
- // Operation
- SignEncryptOperation op = new SignEncryptOperation(
- mKeychainService, providerHelper, mKeychainService, mActionCanceled);
- SignEncryptResult result = op.execute(inputParcel, cryptoInput);
-
- // Result
- sendMessageToHandler(MessageStatus.OKAY, result);
-
- break;
- }
case ACTION_UPLOAD_KEYRING: {
try {
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/ProgressEvent.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/ProgressEvent.java
new file mode 100644
index 000000000..d441eccd0
--- /dev/null
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/ProgressEvent.java
@@ -0,0 +1,16 @@
+package org.sufficientlysecure.keychain.service;
+
+
+public class ProgressEvent {
+
+ public final String mMessage;
+ public final int mProgress;
+ public final int mMax;
+
+ public ProgressEvent(String message, int progress, int max) {
+ mMessage = message;
+ mProgress = progress;
+ mMax = max;
+ }
+
+}