Browse Source

Catch any uncaught exceptions and log them (but still throw the normal Android exceptions.

pull/187/head
Eric Kok 10 years ago
parent
commit
522edfb64a
  1. 4
      app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java
  2. 2
      app/src/main/java/org/transdroid/core/gui/log/ErrorLogSender.java
  3. 2
      app/src/main/java/org/transdroid/core/gui/log/Log.java
  4. 50
      app/src/main/java/org/transdroid/core/gui/log/LogUncaughtExceptionHandler.java
  5. 4
      app/src/main/java/org/transdroid/daemon/util/TlsSniSocketFactory.java

4
app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java

@ -185,6 +185,9 @@ public class TorrentsActivity extends Activity implements OnNavigationListener,
setTheme(R.style.TransdroidTheme_Dark); setTheme(R.style.TransdroidTheme_Dark);
getActionBar().setIcon(R.drawable.ic_activity_torrents); getActionBar().setIcon(R.drawable.ic_activity_torrents);
} }
// Catch any uncaught exception to log it
Thread.setDefaultUncaughtExceptionHandler(new LogUncaughtExceptionHandler(this,
Thread.getDefaultUncaughtExceptionHandler()));
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
} }
@ -265,7 +268,6 @@ public class TorrentsActivity extends Activity implements OnNavigationListener,
// Handle any start up intents // Handle any start up intents
if (openTorrent != null) { if (openTorrent != null) {
openDetails(openTorrent); openDetails(openTorrent);
openTorrent = null;
} else if (getIntent() != null) { } else if (getIntent() != null) {
handleStartIntent(); handleStartIntent();
} }

2
app/src/main/java/org/transdroid/core/gui/log/ErrorLogSender.java

@ -74,7 +74,7 @@ public class ErrorLogSender {
Intent target = new Intent(Intent.ACTION_SEND); Intent target = new Intent(Intent.ACTION_SEND);
target.setType("message/rfc822"); target.setType("message/rfc822");
target.putExtra(Intent.EXTRA_EMAIL, new String[] { "transdroid.org@gmail.com" }); target.putExtra(Intent.EXTRA_EMAIL, new String[] { "transdroid@2312.nl" });
target.putExtra(Intent.EXTRA_SUBJECT, "Transdroid error report"); target.putExtra(Intent.EXTRA_SUBJECT, "Transdroid error report");
target.putExtra(Intent.EXTRA_TEXT, body.toString()); target.putExtra(Intent.EXTRA_TEXT, body.toString());
try { try {

2
app/src/main/java/org/transdroid/core/gui/log/Log.java

@ -46,8 +46,6 @@ public class Log implements ITLogger {
private Context context; private Context context;
@OrmLiteDao(helper = DatabaseHelper.class, model = ErrorLogEntry.class) @OrmLiteDao(helper = DatabaseHelper.class, model = ErrorLogEntry.class)
Dao<ErrorLogEntry, Integer> errorLogDao; Dao<ErrorLogEntry, Integer> errorLogDao;
@Bean
protected NavigationHelper navigationHelper;
protected Log(Context context) { protected Log(Context context) {
this.context = context; this.context = context;

50
app/src/main/java/org/transdroid/core/gui/log/LogUncaughtExceptionHandler.java

@ -0,0 +1,50 @@
/*
* Copyright 2010-2013 Eric Kok et al.
*
* Transdroid 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.
*
* Transdroid 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 Transdroid. If not, see <http://www.gnu.org/licenses/>.
*/
package org.transdroid.core.gui.log;
import android.content.Context;
public class LogUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
private final Context context;
private final Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler;
public LogUncaughtExceptionHandler(Context context, Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler) {
this.context = context;
this.defaultUncaughtExceptionHandler = defaultUncaughtExceptionHandler;
}
@Override
public void uncaughtException(Thread thread, Throwable ex) {
// Write exception stack trace to the log
String prefix = "E: ";
Log.e(context, prefix + ex.toString());
if (ex.getCause() != null) {
for (StackTraceElement e : ex.getCause().getStackTrace()) {
Log.e(context, prefix + e.toString());
}
}
for (StackTraceElement e : ex.getStackTrace()) {
Log.e(context, prefix + e.toString());
}
// Rely on default Android exception handling
defaultUncaughtExceptionHandler.uncaughtException(thread, ex);
}
}

4
app/src/main/java/org/transdroid/daemon/util/TlsSniSocketFactory.java

@ -140,9 +140,9 @@ public class TlsSniSocketFactory implements LayeredSocketFactory {
throw new SSLPeerUnverifiedException("Cannot verify hostname: " + host); throw new SSLPeerUnverifiedException("Cannot verify hostname: " + host);
} }
DLog.d(TlsSniSocketFactory.class.getSimpleName(), /*DLog.d(TlsSniSocketFactory.class.getSimpleName(),
"Established " + session.getProtocol() + " connection with " + session.getPeerHost() + "Established " + session.getProtocol() + " connection with " + session.getPeerHost() +
" using " + session.getCipherSuite()); " using " + session.getCipherSuite());*/
return ssl; return ssl;
} }

Loading…
Cancel
Save