diff --git a/pom.xml b/pom.xml
index fe60a9ae8..eaccadd30 100644
--- a/pom.xml
+++ b/pom.xml
@@ -42,7 +42,7 @@
com.fsck.k9.mail
lib
aar
- 0.0.1.b13cb5f
+ 0.0.1.8f1d14a
diff --git a/src/main/java/com/zegoggles/smssync/App.java b/src/main/java/com/zegoggles/smssync/App.java
index fc2405d79..e86e9cd68 100644
--- a/src/main/java/com/zegoggles/smssync/App.java
+++ b/src/main/java/com/zegoggles/smssync/App.java
@@ -21,7 +21,7 @@
import com.squareup.otto.Bus;
public class App extends Application {
- public static final boolean DEBUG = BuildConfig.DEBUG;
+ public static final boolean DEBUG = true;
public static final boolean LOCAL_LOGV = DEBUG;
public static final String TAG = "SMSBackup+";
public static final String LOG = "sms_backup_plus.log";
diff --git a/src/main/java/com/zegoggles/smssync/service/SmsBackupService.java b/src/main/java/com/zegoggles/smssync/service/SmsBackupService.java
index d2e6b66ac..5be3ade29 100644
--- a/src/main/java/com/zegoggles/smssync/service/SmsBackupService.java
+++ b/src/main/java/com/zegoggles/smssync/service/SmsBackupService.java
@@ -21,6 +21,7 @@
import android.net.NetworkInfo;
import android.text.format.DateFormat;
import android.util.Log;
+import com.fsck.k9.mail.K9MailLib;
import com.fsck.k9.mail.MessagingException;
import com.squareup.otto.Produce;
import com.squareup.otto.Subscribe;
@@ -37,6 +38,7 @@
import com.zegoggles.smssync.service.exception.RequiresWifiException;
import com.zegoggles.smssync.service.state.BackupState;
import com.zegoggles.smssync.service.state.SmsSyncState;
+import com.zegoggles.smssync.utils.AppLog;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -222,7 +224,14 @@ private void handleErrorState(BackupState state) {
appLog(R.string.app_log_backup_failed_connectivity, state.getDetailedErrorMessage(getResources()));
} else {
appLog(R.string.app_log_backup_failed_general_error, state.getDetailedErrorMessage(getResources()));
-
+ String stackTrace = state.getStackTrace();
+ if (stackTrace != null) {
+ appLogDebug(stackTrace);
+ final String k9Log = AppLog.snapshotCurrentLog(K9MailLib.LOG_TAG, 20);
+ if (k9Log != null) {
+ appLogDebug(k9Log);
+ }
+ }
if (shouldNotifyUser(state)) {
notifyUser(android.R.drawable.stat_sys_warning,
getString(R.string.notification_general_error),
diff --git a/src/main/java/com/zegoggles/smssync/service/state/State.java b/src/main/java/com/zegoggles/smssync/service/state/State.java
index a9a8a5df4..08963d4da 100644
--- a/src/main/java/com/zegoggles/smssync/service/state/State.java
+++ b/src/main/java/com/zegoggles/smssync/service/state/State.java
@@ -12,6 +12,9 @@
import com.zegoggles.smssync.service.exception.RequiresLoginException;
import org.jetbrains.annotations.Nullable;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
import java.util.EnumSet;
public abstract class State {
@@ -55,6 +58,21 @@ public String getDetailedErrorMessage(Resources resources) {
}
}
+ public String getStackTrace() {
+ Throwable throwable = exception;
+ if (throwable != null) {
+ if (throwable instanceof MessagingException && throwable.getCause() instanceof IOException) {
+ throwable = throwable.getCause();
+ }
+ final StringWriter sw = new StringWriter();
+ throwable.printStackTrace(new PrintWriter(sw));
+ return sw.toString();
+ }
+ else {
+ return null;
+ }
+ }
+
public boolean isInitialState() {
return state == SmsSyncState.INITIAL;
}
diff --git a/src/main/java/com/zegoggles/smssync/utils/AppLog.java b/src/main/java/com/zegoggles/smssync/utils/AppLog.java
index 715d58a1a..72737ab9b 100644
--- a/src/main/java/com/zegoggles/smssync/utils/AppLog.java
+++ b/src/main/java/com/zegoggles/smssync/utils/AppLog.java
@@ -16,16 +16,19 @@
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.PrintWriter;
+import java.util.ArrayList;
import java.util.Date;
+import java.util.List;
import static com.zegoggles.smssync.App.LOCAL_LOGV;
import static com.zegoggles.smssync.App.TAG;
public class AppLog {
// keep max 32k worth of logs
- static final int MAX_SIZE = 32 * 1024;
+ private static final int MAX_SIZE = 32 * 1024;
public static final int ID = 1;
private PrintWriter writer;
@@ -180,6 +183,27 @@ public static boolean readLog(File f, TextView view) {
return text.length() > 0;
}
+ public static String snapshotCurrentLog(String tag, int maxLines) {
+ Process logcat;
+ List lines = new ArrayList(50);
+ try {
+ logcat = Runtime.getRuntime().exec(new String[]{"logcat", "-d", tag+":*", "*:S"});
+ BufferedReader br = new BufferedReader(new InputStreamReader(logcat.getInputStream()), 8192);
+ String line;
+ while ((line = br.readLine()) != null) {
+ lines.add(line);
+ }
+ final String separator = System.getProperty("line.separator");
+ final StringBuilder log = new StringBuilder();
+ for (int i=lines.size() - Math.min(maxLines, lines.size()); i