diff options
author | Markus Doits <markus.doits@gmail.com> | 2011-01-05 14:07:09 +0000 |
---|---|---|
committer | Markus Doits <markus.doits@gmail.com> | 2011-01-05 14:07:09 +0000 |
commit | 1a338de47e7d9faa73a3bc6eda51cb47a18dc91b (patch) | |
tree | 3184c203a6bae8922c6cc555edf7356dc7b337cc /src/org/thialfihar/android/apg/utils | |
parent | dbb46f1633b94aa7be39ebb8f4acc24a3420083f (diff) | |
download | open-keychain-1a338de47e7d9faa73a3bc6eda51cb47a18dc91b.tar.gz open-keychain-1a338de47e7d9faa73a3bc6eda51cb47a18dc91b.tar.bz2 open-keychain-1a338de47e7d9faa73a3bc6eda51cb47a18dc91b.zip |
Redesign AIDL-Interface once more
Using Bundles makes passing data easier and does not need to redefine
the interface if the internel functions change.
The helper class has been updated accordingly. In addition, it wrappes
completely around all input and output (if wanted).
Diffstat (limited to 'src/org/thialfihar/android/apg/utils')
-rw-r--r-- | src/org/thialfihar/android/apg/utils/ApgCon.java | 81 |
1 files changed, 61 insertions, 20 deletions
diff --git a/src/org/thialfihar/android/apg/utils/ApgCon.java b/src/org/thialfihar/android/apg/utils/ApgCon.java index 174bce5dc..6234e1b88 100644 --- a/src/org/thialfihar/android/apg/utils/ApgCon.java +++ b/src/org/thialfihar/android/apg/utils/ApgCon.java @@ -1,14 +1,14 @@ package org.thialfihar.android.apg.utils; -import java.util.Arrays; -import java.util.List; -import java.util.Map; +import java.util.ArrayList; import android.content.Context; import android.content.ComponentName; import android.content.ServiceConnection; import android.content.Intent; +import android.os.Bundle; import android.os.IBinder; +import android.os.Parcelable; import android.util.Log; import org.thialfihar.android.apg.IApgService; @@ -25,6 +25,11 @@ public class ApgCon { private final Context mContext; + private Bundle result = new Bundle(); + private Bundle args = new Bundle(); + private ArrayList<String> error_list = new ArrayList<String>(); + private ArrayList<String> warning_list = new ArrayList<String>(); + /** Remote service for decrypting and encrypting data */ private IApgService apgService = null; @@ -41,13 +46,6 @@ public class ApgCon { } }; - /** Possible fields which are returned to the application */ - public static enum retKey { - ERROR, // error enum, see below - ERROR_DESC, // human readable description - RESULT, // if everything went fine, result - } - public static enum error { GENERIC, // no special type CANNOT_BIND_TO_APG, // connection to apg service not possible @@ -101,35 +99,78 @@ public class ApgCon { return true; } - public boolean call(String function, Map<retKey, Object> return_map, String... function_params) { + public boolean call(String function) { + return this.call(function, args, result); + } + + public boolean call(String function, Bundle pArgs) { + return this.call(function, pArgs, result); + } + + public boolean call(String function, Bundle pArgs, Bundle pReturn) { if (!initialize()) { - return_map.put(retKey.ERROR, error.CANNOT_BIND_TO_APG); + error_list.add("CLASS: Cannot bind to ApgService"); + pReturn.putInt("CLASS_ERROR", error.CANNOT_BIND_TO_APG.ordinal()); return false; } if (function == null || function.length() == 0) { - return_map.put(retKey.ERROR, error.CALL_MISSING); + error_list.add("CLASS: Function to call missing"); + pReturn.putInt("CLASS_ERROR", error.CALL_MISSING.ordinal()); return false; } try { - List<String> params_list = Arrays.asList(function_params); - return_map.put(retKey.RESULT, IApgService.class.getMethod(function, List.class).invoke(apgService, params_list)); + Boolean ret = (Boolean) IApgService.class.getMethod(function, Bundle.class, Bundle.class).invoke(apgService, pArgs, pReturn); + error_list = new ArrayList<String>(pReturn.getStringArrayList("ERRORS")); + warning_list = new ArrayList<String>(pReturn.getStringArrayList("WARNINGS")); + return ret; } catch (NoSuchMethodException e) { Log.d(TAG, e.getMessage()); - return_map.put(retKey.ERROR, error.CALL_NOT_KNOWN); - return_map.put(retKey.ERROR_DESC, e.getMessage()); + error_list.add("CLASS: " + e.getMessage()); + pReturn.putInt("CLASS_ERROR", error.CALL_NOT_KNOWN.ordinal()); return false; } catch (Exception e) { Log.d(TAG, e.getMessage()); - return_map.put(retKey.ERROR, error.GENERIC); - return_map.put(retKey.ERROR_DESC, e.getMessage()); + error_list.add("CLASS: " + e.getMessage()); + pReturn.putInt("CLASS_ERROR", error.GENERIC.ordinal()); return false; } - return true; + } + + public void set_arg(String key, String val) { + args.putString(key, val); + } + + public void set_arg(String key, boolean val) { + args.putBoolean(key, val); + } + + public Object get_arg(String key) { + return args.get(key); + } + + public String get_next_error() { + String bla = "abc"; + return error_list.remove(0); + } + + public boolean has_next_error() { + return error_list.size() != 0; + } + + public String get_next_warning() { + return warning_list.remove(0); + } + + public boolean has_next_warning() { + return warning_list.size() != 0; + } + public String get_result() { + return result.getString("RESULT"); } private void disconnect() { |