Log stacktraces the android way

This commit is contained in:
Markus Doits 2011-01-25 19:38:56 +00:00
parent 3372e57157
commit 1036eb6bd5

View File

@ -34,11 +34,6 @@ import org.thialfihar.android.apg.IApgService;
*/ */
public class ApgCon { public class ApgCon {
/**
* Put stacktraces into the log?
*/
private final static boolean stacktraces = true;
private class call_async extends AsyncTask<String, Void, Void> { private class call_async extends AsyncTask<String, Void, Void> {
@Override @Override
@ -61,21 +56,15 @@ public class ApgCon {
} }
Log.d(TAG, "Callback executed"); Log.d(TAG, "Callback executed");
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
if (stacktraces) Log.w(TAG, "Exception in callback: Method '" + callback_method + "' not found", e);
e.printStackTrace();
Log.w(TAG, "Exception in callback: Method '" + callback_method + "' not found");
warning_list.add("(LOCAL) Could not execute callback, method '" + callback_method + "()' not found"); warning_list.add("(LOCAL) Could not execute callback, method '" + callback_method + "()' not found");
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
if (stacktraces)
e.printStackTrace();
Throwable orig = e.getTargetException(); Throwable orig = e.getTargetException();
Log.w(TAG, "Exception of type '" + orig.getClass() + "' in callback's method '" + callback_method + "()':" + orig.getMessage()); Log.w(TAG, "Exception of type '" + orig.getClass() + "' in callback's method '" + callback_method + "()':" + orig.getMessage(), orig);
warning_list.add("(LOCAL) Exception of type '" + orig.getClass() + "' in callback's method '" + callback_method + "()':" warning_list.add("(LOCAL) Exception of type '" + orig.getClass() + "' in callback's method '" + callback_method + "()':"
+ orig.getMessage()); + orig.getMessage());
} catch (Exception e) { } catch (Exception e) {
if (stacktraces) Log.w(TAG, "Exception on callback: (" + e.getClass() + ") " + e.getMessage(), e);
e.printStackTrace();
Log.w(TAG, "Exception on callback: (" + e.getClass() + ") " + e.getMessage());
warning_list.add("(LOCAL) Could not execute callback (" + e.getClass() + "): " + e.getMessage()); warning_list.add("(LOCAL) Could not execute callback (" + e.getClass() + "): " + e.getMessage());
} }
} }
@ -211,9 +200,7 @@ public class ApgCon {
} }
} }
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
if (stacktraces) Log.e(TAG, "Could not find APG, is it installed?", e);
e.printStackTrace();
Log.e(TAG, "Could not find APG, is it installed?");
error_list.add("(LOCAL) Could not find APG, is it installed?"); error_list.add("(LOCAL) Could not find APG, is it installed?");
result.putInt(ret.ERROR.name(), error.APG_NOT_FOUND.ordinal()); result.putInt(ret.ERROR.name(), error.APG_NOT_FOUND.ordinal());
tmp_connection_status = error.APG_NOT_FOUND; tmp_connection_status = error.APG_NOT_FOUND;
@ -234,9 +221,7 @@ public class ApgCon {
try { try {
mContext.bindService(new Intent(IApgService.class.getName()), apgConnection, Context.BIND_AUTO_CREATE); mContext.bindService(new Intent(IApgService.class.getName()), apgConnection, Context.BIND_AUTO_CREATE);
} catch (Exception e) { } catch (Exception e) {
if (stacktraces) Log.e(TAG, "could not bind APG service", e);
e.printStackTrace();
Log.v(TAG, "could not bind APG service");
return false; return false;
} }
@ -365,23 +350,17 @@ public class ApgCon {
warning_list.addAll(pReturn.getStringArrayList(ret.WARNINGS.name())); warning_list.addAll(pReturn.getStringArrayList(ret.WARNINGS.name()));
return success; return success;
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
if (stacktraces) Log.e(TAG, "Remote call not known (" + function + "): " + e.getMessage(), e);
e.printStackTrace();
Log.e(TAG, "Remote call not known (" + function + "): " + e.getMessage());
error_list.add("(LOCAL) Remote call not known (" + function + "): " + e.getMessage()); error_list.add("(LOCAL) Remote call not known (" + function + "): " + e.getMessage());
result.putInt(ret.ERROR.name(), error.CALL_NOT_KNOWN.ordinal()); result.putInt(ret.ERROR.name(), error.CALL_NOT_KNOWN.ordinal());
return false; return false;
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
if (stacktraces)
e.printStackTrace();
Throwable orig = e.getTargetException(); Throwable orig = e.getTargetException();
Log.w(TAG, "Exception of type '" + orig.getClass() + "' on AIDL call '" + function + "': " + orig.getMessage()); Log.w(TAG, "Exception of type '" + orig.getClass() + "' on AIDL call '" + function + "': " + orig.getMessage(), orig);
error_list.add("(LOCAL) Exception of type '" + orig.getClass() + "' on AIDL call '" + function + "': " + orig.getMessage()); error_list.add("(LOCAL) Exception of type '" + orig.getClass() + "' on AIDL call '" + function + "': " + orig.getMessage());
return false; return false;
} catch (Exception e) { } catch (Exception e) {
if (stacktraces) Log.e(TAG, "Generic error (" + e.getClass() + "): " + e.getMessage(), e);
e.printStackTrace();
Log.e(TAG, "Generic error (" + e.getClass() + "): " + e.getMessage());
error_list.add("(LOCAL) Generic error (" + e.getClass() + "): " + e.getMessage()); error_list.add("(LOCAL) Generic error (" + e.getClass() + "): " + e.getMessage());
result.putInt(ret.ERROR.name(), error.GENERIC.ordinal()); result.putInt(ret.ERROR.name(), error.GENERIC.ordinal());
return false; return false;