Reset errors before calling, make some vars final, minor cleanups

This commit is contained in:
Markus Doits 2011-01-09 17:17:27 +00:00
parent 91da2dd2ea
commit a29dfc0add

View File

@ -20,14 +20,14 @@ import org.thialfihar.android.apg.IApgService;
*/ */
public class ApgCon { public class ApgCon {
private String TAG = "ApgCon"; private final static String TAG = "ApgCon";
private final Context mContext; private final Context mContext;
private Bundle result = new Bundle(); private final Bundle result = new Bundle();
private Bundle args = new Bundle(); private final Bundle args = new Bundle();
private ArrayList<String> error_list = new ArrayList<String>(); private final ArrayList<String> error_list = new ArrayList<String>();
private ArrayList<String> warning_list = new ArrayList<String>(); private final ArrayList<String> warning_list = new ArrayList<String>();
/** Remote service for decrypting and encrypting data */ /** Remote service for decrypting and encrypting data */
private IApgService apgService = null; private IApgService apgService = null;
@ -108,6 +108,9 @@ public class ApgCon {
public boolean call(String function, Bundle pArgs, Bundle pReturn) { public boolean call(String function, Bundle pArgs, Bundle pReturn) {
error_list.clear();
warning_list.clear();
if (!initialize()) { if (!initialize()) {
error_list.add("CLASS: Cannot bind to ApgService"); error_list.add("CLASS: Cannot bind to ApgService");
pReturn.putInt("CLASS_ERROR", error.CANNOT_BIND_TO_APG.ordinal()); pReturn.putInt("CLASS_ERROR", error.CANNOT_BIND_TO_APG.ordinal());
@ -122,8 +125,8 @@ public class ApgCon {
try { try {
Boolean ret = (Boolean) IApgService.class.getMethod(function, Bundle.class, Bundle.class).invoke(apgService, pArgs, pReturn); Boolean ret = (Boolean) IApgService.class.getMethod(function, Bundle.class, Bundle.class).invoke(apgService, pArgs, pReturn);
error_list = new ArrayList<String>(pReturn.getStringArrayList("ERRORS")); error_list.addAll(pReturn.getStringArrayList("ERRORS"));
warning_list = new ArrayList<String>(pReturn.getStringArrayList("WARNINGS")); warning_list.addAll(pReturn.getStringArrayList("WARNINGS"));
return ret; return ret;
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
Log.d(TAG, e.getMessage()); Log.d(TAG, e.getMessage());
@ -142,7 +145,7 @@ public class ApgCon {
public void set_arg(String key, String val) { public void set_arg(String key, String val) {
args.putString(key, val); args.putString(key, val);
} }
public void set_arg(String key, boolean val) { public void set_arg(String key, boolean val) {
args.putBoolean(key, val); args.putBoolean(key, val);
} }
@ -152,7 +155,10 @@ public class ApgCon {
} }
public String get_next_error() { public String get_next_error() {
return error_list.remove(0); if (error_list.size() != 0)
return error_list.remove(0);
else
return null;
} }
public boolean has_next_error() { public boolean has_next_error() {
@ -160,7 +166,10 @@ public class ApgCon {
} }
public String get_next_warning() { public String get_next_warning() {
return warning_list.remove(0); if (warning_list.size() != 0)
return warning_list.remove(0);
else
return null;
} }
public boolean has_next_warning() { public boolean has_next_warning() {