aboutsummaryrefslogtreecommitdiffstats
path: root/OpenPGP-Keychain/src/org
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2013-09-16 13:08:02 +0200
committerDominik Schürmann <dominik@dominikschuermann.de>2013-09-16 13:08:02 +0200
commit0e24a74bb82bc0db720297046909145b61399857 (patch)
tree569e3f1c3b45add9dbb9ea6cc62fe302cc21f568 /OpenPGP-Keychain/src/org
parent363358d30b54ad70c92df59b9496dcdda5becc79 (diff)
downloadopen-keychain-0e24a74bb82bc0db720297046909145b61399857.tar.gz
open-keychain-0e24a74bb82bc0db720297046909145b61399857.tar.bz2
open-keychain-0e24a74bb82bc0db720297046909145b61399857.zip
Simplify exception handling in service
Diffstat (limited to 'OpenPGP-Keychain/src/org')
-rw-r--r--OpenPGP-Keychain/src/org/sufficientlysecure/keychain/service/remote/ExtendedApiService.java16
-rw-r--r--OpenPGP-Keychain/src/org/sufficientlysecure/keychain/service/remote/OpenPgpService.java68
2 files changed, 23 insertions, 61 deletions
diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/service/remote/ExtendedApiService.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/service/remote/ExtendedApiService.java
index 4530179cb..427e6bb8f 100644
--- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/service/remote/ExtendedApiService.java
+++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/service/remote/ExtendedApiService.java
@@ -45,7 +45,7 @@ public class ExtendedApiService extends RemoteService {
}
private void selfSignedX509CertSafe(String subjAltNameURI, IExtendedApiCallback callback,
- AppSettings appSettings) throws RemoteException {
+ AppSettings appSettings) {
// TODO: for pgp keyrings with password
CallbackHandler pgpPwdCallbackHandler = new PgpToX509.PredefinedPasswordCallbackHandler("");
@@ -77,7 +77,11 @@ public class ExtendedApiService extends RemoteService {
callback.onSuccess(outputBytes);
} catch (Exception e) {
Log.e(Constants.TAG, "ExtendedApiService", e);
- callback.onError(e.getMessage());
+ try {
+ callback.onError(e.getMessage());
+ } catch (RemoteException e1) {
+ Log.e(Constants.TAG, "ExtendedApiService", e);
+ }
}
// TODO: no private key at the moment! Don't give it to others
@@ -104,19 +108,13 @@ public class ExtendedApiService extends RemoteService {
final AppSettings settings = getAppSettings();
Runnable r = new Runnable() {
-
@Override
public void run() {
- try {
- selfSignedX509CertSafe(subjAltNameURI, callback, settings);
- } catch (RemoteException e) {
- Log.e(Constants.TAG, "OpenPgpService", e);
- }
+ selfSignedX509CertSafe(subjAltNameURI, callback, settings);
}
};
checkAndEnqueue(r);
-
}
};
diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/service/remote/OpenPgpService.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/service/remote/OpenPgpService.java
index f3916bdc6..a6fb78f71 100644
--- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/service/remote/OpenPgpService.java
+++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/service/remote/OpenPgpService.java
@@ -55,23 +55,6 @@ import android.os.RemoteException;
public class OpenPgpService extends RemoteService {
- @Override
- public void onCreate() {
- super.onCreate();
- Log.d(Constants.TAG, "OpenPgpService, onCreate()");
- }
-
- @Override
- public void onDestroy() {
- super.onDestroy();
- Log.d(Constants.TAG, "OpenPgpService, onDestroy()");
- }
-
- @Override
- public IBinder onBind(Intent intent) {
- return mBinder;
- }
-
private String getCachedPassphrase(long keyId, boolean allowUserInteraction)
throws UserInteractionRequiredException {
String passphrase = PassphraseCacheService.getCachedPassphrase(getContext(), keyId);
@@ -234,7 +217,7 @@ public class OpenPgpService extends RemoteService {
private synchronized void encryptAndSignSafe(byte[] inputBytes, String[] encryptionUserIds,
boolean asciiArmor, boolean allowUserInteraction, IOpenPgpCallback callback,
- AppSettings appSettings, boolean sign) throws RemoteException {
+ AppSettings appSettings, boolean sign) {
try {
// build InputData and write into OutputStream
InputStream inputStream = new ByteArrayInputStream(inputBytes);
@@ -285,10 +268,8 @@ public class OpenPgpService extends RemoteService {
// TODO: asciiArmor?!
private void signSafe(byte[] inputBytes, boolean allowUserInteraction,
- IOpenPgpCallback callback, AppSettings appSettings) throws RemoteException {
+ IOpenPgpCallback callback, AppSettings appSettings) {
try {
- Log.d(Constants.TAG, "current therad id: " + Thread.currentThread().getId());
-
// build InputData and write into OutputStream
InputStream inputStream = new ByteArrayInputStream(inputBytes);
long inputLength = inputBytes.length;
@@ -321,7 +302,7 @@ public class OpenPgpService extends RemoteService {
}
private synchronized void decryptAndVerifySafe(byte[] inputBytes, boolean allowUserInteraction,
- IOpenPgpCallback callback, AppSettings appSettings) throws RemoteException {
+ IOpenPgpCallback callback, AppSettings appSettings) {
try {
// TODO: this is not really needed
// checked if it is text with BEGIN and END tags
@@ -466,7 +447,8 @@ public class OpenPgpService extends RemoteService {
try {
callback.onError(new OpenPgpError(0, message));
} catch (Exception t) {
- Log.e(Constants.TAG, "Error returning exception to client", t);
+ Log.e(Constants.TAG,
+ "Exception while returning OpenPgpError to client via callback.onError()", t);
}
}
@@ -476,19 +458,13 @@ public class OpenPgpService extends RemoteService {
public void encrypt(final byte[] inputBytes, final String[] encryptionUserIds,
final boolean asciiArmor, final boolean allowUserInteraction,
final IOpenPgpCallback callback) throws RemoteException {
-
final AppSettings settings = getAppSettings();
Runnable r = new Runnable() {
-
@Override
public void run() {
- try {
- encryptAndSignSafe(inputBytes, encryptionUserIds, asciiArmor,
- allowUserInteraction, callback, settings, false);
- } catch (RemoteException e) {
- Log.e(Constants.TAG, "OpenPgpService", e);
- }
+ encryptAndSignSafe(inputBytes, encryptionUserIds, asciiArmor,
+ allowUserInteraction, callback, settings, false);
}
};
@@ -499,19 +475,13 @@ public class OpenPgpService extends RemoteService {
public void signAndEncrypt(final byte[] inputBytes, final String[] encryptionUserIds,
final boolean asciiArmor, final boolean allowUserInteraction,
final IOpenPgpCallback callback) throws RemoteException {
-
final AppSettings settings = getAppSettings();
Runnable r = new Runnable() {
-
@Override
public void run() {
- try {
- encryptAndSignSafe(inputBytes, encryptionUserIds, asciiArmor,
- allowUserInteraction, callback, settings, true);
- } catch (RemoteException e) {
- Log.e(Constants.TAG, "OpenPgpService", e);
- }
+ encryptAndSignSafe(inputBytes, encryptionUserIds, asciiArmor,
+ allowUserInteraction, callback, settings, true);
}
};
@@ -525,19 +495,13 @@ public class OpenPgpService extends RemoteService {
final AppSettings settings = getAppSettings();
Runnable r = new Runnable() {
-
@Override
public void run() {
- try {
- signSafe(inputBytes, allowUserInteraction, callback, settings);
- } catch (RemoteException e) {
- Log.e(Constants.TAG, "OpenPgpService", e);
- }
+ signSafe(inputBytes, allowUserInteraction, callback, settings);
}
};
checkAndEnqueue(r);
-
}
@Override
@@ -547,14 +511,9 @@ public class OpenPgpService extends RemoteService {
final AppSettings settings = getAppSettings();
Runnable r = new Runnable() {
-
@Override
public void run() {
- try {
- decryptAndVerifySafe(inputBytes, allowUserInteraction, callback, settings);
- } catch (RemoteException e) {
- Log.e(Constants.TAG, "OpenPgpService", e);
- }
+ decryptAndVerifySafe(inputBytes, allowUserInteraction, callback, settings);
}
};
@@ -563,4 +522,9 @@ public class OpenPgpService extends RemoteService {
};
+ @Override
+ public IBinder onBind(Intent intent) {
+ return mBinder;
+ }
+
}